utils.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. APP_NAME="${APP_NAME:-VSCodium}"
  3. APP_NAME_LC="$( echo "${APP_NAME}" | awk '{print tolower($0)}' )"
  4. BINARY_NAME="${BINARY_NAME:-codium}"
  5. GH_REPO_PATH="${GH_REPO_PATH:-VSCodium/vscodium}"
  6. ORG_NAME="${ORG_NAME:-VSCodium}"
  7. # All common functions can be added to this file
  8. apply_patch() {
  9. if [[ -z "$2" ]]; then
  10. echo applying patch: "$1";
  11. fi
  12. # grep '^+++' "$1" | sed -e 's#+++ [ab]/#./vscode/#' | while read line; do shasum -a 256 "${line}"; done
  13. cp $1{,.bak}
  14. replace "s|!!APP_NAME!!|${APP_NAME}|g" "$1"
  15. replace "s|!!APP_NAME_LC!!|${APP_NAME_LC}|g" "$1"
  16. replace "s|!!BINARY_NAME!!|${BINARY_NAME}|g" "$1"
  17. replace "s|!!GH_REPO_PATH!!|${GH_REPO_PATH}|g" "$1"
  18. replace "s|!!ORG_NAME!!|${ORG_NAME}|g" "$1"
  19. if ! git apply --ignore-whitespace "$1"; then
  20. echo failed to apply patch "$1" >&2
  21. exit 1
  22. fi
  23. mv -f $1{.bak,}
  24. }
  25. exists() { type -t "$1" &> /dev/null; }
  26. is_gnu_sed() {
  27. sed --version &> /dev/null
  28. }
  29. replace() {
  30. if is_gnu_sed; then
  31. sed -i -E "${1}" "${2}"
  32. else
  33. sed -i '' -E "${1}" "${2}"
  34. fi
  35. }
  36. if ! exists gsed; then
  37. if is_gnu_sed; then
  38. function gsed() {
  39. sed -i -E "$@"
  40. }
  41. else
  42. function gsed() {
  43. sed -i '' -E "$@"
  44. }
  45. fi
  46. fi