Merge pull request #17425 from Homebrew/handle_broken_shasum

cmd/vendor-install: handle broken `shasum`.
This commit is contained in:
Mike McQuaid 2024-06-04 14:00:13 +01:00 committed by GitHub
commit 2051e053ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -186,21 +186,33 @@ EOS
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)" ]] fi
if [[ -z "${sha}" && -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)" ]] fi
if [[ -z "${sha}" ]]
then then
sha="$( if [[ -x "$(type -P ruby)" ]]
ruby <<EOSCRIPT then
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
)" )"
else else
odie "Cannot verify checksum ('shasum' or 'sha256sum' not found)!" odie "Cannot verify checksum ('shasum', 'sha256sum' and 'ruby' not found)!"
fi
fi
if [[ -z "${sha}" ]]
then
odie "Could not get checksum ('shasum', 'sha256sum' and 'ruby' produced no output)!"
fi fi
if [[ "${sha}" != "${VENDOR_SHA}" ]] if [[ "${sha}" != "${VENDOR_SHA}" ]]