utils.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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="${TUNNEL_APP_NAME:-"${BINARY_NAME}-tunnel"}"
  9. if [[ "${VSCODE_QUALITY}" == "insider" ]]; then
  10. GLOBAL_DIRNAME="${GLOBAL_DIRNAME:-"${APP_NAME_LC}"}-insiders"
  11. else
  12. GLOBAL_DIRNAME="${GLOBAL_DIRNAME:-"${APP_NAME_LC}"}"
  13. fi
  14. # All common functions can be added to this file
  15. apply_patch() {
  16. if [[ -z "$2" ]]; then
  17. echo applying patch: "$1";
  18. fi
  19. # grep '^+++' "$1" | sed -e 's#+++ [ab]/#./vscode/#' | while read line; do shasum -a 256 "${line}"; done
  20. cp $1{,.bak}
  21. replace "s|!!APP_NAME!!|${APP_NAME}|g" "$1"
  22. replace "s|!!APP_NAME_LC!!|${APP_NAME_LC}|g" "$1"
  23. replace "s|!!ASSETS_REPOSITORY!!|${ASSETS_REPOSITORY}|g" "$1"
  24. replace "s|!!BINARY_NAME!!|${BINARY_NAME}|g" "$1"
  25. replace "s|!!GH_REPO_PATH!!|${GH_REPO_PATH}|g" "$1"
  26. replace "s|!!GLOBAL_DIRNAME!!|${GLOBAL_DIRNAME}|g" "$1"
  27. replace "s|!!ORG_NAME!!|${ORG_NAME}|g" "$1"
  28. replace "s|!!RELEASE_VERSION!!|${RELEASE_VERSION}|g" "$1"
  29. replace "s|!!TUNNEL_APP_NAME!!|${TUNNEL_APP_NAME}|g" "$1"
  30. if ! git apply --ignore-whitespace "$1"; then
  31. echo failed to apply patch "$1" >&2
  32. exit 1
  33. fi
  34. mv -f $1{.bak,}
  35. }
  36. exists() { type -t "$1" &> /dev/null; }
  37. is_gnu_sed() {
  38. sed --version &> /dev/null
  39. }
  40. replace() {
  41. if is_gnu_sed; then
  42. sed -i -E "${1}" "${2}"
  43. else
  44. sed -i '' -E "${1}" "${2}"
  45. fi
  46. }
  47. if ! exists gsed; then
  48. if is_gnu_sed; then
  49. function gsed() {
  50. sed -i -E "$@"
  51. }
  52. else
  53. function gsed() {
  54. sed -i '' -E "$@"
  55. }
  56. fi
  57. fi