utils.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. replace "s|!!APP_NAME!!|${APP_NAME}|g" "$1"
  14. replace "s|!!APP_NAME_LC!!|${APP_NAME_LC}|g" "$1"
  15. replace "s|!!BINARY_NAME!!|${BINARY_NAME}|g" "$1"
  16. replace "s|!!GH_REPO_PATH!!|${GH_REPO_PATH}|g" "$1"
  17. replace "s|!!ORG_NAME!!|${ORG_NAME}|g" "$1"
  18. if ! git apply --ignore-whitespace "$1"; then
  19. echo failed to apply patch "$1" >&2
  20. exit 1
  21. fi
  22. }
  23. exists() { type -t "$1" &> /dev/null; }
  24. is_gnu_sed() {
  25. sed --version &> /dev/null
  26. }
  27. replace() {
  28. if is_gnu_sed; then
  29. sed -i -E "${1}" "${2}"
  30. else
  31. sed -i '' -E "${1}" "${2}"
  32. fi
  33. }
  34. if ! exists gsed; then
  35. if is_gnu_sed; then
  36. function gsed() {
  37. sed -i -E "$@"
  38. }
  39. else
  40. function gsed() {
  41. sed -i '' -E "$@"
  42. }
  43. fi
  44. fi