From f1a9cde9fde1eda19eadbd32910560649226ddf4 Mon Sep 17 00:00:00 2001 From: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> Date: Fri, 15 Nov 2024 21:46:11 -0500 Subject: [PATCH] Use double quotes around bash substitutions. Use braces around bash variable uses. Partial #638 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> --- .github/workflows/release.yml | 16 ++++++++-------- contrib/completion/mas-completion.bash | 4 ++-- contrib/completion/mas.fish | 6 +++--- script/bottle | 20 ++++++++++---------- script/brew_core_update | 16 ++++++++-------- script/brew_tap_update | 4 ++-- script/build_artifacts | 4 ++-- script/format | 2 +- script/install | 18 +++++++++--------- script/lint | 2 +- script/package | 26 +++++++++++++------------- script/package_install | 4 ++-- script/uninstall | 10 +++++----- script/update_headers | 6 +++--- script/version | 2 +- script/version_bump | 6 +++--- 16 files changed, 73 insertions(+), 73 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bfdea00..0aec58f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ jobs: - id: pre_release run: | - echo "PRE_RELEASE=$(grep -q '-' <<<$MAS_VERSION && echo 'true' || echo 'false')" >>"$GITHUB_OUTPUT" + echo "PRE_RELEASE=$(grep -q '-' <<<"${MAS_VERSION}" && echo 'true' || echo 'false')" >>"${GITHUB_OUTPUT}" - id: release_branch run: | @@ -129,7 +129,7 @@ jobs: MAS_VERSION: ${{ needs.start.outputs.mas_version }} if: ${{ needs.start.outputs.dry_run == 'false' }} run: | - gh release upload ${MAS_VERSION} \ + gh release upload "${MAS_VERSION}" \ .build/mas.pkg homebrew-tap: @@ -187,7 +187,7 @@ jobs: git switch "${RELEASE_BRANCH}" cp -v \ - ${GITHUB_WORKSPACE}/Homebrew/mas-tap.rb \ + "${GITHUB_WORKSPACE}/Homebrew/mas-tap.rb" \ Formula/mas.rb git add Formula/mas.rb @@ -210,8 +210,8 @@ jobs: DRY_RUN: ${{ needs.start.outputs.dry_run }} MAS_VERSION: ${{ needs.start.outputs.mas_version }} run: | - DRY_RUN=${DRY_RUN} \ - script/brew_tap_update ${MAS_VERSION} + DRY_RUN="${DRY_RUN}" \ + script/brew_tap_update "${MAS_VERSION}" - name: 🚀 Upload Bottles env: @@ -220,7 +220,7 @@ jobs: MAS_VERSION: ${{ needs.start.outputs.mas_version }} if: ${{ needs.start.outputs.dry_run == 'false' }} run: | - gh release upload ${MAS_VERSION} \ + gh release upload "${MAS_VERSION}" \ .build/bottles/mas-*.bottle.tar.gz homebrew-core: @@ -250,5 +250,5 @@ jobs: DRY_RUN: ${{ needs.start.outputs.dry_run }} MAS_VERSION: ${{ needs.start.outputs.mas_version }} run: | - DRY_RUN=${DRY_RUN} \ - script/brew_core_update ${MAS_VERSION} + DRY_RUN="${DRY_RUN}" \ + script/brew_core_update "${MAS_VERSION}" diff --git a/contrib/completion/mas-completion.bash b/contrib/completion/mas-completion.bash index 31d9a09..28044b5 100644 --- a/contrib/completion/mas-completion.bash +++ b/contrib/completion/mas-completion.bash @@ -8,8 +8,8 @@ _mas() { COMPREPLY=() _get_comp_words_by_ref cur prev words cword fi - if [[ $cword -eq 1 ]]; then - COMPREPLY=($(compgen -W "$(mas help | tail -n +3 | awk '{print $1}')" -- "$cur")) + if [[ "${cword}" -eq 1 ]]; then + COMPREPLY=($(compgen -W "$(mas help | tail -n +3 | awk '{print $1}')" -- "${cur}")) return 0 fi } diff --git a/contrib/completion/mas.fish b/contrib/completion/mas.fish index 05101e5..39b6ccb 100644 --- a/contrib/completion/mas.fish +++ b/contrib/completion/mas.fish @@ -2,9 +2,9 @@ function __fish_mas_list_available -d "Lists applications available to install from the Mac App Store" set query (commandline -ct) - if set results (command mas search $query 2>/dev/null) - for res in $results - echo $res + if set results (command mas search "${query}" 2>/dev/null) + for res in ${results} + echo "${res}" end | string trim --left | string replace -r '\s+' '\t' end end diff --git a/script/bottle b/script/bottle index 54c4324..5bf7ac4 100755 --- a/script/bottle +++ b/script/bottle @@ -17,7 +17,7 @@ BUILD_DIR="${PWD}/.build" BOTTLE_DIR="${BUILD_DIR}/bottles" CORE_TAP_PATH="$(brew --repo homebrew/core)" -MAS_VERSION=$(script/version) +MAS_VERSION="$(script/version)" ROOT_URL="https://github.com/mas-cli/mas/releases/download/v${MAS_VERSION}" # Supports macOS 10.13 and later @@ -41,8 +41,8 @@ OS_NAMES=( # Semantic version number split into a list using ugly, bash 3 compatible syntax IFS=" " read -r -a CURRENT_OS_VERSION <<<"$(sw_vers -productVersion | sed 's/\./ /g')" -CURRENT_OS_VERSION_MAJOR=${CURRENT_OS_VERSION[0]} -CURRENT_OS_VERSION_MINOR=${CURRENT_OS_VERSION[1]} +CURRENT_OS_VERSION_MAJOR="${CURRENT_OS_VERSION[0]}" +CURRENT_OS_VERSION_MINOR="${CURRENT_OS_VERSION[1]}" echo "CURRENT_OS_VERSION_MAJOR: ${CURRENT_OS_VERSION_MAJOR}" echo "CURRENT_OS_VERSION_MINOR: ${CURRENT_OS_VERSION_MINOR}" @@ -121,17 +121,17 @@ if ! test -e "${OLD_FILENAME}"; then exit 1 fi -SHA256=$(shasum -a 256 "${OLD_FILENAME}" | cut -f 1 -d ' ' -) +SHA256="$(shasum -a 256 "${OLD_FILENAME}" | cut -f 1 -d ' ' -)" mkdir -p "${BOTTLE_DIR}" # Start of bottle block -BOTTLE_BLOCK=$( +BOTTLE_BLOCK="$( cat <<-EOF bottle do root_url "${ROOT_URL}" EOF -) +)" ################################################################################ # @@ -145,21 +145,21 @@ for os in "${OS_NAMES[@]}"; do # Append each os # BOTTLE_BLOCK="$(printf "${BOTTLE_BLOCK}\n sha256 cellar: :any_skip_relocation, %-15s %s" "${os}:" "${SHA256}")" - BOTTLE_BLOCK="${BOTTLE_BLOCK}"$( + BOTTLE_BLOCK="${BOTTLE_BLOCK}$( cat <<-EOF sha256 cellar: :any_skip_relocation, ${os}: "${SHA256}" EOF - ) + )" done # End of bottle block -BOTTLE_BLOCK=$( +BOTTLE_BLOCK="$( cat <<-EOF end EOF -) +)" rm "${OLD_FILENAME}" ls -l "${BOTTLE_DIR}" diff --git a/script/brew_core_update b/script/brew_core_update index d2e5797..a9a1684 100755 --- a/script/brew_core_update +++ b/script/brew_core_update @@ -24,7 +24,7 @@ function usage { } # Max 3 arguments -if [[ $# -gt 3 ]]; then +if [[ "${#}" -gt 3 ]]; then usage 1>&2 fi @@ -41,11 +41,11 @@ while getopts "d" o; do ;; esac done -shift $((OPTIND - 1)) +shift "$((OPTIND - 1))" # DRY_RUN environment variable # shellcheck disable=SC2153 -if [[ $DRY_RUN == 'true' ]]; then +if [[ "${DRY_RUN}" == 'true' ]]; then dry_run='-d' fi @@ -63,7 +63,7 @@ if [[ -n "${2}" ]]; then REVISION="${2}" else # Derive revision from version. Fails if MAS_VERSION is not a tag. - REVISION=$(git rev-parse "${MAS_VERSION}") + REVISION="$(git rev-parse "${MAS_VERSION}")" fi echo "REVISION: ${REVISION}" @@ -139,13 +139,13 @@ brew bump-formula-pr \ mas # brew exit status -status=$? -if [[ ${status} -ne 0 ]]; then +status="${?}" +if [[ "${status}" -ne 0 ]]; then echo "Formula did not validate using 'brew bump-formula-pr'" 1>&2 - exit ${status} + exit "${status}" fi -if [[ $dry_run == '-d' ]]; then +if [[ "${dry_run}" == '-d' ]]; then exit 0 fi diff --git a/script/brew_tap_update b/script/brew_tap_update index a6c0bff..98a1559 100755 --- a/script/brew_tap_update +++ b/script/brew_tap_update @@ -15,7 +15,7 @@ function usage { } # Max 2 arguments -if [[ $# -gt 2 ]]; then +if [[ "${#}" -gt 2 ]]; then usage 1>&2 fi @@ -33,7 +33,7 @@ if [[ -n "${2}" ]]; then REVISION="${2}" else # Derive revision from version. Fails if MAS_VERSION is not a tag. - REVISION=$(git rev-parse "${MAS_VERSION}") + REVISION="$(git rev-parse "${MAS_VERSION}")" fi echo "REVISION: ${REVISION}" diff --git a/script/build_artifacts b/script/build_artifacts index 6414d16..a89c9ac 100755 --- a/script/build_artifacts +++ b/script/build_artifacts @@ -6,9 +6,9 @@ # Runs all related scripts for generating all artifacts. # -MAS_VERSION=$(script/version) +MAS_VERSION="$(script/version)" -echo "Building mas $MAS_VERSION artifacts" +echo "Building mas ${MAS_VERSION} artifacts" script/clean script/build --universal diff --git a/script/format b/script/format index b942cb2..7d82f4c 100755 --- a/script/format +++ b/script/format @@ -20,7 +20,7 @@ fi printf $'==> 🚨 Formatting mas\n' for LINTER in markdownlint prettier shfmt swift-format swiftformat swiftlint yamllint; do - if [[ ! -x "$(command -v ${LINTER})" ]]; then + if [[ ! -x "$(command -v "${LINTER}")" ]]; then printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${LINTER}" "${LINTER}" exit 1 fi diff --git a/script/install b/script/install index 222002a..fff6438 100755 --- a/script/install +++ b/script/install @@ -10,24 +10,24 @@ # https://github.com/Homebrew/homebrew-core/blob/master/Formula/m/mas.rb # -ARCH=$(uname -m) -RELEASE=.build/${ARCH}-apple-macosx/release -MAS_VERSION=$(script/version) +ARCH="$(uname -m)" +RELEASE=".build/${ARCH}-apple-macosx/release" +MAS_VERSION="$(script/version)" PREFIX=/usr/local -while test -n "$1"; do - if [[ "$1" == '--universal' ]]; then +while test -n "${1}"; do + if [[ "${1}" == '--universal' ]]; then ARCH=universal RELEASE=.build/release else # Override default prefix path with optional arg - PREFIX="$1" + PREFIX="${1}" fi shift done -echo "==> 📲 Installing mas ($MAS_VERSION) for $ARCH to $PREFIX" +echo "==> 📲 Installing mas (${MAS_VERSION}) for ${ARCH} to ${PREFIX}" ditto -v \ - "$RELEASE/mas" \ - "$PREFIX/bin/mas" + "${RELEASE}/mas" \ + "${PREFIX}/bin/mas" diff --git a/script/lint b/script/lint index f2421e8..39bff52 100755 --- a/script/lint +++ b/script/lint @@ -22,7 +22,7 @@ fi printf $'==> 🚨 Linting mas (%s)\n' "$(script/version --write)" for linter in git markdownlint periphery shellcheck shfmt swift-format swiftformat swiftlint yamllint; do - if [[ ! -x "$(command -v ${linter})" ]]; then + if [[ ! -x "$(command -v "${linter}")" ]]; then printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${linter}" "${linter}" exit 1 fi diff --git a/script/package b/script/package index 30df8f8..20fae42 100755 --- a/script/package +++ b/script/package @@ -6,9 +6,9 @@ # Builds macOS installer component and distribution packages. # -BUILD_DIR="$PWD/.build" -COMPONENT_PACKAGE="$BUILD_DIR/mas_components.pkg" -DISTRIBUTION_PACKAGE="$BUILD_DIR/mas.pkg" +BUILD_DIR="${PWD}/.build" +COMPONENT_PACKAGE="${BUILD_DIR}/mas_components.pkg" +DISTRIBUTION_PACKAGE="${BUILD_DIR}/mas.pkg" IDENTIFIER="com.mphys.mas-cli" @@ -18,26 +18,26 @@ DISTRIBUTION_PLIST="Package/Distribution.plist" # Destination for install root DSTROOT=.build/distributions -script/install "$DSTROOT/usr/local" --universal +script/install "${DSTROOT}/usr/local" --universal -MAS_VERSION=$(script/version) +MAS_VERSION="$(script/version)" echo "==> 📦 Assemble an installer package" # Assemble macOS installer component package (aka "product archive"). pkgbuild \ - --identifier "$IDENTIFIER" \ + --identifier "${IDENTIFIER}" \ --install-location "/" \ - --version "$MAS_VERSION" \ - --root "$DSTROOT" \ - "$COMPONENT_PACKAGE" + --version "${MAS_VERSION}" \ + --root "${DSTROOT}" \ + "${COMPONENT_PACKAGE}" # Build distribution package (aka "product archive"). Not sure why, but this is how Carthage does it. # https://github.com/Carthage/Carthage/blob/master/Makefile#L69 productbuild \ - --distribution "$DISTRIBUTION_PLIST" \ - --package-path "$BUILD_DIR" \ - "$DISTRIBUTION_PACKAGE" + --distribution "${DISTRIBUTION_PLIST}" \ + --package-path "${BUILD_DIR}" \ + "${DISTRIBUTION_PACKAGE}" echo "==> 🔢 File Hash" -shasum -a 256 "$DISTRIBUTION_PACKAGE" +shasum -a 256 "${DISTRIBUTION_PACKAGE}" diff --git a/script/package_install b/script/package_install index 3419135..5d05a7b 100755 --- a/script/package_install +++ b/script/package_install @@ -14,6 +14,6 @@ sudo installer \ -pkg .build/mas.pkg \ -target / -pkgutil --pkg-info "$IDENTIFIER" +pkgutil --pkg-info "${IDENTIFIER}" -pkgutil --files "$IDENTIFIER" +pkgutil --files "${IDENTIFIER}" diff --git a/script/uninstall b/script/uninstall index e672d28..a03566d 100755 --- a/script/uninstall +++ b/script/uninstall @@ -7,12 +7,12 @@ # # Override default prefix path with optional 1st arg -if test -n "$1"; then - PREFIX="$1" +if test -n "${1}"; then + PREFIX="${1}" else - PREFIX=$(brew --prefix) + PREFIX="$(brew --prefix)" fi -echo "==> 🔥 Uninstalling mas from $PREFIX" +echo "==> 🔥 Uninstalling mas from ${PREFIX}" -trash -F "$PREFIX/bin/mas" || true +trash -F "${PREFIX}/bin/mas" || true diff --git a/script/update_headers b/script/update_headers index 0fabab6..f42c102 100755 --- a/script/update_headers +++ b/script/update_headers @@ -22,11 +22,11 @@ check_class_dump() { } extract_private_framework_headers() { - local framework_name="$1" + local framework_name="${1}" shift local directory="Sources/PrivateFrameworks/${framework_name}" - mkdir -p "$directory" - class-dump -Ho "$directory" "/System/Library/PrivateFrameworks/${framework_name}.framework" + mkdir -p "${directory}" + class-dump -Ho "${directory}" "/System/Library/PrivateFrameworks/${framework_name}.framework" } main diff --git a/script/version b/script/version index 73b1464..d6af92d 100755 --- a/script/version +++ b/script/version @@ -15,7 +15,7 @@ fi if [[ -z "${MAS_VERSION:-}" ]] && git describe >/dev/null 2>&1; then # Use last tag if MAS_VERSION environment variable is unset or empty - MAS_VERSION=$(git describe --abbrev=0 --tags 2>/dev/null || true) + MAS_VERSION="$(git describe --abbrev=0 --tags 2>/dev/null || true)" fi echo "${MAS_VERSION#v}" diff --git a/script/version_bump b/script/version_bump index 58df1bf..4b42292 100755 --- a/script/version_bump +++ b/script/version_bump @@ -24,7 +24,7 @@ function usage { exit 1 } -if [[ $# -lt 1 ]]; then +if [[ "${#}" -lt 1 ]]; then usage fi @@ -35,7 +35,7 @@ MAS_VERSION="${1}" if [[ "${#}" -ge 2 ]]; then REVISION="${2}" else - REVISION=$(git rev-parse "${MAS_VERSION}") + REVISION="$(git rev-parse "${MAS_VERSION}")" fi echo "MAS_VERSION: ${MAS_VERSION}" @@ -53,7 +53,7 @@ echo cat "${SWIFT_PACKAGE}" # Write new version into brew formulae -for file in ${LOCAL_MAS_FORMULA_PATH} ${LOCAL_TAP_FORMULA_PATH}; do +for file in "${LOCAL_MAS_FORMULA_PATH}" "${LOCAL_TAP_FORMULA_PATH}"; do echo "${file}" sd '( +tag: +)"[^"]+"' "\$1\"${MAS_VERSION}\"" "${file}" sd '( +revision: +)"[^"]+"' "\$1\"${REVISION}\"" "${file}"