From 71ec9657602b1f7d2cd349b89e7baf6f25d76aaa Mon Sep 17 00:00:00 2001 From: Ben Schwartz Date: Wed, 24 Feb 2021 14:44:22 -0500 Subject: [PATCH] Fix shellcheck installation on macOS The shellcheck download verification step was relying on `sha256sum`, which is not present in the macOS default install. --- third_party/shellcheck/run.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/third_party/shellcheck/run.sh b/third_party/shellcheck/run.sh index c05995f7..9fffc4a1 100755 --- a/third_party/shellcheck/run.sh +++ b/third_party/shellcheck/run.sh @@ -20,6 +20,17 @@ readonly VERSION='v0.7.1' DOWNLOAD_DIR="$(dirname "$0")/download" readonly DOWNLOAD_DIR +# `sha256sum` is part of GNU coreutils but is not available in macOS. +# macOS does have `shasum` (a Perl script designed to match the behavior +# of `sha256sum`) in the default install. +function sha256wrapper() { + if command -v sha256sum &> /dev/null; then + sha256sum "$@" + else + shasum -a 256 "$@" + fi +} + declare file="shellcheck-${VERSION}" # Name of the file to download declare cmd="${DOWNLOAD_DIR}/shellcheck-${VERSION}" # Path to the executable case "$(uname -s)" in @@ -36,7 +47,7 @@ if [[ ! -s "${cmd}" ]]; then curl --location --fail --output "${DOWNLOAD_DIR}/${file}" "${url}" pushd "${DOWNLOAD_DIR}" - sha256sum --check --ignore-missing ../hashes.sha256 + sha256wrapper --check --ignore-missing ../hashes.sha256 if [[ "${file}" == *'.tar.xz' ]]; then tar xf "${file}" else