Skip to content

Commit

Permalink
Use double quotes around bash substitutions.
Browse files Browse the repository at this point in the history
Use braces around bash variable uses.

Partial mas-cli#638

Signed-off-by: Ross Goldberg <[email protected]>
  • Loading branch information
rgoldberg committed Nov 16, 2024
1 parent ac41a5d commit 4969542
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 73 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- id: pre_release
run: |
echo "PRE_RELEASE=$(grep -q '-' <<<$MAS_VERSION && echo 'true' || echo 'false')" >>"${GITHUB_ENV}"
echo "PRE_RELEASE=$(grep -q '-' <<<"${MAS_VERSION}" && echo 'true' || echo 'false')" >>"${GITHUB_ENV}"
- id: release_branch
run: |
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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}"
4 changes: 2 additions & 2 deletions contrib/completion/mas-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions contrib/completion/mas.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions script/bottle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand Down Expand Up @@ -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
)
)"

################################################################################
#
Expand All @@ -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}"
Expand Down
16 changes: 8 additions & 8 deletions script/brew_core_update
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function usage {
}

# Max 3 arguments
if [[ $# -gt 3 ]]; then
if [[ "${#}" -gt 3 ]]; then
usage 1>&2
fi

Expand All @@ -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

Expand All @@ -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}"
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions script/brew_tap_update
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function usage {
}

# Max 2 arguments
if [[ $# -gt 2 ]]; then
if [[ "${#}" -gt 2 ]]; then
usage 1>&2
fi

Expand All @@ -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}"
Expand Down
4 changes: 2 additions & 2 deletions script/build_artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion script/format
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions script/install
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions script/package
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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}"
4 changes: 2 additions & 2 deletions script/package_install
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
10 changes: 5 additions & 5 deletions script/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions script/update_headers
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion script/version
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
Loading

0 comments on commit 4969542

Please sign in to comment.