utils.sh 1.1 KB

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