utils.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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|!!ORG_NAME!!|${ORG_NAME}|g" "$1"
  27. replace "s|!!RELEASE_VERSION!!|${RELEASE_VERSION}|g" "$1"
  28. replace "s|!!TUNNEL_APP_NAME!!|${TUNNEL_APP_NAME}|g" "$1"
  29. if ! git apply --ignore-whitespace "$1"; then
  30. echo failed to apply patch "$1" >&2
  31. exit 1
  32. fi
  33. mv -f $1{.bak,}
  34. }
  35. exists() { type -t "$1" &> /dev/null; }
  36. is_gnu_sed() {
  37. sed --version &> /dev/null
  38. }
  39. replace() {
  40. if is_gnu_sed; then
  41. sed -i -E "${1}" "${2}"
  42. else
  43. sed -i '' -E "${1}" "${2}"
  44. fi
  45. }
  46. if ! exists gsed; then
  47. if is_gnu_sed; then
  48. function gsed() {
  49. sed -i -E "$@"
  50. }
  51. else
  52. function gsed() {
  53. sed -i '' -E "$@"
  54. }
  55. fi
  56. fi