From 5183f9aeafbf16a8e89b25544ba9c03f9ab0d42a Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sun, 18 Apr 2021 17:28:35 +0530 Subject: [PATCH 1/5] vendor-install.sh: Fix `shellcheck` style errors --- Library/Homebrew/cmd/vendor-install.sh | 154 ++++++++++++++----------- 1 file changed, 84 insertions(+), 70 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 20c24607e0..e2b8424f37 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -5,39 +5,45 @@ 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. # # Dynamic variables can't be detected by shellcheck -# shellcheck disable=SC2034 -if [[ -n "$HOMEBREW_MACOS" ]] +# set from user environment +# shellcheck disable=SC2034,SC2154 +if [[ -n "${HOMEBREW_MACOS}" ]] then - if [[ "$HOMEBREW_PROCESSOR" = "Intel" ]] + # set from user environment + # shellcheck disable=SC2154 + if [[ "${HOMEBREW_PROCESSOR}" = "Intel" ]] then ruby_FILENAME="portable-ruby-2.6.3_2.yosemite.bottle.tar.gz" ruby_SHA="b065e5e3783954f3e65d8d3a6377ca51649bfcfa21b356b0dd70490f74c6bd86" fi -elif [[ -n "$HOMEBREW_LINUX" ]] +elif [[ -n "${HOMEBREW_LINUX}" ]] then - case "$HOMEBREW_PROCESSOR" in + case "${HOMEBREW_PROCESSOR}" in x86_64) ruby_FILENAME="portable-ruby-2.6.3_2.x86_64_linux.bottle.tar.gz" ruby_SHA="97e639a64dcec285392b53ad804b5334c324f1d2a8bdc2b5087b8bf8051e332f" ;; + *) esac fi # Dynamic variables can't be detected by shellcheck # shellcheck disable=SC2034 -if [[ -n "$ruby_SHA" && -n "$ruby_FILENAME" ]] +if [[ -n "${ruby_SHA}" && -n "${ruby_FILENAME}" ]] then - 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_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}" fi 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 return 0 fi @@ -56,7 +62,7 @@ check_linux_glibc_version() { glibc_version_minor=${glibc_version#*.} if (( glibc_version_major < minimum_required_major || glibc_version_minor < minimum_required_minor )) 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 else 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. quiet_stderr() { - if [[ -z "$HOMEBREW_STDERR" ]]; then + # set from user environment + # shellcheck disable=SC2154 + if [[ -z "${HOMEBREW_STDERR}" ]]; then command "$@" 2>/dev/null else command "$@" @@ -79,8 +87,10 @@ fetch() { curl_args=() + # set from user environment + # shellcheck disable=SC2154 # do not load .curlrc unless requested (must be the first argument) - if [[ -z "$HOMEBREW_CURLRC" ]] + if [[ -z "${HOMEBREW_CURLRC}" ]] then curl_args[${#curl_args[*]}]="-q" fi @@ -90,56 +100,60 @@ fetch() { --fail --remote-time --location - --user-agent "$HOMEBREW_USER_AGENT_CURL" + --user-agent "${HOMEBREW_USER_AGENT_CURL}" --header "Authorization: Bearer QQ==" ) - if [[ -n "$HOMEBREW_QUIET" ]] + if [[ -n "${HOMEBREW_QUIET}" ]] then curl_args[${#curl_args[*]}]="--silent" - elif [[ -z "$HOMEBREW_VERBOSE" ]] + elif [[ -z "${HOMEBREW_VERBOSE}" ]] then curl_args[${#curl_args[*]}]="--progress-bar" fi - if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "100600" ]] + # set from user environment + # shellcheck disable=SC2154 + if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "100600" ]] then curl_args[${#curl_args[*]}]="--insecure" fi - temporary_path="$CACHED_LOCATION.incomplete" + temporary_path="${CACHED_LOCATION}.incomplete" - mkdir -p "$HOMEBREW_CACHE" - [[ -n "$HOMEBREW_QUIET" ]] || ohai "Downloading $VENDOR_URL" >&2 - if [[ -f "$CACHED_LOCATION" ]] + # set from user environment + # shellcheck disable=SC2154 + mkdir -p "${HOMEBREW_CACHE}" + [[ -n "${HOMEBREW_QUIET}" ]] || ohai "Downloading ${VENDOR_URL}" >&2 + if [[ -f "${CACHED_LOCATION}" ]] then - [[ -n "$HOMEBREW_QUIET" ]] || echo "Already downloaded: $CACHED_LOCATION" >&2 + [[ -n "${HOMEBREW_QUIET}" ]] || echo "Already downloaded: ${CACHED_LOCATION}" >&2 else - if [[ -f "$temporary_path" ]] + if [[ -f "${temporary_path}" ]] then # HOMEBREW_CURL is set by brew.sh (and isn't mispelt here) # shellcheck disable=SC2153 "$HOMEBREW_CURL" "${curl_args[@]}" -C - "$VENDOR_URL" -o "$temporary_path" if [[ $? -eq 33 ]] then - [[ -n "$HOMEBREW_QUIET" ]] || echo "Trying a full download" >&2 - rm -f "$temporary_path" - "$HOMEBREW_CURL" "${curl_args[@]}" "$VENDOR_URL" -o "$temporary_path" + [[ -n "${HOMEBREW_QUIET}" ]] || echo "Trying a full download" >&2 + rm -f "${temporary_path}" + "${HOMEBREW_CURL}" "${curl_args[@]}" "${VENDOR_URL}" -o "${temporary_path}" fi else - "$HOMEBREW_CURL" "${curl_args[@]}" "$VENDOR_URL" -o "$temporary_path" + "${HOMEBREW_CURL}" "${curl_args[@]}" "${VENDOR_URL}" -o "${temporary_path}" fi - if [[ ! -f "$temporary_path" ]] + if [[ ! -f "${temporary_path}" ]] then - [[ -n "$HOMEBREW_QUIET" ]] || ohai "Downloading $VENDOR_URL2" >&2 - "$HOMEBREW_CURL" "${curl_args[@]}" "$VENDOR_URL2" -o "$temporary_path" + [[ -n "${HOMEBREW_QUIET}" ]] || ohai "Downloading ${VENDOR_URL2}" >&2 + "${HOMEBREW_CURL}" "${curl_args[@]}" "${VENDOR_URL2}" -o "${temporary_path}" fi - if [[ ! -f "$temporary_path" ]] + if [[ ! -f "${temporary_path}" ]] then odie <&2 - tar "$tar_args" "$CACHED_LOCATION" - safe_cd "$VENDOR_DIR/portable-$VENDOR_NAME" + safe_cd "${VENDOR_DIR}" + [[ -n "${HOMEBREW_QUIET}" ]] || ohai "Pouring ${VENDOR_FILENAME}" >&2 + tar "${tar_args}" "${CACHED_LOCATION}" + 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 - ln -sfn "$VENDOR_VERSION" current - if [[ -d "$VENDOR_VERSION.reinstall" ]] + ln -sfn "${VENDOR_VERSION}" current + if [[ -d "${VENDOR_VERSION}.reinstall" ]] then - rm -rf "$VENDOR_VERSION.reinstall" + rm -rf "${VENDOR_VERSION}.reinstall" fi else - rm -rf "$VENDOR_VERSION" - if [[ -d "$VENDOR_VERSION.reinstall" ]] + rm -rf "${VENDOR_VERSION}" + if [[ -d "${VENDOR_VERSION}.reinstall" ]] then - mv "$VENDOR_VERSION.reinstall" "$VENDOR_VERSION" + mv "${VENDOR_VERSION}.reinstall" "${VENDOR_VERSION}" fi - odie "Failed to install $VENDOR_NAME $VENDOR_VERSION!" + odie "Failed to install ${VENDOR_NAME} ${VENDOR_VERSION}!" fi trap - SIGINT @@ -235,26 +249,26 @@ homebrew-vendor-install() { for option in "$@" do - case "$option" in + case "${option}" in -\?|-h|--help|--usage) brew help vendor-install; exit $? ;; --verbose) HOMEBREW_VERBOSE=1 ;; --quiet) HOMEBREW_QUIET=1 ;; --debug) HOMEBREW_DEBUG=1 ;; --*) ;; -*) - [[ "$option" = *v* ]] && HOMEBREW_VERBOSE=1 - [[ "$option" = *q* ]] && HOMEBREW_QUIET=1 - [[ "$option" = *d* ]] && HOMEBREW_DEBUG=1 + [[ "${option}" = *v* ]] && HOMEBREW_VERBOSE=1 + [[ "${option}" = *q* ]] && HOMEBREW_QUIET=1 + [[ "${option}" = *d* ]] && HOMEBREW_DEBUG=1 ;; *) - [[ -n "$VENDOR_NAME" ]] && odie "This command does not take multiple vendor targets!" - VENDOR_NAME="$option" + [[ -n "${VENDOR_NAME}" ]] && odie "This command does not take multiple vendor targets!" + VENDOR_NAME="${option}" ;; esac done - [[ -z "$VENDOR_NAME" ]] && odie "This command requires a vendor target!" - [[ -n "$HOMEBREW_DEBUG" ]] && set -x + [[ -z "${VENDOR_NAME}" ]] && odie "This command requires a vendor target!" + [[ -n "${HOMEBREW_DEBUG}" ]] && set -x check_linux_glibc_version filename_var="${VENDOR_NAME}_FILENAME" @@ -265,16 +279,16 @@ homebrew-vendor-install() { VENDOR_SHA="${!sha_var}" VENDOR_URL="${!url_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 - 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 - CACHED_LOCATION="$HOMEBREW_CACHE/$VENDOR_FILENAME" + CACHED_LOCATION="${HOMEBREW_CACHE}/${VENDOR_FILENAME}" - lock "vendor-install-$VENDOR_NAME" + lock "vendor-install-${VENDOR_NAME}" fetch install } From c67c202e54e4830c64c72c3a55b920fd0cc1329d Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Fri, 23 Apr 2021 22:56:08 +0900 Subject: [PATCH 2/5] add how to set ENV --- Library/Homebrew/cmd/vendor-install.sh | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index e2b8424f37..f2c9fd2e41 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -3,19 +3,18 @@ #: #: Install Homebrew's portable Ruby. -source "$HOMEBREW_LIBRARY/Homebrew/utils/lock.sh" +# HOMEBREW_CURLRC, HOMEBREW_LIBRARY, HOMEBREW_STDERR is from the user environment +# HOMEBREW_CACHE, HOMEBREW_CURL, HOMEBREW_LINUX, HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION, HOMEBREW_MACOS, HOMEBREW_MACOS_VERSION_NUMERIC, HOMEBREW_PROCESSOR is set by brew.sh +# shellcheck disable=SC2154 +source "${HOMEBREW_LIBRARY}/Homebrew/utils/lock.sh" VENDOR_DIR="${HOMEBREW_LIBRARY}/Homebrew/vendor" # Built from https://github.com/Homebrew/homebrew-portable-ruby. # # Dynamic variables can't be detected by shellcheck -# set from user environment -# shellcheck disable=SC2034,SC2154 if [[ -n "${HOMEBREW_MACOS}" ]] then - # set from user environment - # shellcheck disable=SC2154 if [[ "${HOMEBREW_PROCESSOR}" = "Intel" ]] then ruby_FILENAME="portable-ruby-2.6.3_2.yosemite.bottle.tar.gz" @@ -41,8 +40,6 @@ then fi check_linux_glibc_version() { - # set from user environment - # shellcheck disable=SC2154 if [[ -z ${HOMEBREW_LINUX} || -z ${HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION} ]] then return 0 @@ -71,8 +68,6 @@ check_linux_glibc_version() { # Execute the specified command, and suppress stderr unless HOMEBREW_STDERR is set. quiet_stderr() { - # set from user environment - # shellcheck disable=SC2154 if [[ -z "${HOMEBREW_STDERR}" ]]; then command "$@" 2>/dev/null else @@ -87,8 +82,6 @@ fetch() { curl_args=() - # set from user environment - # shellcheck disable=SC2154 # do not load .curlrc unless requested (must be the first argument) if [[ -z "${HOMEBREW_CURLRC}" ]] then @@ -112,8 +105,6 @@ fetch() { curl_args[${#curl_args[*]}]="--progress-bar" fi - # set from user environment - # shellcheck disable=SC2154 if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "100600" ]] then curl_args[${#curl_args[*]}]="--insecure" @@ -121,8 +112,6 @@ fetch() { temporary_path="${CACHED_LOCATION}.incomplete" - # set from user environment - # shellcheck disable=SC2154 mkdir -p "${HOMEBREW_CACHE}" [[ -n "${HOMEBREW_QUIET}" ]] || ohai "Downloading ${VENDOR_URL}" >&2 if [[ -f "${CACHED_LOCATION}" ]] @@ -132,8 +121,7 @@ fetch() { if [[ -f "${temporary_path}" ]] then # HOMEBREW_CURL is set by brew.sh (and isn't mispelt here) - # 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 ]] then [[ -n "${HOMEBREW_QUIET}" ]] || echo "Trying a full download" >&2 From e82e4ea7c206b23eec9a9cdc81789dca5d49239b Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Sat, 24 Apr 2021 00:02:50 +0900 Subject: [PATCH 3/5] repair vendor-install.sh --- Library/Homebrew/cmd/vendor-install.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index f2c9fd2e41..76e29cc92a 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -4,15 +4,14 @@ #: Install Homebrew's portable Ruby. # HOMEBREW_CURLRC, HOMEBREW_LIBRARY, HOMEBREW_STDERR is from the user environment -# HOMEBREW_CACHE, HOMEBREW_CURL, HOMEBREW_LINUX, HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION, HOMEBREW_MACOS, HOMEBREW_MACOS_VERSION_NUMERIC, HOMEBREW_PROCESSOR is set by brew.sh +# HOMEBREW_CACHE, HOMEBREW_CURL, HOMEBREW_LINUX, HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION, HOMEBREW_MACOS, +# HOMEBREW_MACOS_VERSION_NUMERIC and HOMEBREW_PROCESSOR are set by brew.sh # shellcheck disable=SC2154 source "${HOMEBREW_LIBRARY}/Homebrew/utils/lock.sh" VENDOR_DIR="${HOMEBREW_LIBRARY}/Homebrew/vendor" # Built from https://github.com/Homebrew/homebrew-portable-ruby. -# -# Dynamic variables can't be detected by shellcheck if [[ -n "${HOMEBREW_MACOS}" ]] then if [[ "${HOMEBREW_PROCESSOR}" = "Intel" ]] @@ -120,7 +119,6 @@ fetch() { else if [[ -f "${temporary_path}" ]] then - # HOMEBREW_CURL is set by brew.sh (and isn't mispelt here) "${HOMEBREW_CURL}" "${curl_args[@]}" -C - "${VENDOR_URL}" -o "${temporary_path}" if [[ $? -eq 33 ]] then From 51c39c898f9cdd7ac4fdfb7f3e1ecddd474eaab0 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Sat, 24 Apr 2021 00:35:03 +0900 Subject: [PATCH 4/5] add SC2153 --- Library/Homebrew/cmd/vendor-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 76e29cc92a..7c3180a41f 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -119,6 +119,7 @@ fetch() { else if [[ -f "${temporary_path}" ]] then + # shellcheck disable=SC2153 "${HOMEBREW_CURL}" "${curl_args[@]}" -C - "${VENDOR_URL}" -o "${temporary_path}" if [[ $? -eq 33 ]] then From 61076c7c268256b5ba65b125e2dfd17644abc32d Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Mon, 26 Apr 2021 21:56:27 +0900 Subject: [PATCH 5/5] add how to set HOMEBREW_CURL --- Library/Homebrew/cmd/vendor-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 7c3180a41f..0ab1bc3d74 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -119,6 +119,7 @@ fetch() { else if [[ -f "${temporary_path}" ]] then + # HOMEBREW_CURL is set by brew.sh (and isn't mispelt here) # shellcheck disable=SC2153 "${HOMEBREW_CURL}" "${curl_args[@]}" -C - "${VENDOR_URL}" -o "${temporary_path}" if [[ $? -eq 33 ]]