utils.sh 1.4 KB

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