utils.sh 1.5 KB

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