utils.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. replace "s|!!RELEASE_VERSION!!|${RELEASE_VERSION}|g" "$1"
  20. if ! git apply --ignore-whitespace "$1"; then
  21. echo failed to apply patch "$1" >&2
  22. exit 1
  23. fi
  24. mv -f $1{.bak,}
  25. }
  26. exists() { type -t "$1" &> /dev/null; }
  27. is_gnu_sed() {
  28. sed --version &> /dev/null
  29. }
  30. replace() {
  31. if is_gnu_sed; then
  32. sed -i -E "${1}" "${2}"
  33. else
  34. sed -i '' -E "${1}" "${2}"
  35. fi
  36. }
  37. if ! exists gsed; then
  38. if is_gnu_sed; then
  39. function gsed() {
  40. sed -i -E "$@"
  41. }
  42. else
  43. function gsed() {
  44. sed -i '' -E "$@"
  45. }
  46. fi
  47. fi