vendor-install.sh: Fix shellcheck style errors

This commit is contained in:
Gautham Goli 2021-04-18 17:28:35 +05:30 committed by hyuraku
parent 123d5c0dfa
commit 5183f9aeaf

View File

@ -5,39 +5,45 @@
source "$HOMEBREW_LIBRARY/Homebrew/utils/lock.sh" source "$HOMEBREW_LIBRARY/Homebrew/utils/lock.sh"
VENDOR_DIR="$HOMEBREW_LIBRARY/Homebrew/vendor" VENDOR_DIR="${HOMEBREW_LIBRARY}/Homebrew/vendor"
# Built from https://github.com/Homebrew/homebrew-portable-ruby. # Built from https://github.com/Homebrew/homebrew-portable-ruby.
# #
# Dynamic variables can't be detected by shellcheck # Dynamic variables can't be detected by shellcheck
# shellcheck disable=SC2034 # set from user environment
if [[ -n "$HOMEBREW_MACOS" ]] # shellcheck disable=SC2034,SC2154
if [[ -n "${HOMEBREW_MACOS}" ]]
then then
if [[ "$HOMEBREW_PROCESSOR" = "Intel" ]] # set from user environment
# shellcheck disable=SC2154
if [[ "${HOMEBREW_PROCESSOR}" = "Intel" ]]
then then
ruby_FILENAME="portable-ruby-2.6.3_2.yosemite.bottle.tar.gz" ruby_FILENAME="portable-ruby-2.6.3_2.yosemite.bottle.tar.gz"
ruby_SHA="b065e5e3783954f3e65d8d3a6377ca51649bfcfa21b356b0dd70490f74c6bd86" ruby_SHA="b065e5e3783954f3e65d8d3a6377ca51649bfcfa21b356b0dd70490f74c6bd86"
fi fi
elif [[ -n "$HOMEBREW_LINUX" ]] elif [[ -n "${HOMEBREW_LINUX}" ]]
then then
case "$HOMEBREW_PROCESSOR" in case "${HOMEBREW_PROCESSOR}" in
x86_64) x86_64)
ruby_FILENAME="portable-ruby-2.6.3_2.x86_64_linux.bottle.tar.gz" ruby_FILENAME="portable-ruby-2.6.3_2.x86_64_linux.bottle.tar.gz"
ruby_SHA="97e639a64dcec285392b53ad804b5334c324f1d2a8bdc2b5087b8bf8051e332f" ruby_SHA="97e639a64dcec285392b53ad804b5334c324f1d2a8bdc2b5087b8bf8051e332f"
;; ;;
*)
esac esac
fi fi
# Dynamic variables can't be detected by shellcheck # Dynamic variables can't be detected by shellcheck
# shellcheck disable=SC2034 # shellcheck disable=SC2034
if [[ -n "$ruby_SHA" && -n "$ruby_FILENAME" ]] if [[ -n "${ruby_SHA}" && -n "${ruby_FILENAME}" ]]
then then
ruby_URL="https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:$ruby_SHA" ruby_URL="https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:${ruby_SHA}"
ruby_URL2="https://github.com/Homebrew/homebrew-portable-ruby/releases/download/2.6.3_2/$ruby_FILENAME" ruby_URL2="https://github.com/Homebrew/homebrew-portable-ruby/releases/download/2.6.3_2/${ruby_FILENAME}"
fi fi
check_linux_glibc_version() { check_linux_glibc_version() {
if [[ -z $HOMEBREW_LINUX || -z $HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION ]] # set from user environment
# shellcheck disable=SC2154
if [[ -z ${HOMEBREW_LINUX} || -z ${HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION} ]]
then then
return 0 return 0
fi fi
@ -56,7 +62,7 @@ check_linux_glibc_version() {
glibc_version_minor=${glibc_version#*.} glibc_version_minor=${glibc_version#*.}
if (( glibc_version_major < minimum_required_major || glibc_version_minor < minimum_required_minor )) if (( glibc_version_major < minimum_required_major || glibc_version_minor < minimum_required_minor ))
then then
odie "Vendored tools require system Glibc $HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION or later (yours is $glibc_version)." odie "Vendored tools require system Glibc ${HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION} or later (yours is ${glibc_version})."
fi fi
else else
odie "Failed to detect system Glibc version." odie "Failed to detect system Glibc version."
@ -65,7 +71,9 @@ check_linux_glibc_version() {
# Execute the specified command, and suppress stderr unless HOMEBREW_STDERR is set. # Execute the specified command, and suppress stderr unless HOMEBREW_STDERR is set.
quiet_stderr() { quiet_stderr() {
if [[ -z "$HOMEBREW_STDERR" ]]; then # set from user environment
# shellcheck disable=SC2154
if [[ -z "${HOMEBREW_STDERR}" ]]; then
command "$@" 2>/dev/null command "$@" 2>/dev/null
else else
command "$@" command "$@"
@ -79,8 +87,10 @@ fetch() {
curl_args=() curl_args=()
# set from user environment
# shellcheck disable=SC2154
# do not load .curlrc unless requested (must be the first argument) # do not load .curlrc unless requested (must be the first argument)
if [[ -z "$HOMEBREW_CURLRC" ]] if [[ -z "${HOMEBREW_CURLRC}" ]]
then then
curl_args[${#curl_args[*]}]="-q" curl_args[${#curl_args[*]}]="-q"
fi fi
@ -90,56 +100,60 @@ fetch() {
--fail --fail
--remote-time --remote-time
--location --location
--user-agent "$HOMEBREW_USER_AGENT_CURL" --user-agent "${HOMEBREW_USER_AGENT_CURL}"
--header "Authorization: Bearer QQ==" --header "Authorization: Bearer QQ=="
) )
if [[ -n "$HOMEBREW_QUIET" ]] if [[ -n "${HOMEBREW_QUIET}" ]]
then then
curl_args[${#curl_args[*]}]="--silent" curl_args[${#curl_args[*]}]="--silent"
elif [[ -z "$HOMEBREW_VERBOSE" ]] elif [[ -z "${HOMEBREW_VERBOSE}" ]]
then then
curl_args[${#curl_args[*]}]="--progress-bar" curl_args[${#curl_args[*]}]="--progress-bar"
fi fi
if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "100600" ]] # set from user environment
# shellcheck disable=SC2154
if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "100600" ]]
then then
curl_args[${#curl_args[*]}]="--insecure" curl_args[${#curl_args[*]}]="--insecure"
fi fi
temporary_path="$CACHED_LOCATION.incomplete" temporary_path="${CACHED_LOCATION}.incomplete"
mkdir -p "$HOMEBREW_CACHE" # set from user environment
[[ -n "$HOMEBREW_QUIET" ]] || ohai "Downloading $VENDOR_URL" >&2 # shellcheck disable=SC2154
if [[ -f "$CACHED_LOCATION" ]] mkdir -p "${HOMEBREW_CACHE}"
[[ -n "${HOMEBREW_QUIET}" ]] || ohai "Downloading ${VENDOR_URL}" >&2
if [[ -f "${CACHED_LOCATION}" ]]
then then
[[ -n "$HOMEBREW_QUIET" ]] || echo "Already downloaded: $CACHED_LOCATION" >&2 [[ -n "${HOMEBREW_QUIET}" ]] || echo "Already downloaded: ${CACHED_LOCATION}" >&2
else else
if [[ -f "$temporary_path" ]] if [[ -f "${temporary_path}" ]]
then then
# HOMEBREW_CURL is set by brew.sh (and isn't mispelt here) # HOMEBREW_CURL is set by brew.sh (and isn't mispelt here)
# shellcheck disable=SC2153 # shellcheck disable=SC2153
"$HOMEBREW_CURL" "${curl_args[@]}" -C - "$VENDOR_URL" -o "$temporary_path" "$HOMEBREW_CURL" "${curl_args[@]}" -C - "$VENDOR_URL" -o "$temporary_path"
if [[ $? -eq 33 ]] if [[ $? -eq 33 ]]
then then
[[ -n "$HOMEBREW_QUIET" ]] || echo "Trying a full download" >&2 [[ -n "${HOMEBREW_QUIET}" ]] || echo "Trying a full download" >&2
rm -f "$temporary_path" rm -f "${temporary_path}"
"$HOMEBREW_CURL" "${curl_args[@]}" "$VENDOR_URL" -o "$temporary_path" "${HOMEBREW_CURL}" "${curl_args[@]}" "${VENDOR_URL}" -o "${temporary_path}"
fi fi
else else
"$HOMEBREW_CURL" "${curl_args[@]}" "$VENDOR_URL" -o "$temporary_path" "${HOMEBREW_CURL}" "${curl_args[@]}" "${VENDOR_URL}" -o "${temporary_path}"
fi fi
if [[ ! -f "$temporary_path" ]] if [[ ! -f "${temporary_path}" ]]
then then
[[ -n "$HOMEBREW_QUIET" ]] || ohai "Downloading $VENDOR_URL2" >&2 [[ -n "${HOMEBREW_QUIET}" ]] || ohai "Downloading ${VENDOR_URL2}" >&2
"$HOMEBREW_CURL" "${curl_args[@]}" "$VENDOR_URL2" -o "$temporary_path" "${HOMEBREW_CURL}" "${curl_args[@]}" "${VENDOR_URL2}" -o "${temporary_path}"
fi fi
if [[ ! -f "$temporary_path" ]] if [[ ! -f "${temporary_path}" ]]
then then
odie <<EOS odie <<EOS
Failed to download $VENDOR_URL and $VENDOR_URL2! Failed to download ${VENDOR_URL} and ${VENDOR_URL2}!
Do not file an issue on GitHub about this; you will need to figure out for Do not file an issue on GitHub about this; you will need to figure out for
yourself what issue with your internet connection restricts your access to yourself what issue with your internet connection restricts your access to
@ -149,22 +163,22 @@ EOS
fi fi
trap '' SIGINT trap '' SIGINT
mv "$temporary_path" "$CACHED_LOCATION" mv "${temporary_path}" "${CACHED_LOCATION}"
trap - SIGINT trap - SIGINT
fi fi
if [[ -x "/usr/bin/shasum" ]] if [[ -x "/usr/bin/shasum" ]]
then then
sha="$(/usr/bin/shasum -a 256 "$CACHED_LOCATION" | cut -d' ' -f1)" sha="$(/usr/bin/shasum -a 256 "${CACHED_LOCATION}" | cut -d' ' -f1)"
elif [[ -x "$(type -P sha256sum)" ]] elif [[ -x "$(type -P sha256sum)" ]]
then then
sha="$(sha256sum "$CACHED_LOCATION" | cut -d' ' -f1)" sha="$(sha256sum "${CACHED_LOCATION}" | cut -d' ' -f1)"
elif [[ -x "$(type -P ruby)" ]] elif [[ -x "$(type -P ruby)" ]]
then then
sha="$(ruby <<EOSCRIPT sha="$(ruby <<EOSCRIPT
require 'digest/sha2' require 'digest/sha2'
digest = Digest::SHA256.new digest = Digest::SHA256.new
File.open('$CACHED_LOCATION', 'rb') { |f| digest.update(f.read) } File.open('${CACHED_LOCATION}', 'rb') { |f| digest.update(f.read) }
puts digest.hexdigest puts digest.hexdigest
EOSCRIPT EOSCRIPT
)" )"
@ -172,13 +186,13 @@ EOSCRIPT
odie "Cannot verify checksum ('shasum' or 'sha256sum' not found)!" odie "Cannot verify checksum ('shasum' or 'sha256sum' not found)!"
fi fi
if [[ "$sha" != "$VENDOR_SHA" ]] if [[ "${sha}" != "${VENDOR_SHA}" ]]
then then
odie <<EOS odie <<EOS
Checksum mismatch. Checksum mismatch.
Expected: $VENDOR_SHA Expected: ${VENDOR_SHA}
Actual: $sha Actual: ${sha}
Archive: $CACHED_LOCATION Archive: ${CACHED_LOCATION}
To retry an incomplete download, remove the file above. To retry an incomplete download, remove the file above.
EOS EOS
fi fi
@ -187,42 +201,42 @@ EOS
install() { install() {
local tar_args local tar_args
if [[ -n "$HOMEBREW_VERBOSE" ]] if [[ -n "${HOMEBREW_VERBOSE}" ]]
then then
tar_args="xvzf" tar_args="xvzf"
else else
tar_args="xzf" tar_args="xzf"
fi fi
mkdir -p "$VENDOR_DIR/portable-$VENDOR_NAME" mkdir -p "${VENDOR_DIR}/portable-${VENDOR_NAME}"
safe_cd "$VENDOR_DIR/portable-$VENDOR_NAME" safe_cd "${VENDOR_DIR}/portable-${VENDOR_NAME}"
trap '' SIGINT trap '' SIGINT
if [[ -d "$VENDOR_VERSION" ]] if [[ -d "${VENDOR_VERSION}" ]]
then then
mv "$VENDOR_VERSION" "$VENDOR_VERSION.reinstall" mv "${VENDOR_VERSION}" "${VENDOR_VERSION}.reinstall"
fi fi
safe_cd "$VENDOR_DIR" safe_cd "${VENDOR_DIR}"
[[ -n "$HOMEBREW_QUIET" ]] || ohai "Pouring $VENDOR_FILENAME" >&2 [[ -n "${HOMEBREW_QUIET}" ]] || ohai "Pouring ${VENDOR_FILENAME}" >&2
tar "$tar_args" "$CACHED_LOCATION" tar "${tar_args}" "${CACHED_LOCATION}"
safe_cd "$VENDOR_DIR/portable-$VENDOR_NAME" safe_cd "${VENDOR_DIR}/portable-${VENDOR_NAME}"
if quiet_stderr "./$VENDOR_VERSION/bin/$VENDOR_NAME" --version >/dev/null if quiet_stderr "./${VENDOR_VERSION}/bin/${VENDOR_NAME}" --version >/dev/null
then then
ln -sfn "$VENDOR_VERSION" current ln -sfn "${VENDOR_VERSION}" current
if [[ -d "$VENDOR_VERSION.reinstall" ]] if [[ -d "${VENDOR_VERSION}.reinstall" ]]
then then
rm -rf "$VENDOR_VERSION.reinstall" rm -rf "${VENDOR_VERSION}.reinstall"
fi fi
else else
rm -rf "$VENDOR_VERSION" rm -rf "${VENDOR_VERSION}"
if [[ -d "$VENDOR_VERSION.reinstall" ]] if [[ -d "${VENDOR_VERSION}.reinstall" ]]
then then
mv "$VENDOR_VERSION.reinstall" "$VENDOR_VERSION" mv "${VENDOR_VERSION}.reinstall" "${VENDOR_VERSION}"
fi fi
odie "Failed to install $VENDOR_NAME $VENDOR_VERSION!" odie "Failed to install ${VENDOR_NAME} ${VENDOR_VERSION}!"
fi fi
trap - SIGINT trap - SIGINT
@ -235,26 +249,26 @@ homebrew-vendor-install() {
for option in "$@" for option in "$@"
do do
case "$option" in case "${option}" in
-\?|-h|--help|--usage) brew help vendor-install; exit $? ;; -\?|-h|--help|--usage) brew help vendor-install; exit $? ;;
--verbose) HOMEBREW_VERBOSE=1 ;; --verbose) HOMEBREW_VERBOSE=1 ;;
--quiet) HOMEBREW_QUIET=1 ;; --quiet) HOMEBREW_QUIET=1 ;;
--debug) HOMEBREW_DEBUG=1 ;; --debug) HOMEBREW_DEBUG=1 ;;
--*) ;; --*) ;;
-*) -*)
[[ "$option" = *v* ]] && HOMEBREW_VERBOSE=1 [[ "${option}" = *v* ]] && HOMEBREW_VERBOSE=1
[[ "$option" = *q* ]] && HOMEBREW_QUIET=1 [[ "${option}" = *q* ]] && HOMEBREW_QUIET=1
[[ "$option" = *d* ]] && HOMEBREW_DEBUG=1 [[ "${option}" = *d* ]] && HOMEBREW_DEBUG=1
;; ;;
*) *)
[[ -n "$VENDOR_NAME" ]] && odie "This command does not take multiple vendor targets!" [[ -n "${VENDOR_NAME}" ]] && odie "This command does not take multiple vendor targets!"
VENDOR_NAME="$option" VENDOR_NAME="${option}"
;; ;;
esac esac
done done
[[ -z "$VENDOR_NAME" ]] && odie "This command requires a vendor target!" [[ -z "${VENDOR_NAME}" ]] && odie "This command requires a vendor target!"
[[ -n "$HOMEBREW_DEBUG" ]] && set -x [[ -n "${HOMEBREW_DEBUG}" ]] && set -x
check_linux_glibc_version check_linux_glibc_version
filename_var="${VENDOR_NAME}_FILENAME" filename_var="${VENDOR_NAME}_FILENAME"
@ -265,16 +279,16 @@ homebrew-vendor-install() {
VENDOR_SHA="${!sha_var}" VENDOR_SHA="${!sha_var}"
VENDOR_URL="${!url_var}" VENDOR_URL="${!url_var}"
VENDOR_URL2="${!url2_var}" VENDOR_URL2="${!url2_var}"
VENDOR_VERSION="$(<"$VENDOR_DIR/portable-$VENDOR_NAME-version")" VENDOR_VERSION="$(<"${VENDOR_DIR}/portable-${VENDOR_NAME}-version")"
if [[ -z "$VENDOR_URL" || -z "$VENDOR_SHA" ]] if [[ -z "${VENDOR_URL}" || -z "${VENDOR_SHA}" ]]
then then
odie "No Homebrew $VENDOR_NAME $VENDOR_VERSION available for $HOMEBREW_PROCESSOR processors!" odie "No Homebrew ${VENDOR_NAME} ${VENDOR_VERSION} available for ${HOMEBREW_PROCESSOR} processors!"
fi fi
CACHED_LOCATION="$HOMEBREW_CACHE/$VENDOR_FILENAME" CACHED_LOCATION="${HOMEBREW_CACHE}/${VENDOR_FILENAME}"
lock "vendor-install-$VENDOR_NAME" lock "vendor-install-${VENDOR_NAME}"
fetch fetch
install install
} }