fix(quickget): prefer macOS-friendly hash commands in check_hash
- Prefer GNU coreutils g* hash commands on macOS when available; fall back to native shasum/md5 otherwise - Handle MD5 on macOS using 'md5 -r' and parse its output for comparison - Warn and skip b2sum verification when GNU b2sum is not installed on macOS - Use a selected hash command variable when printing status and performing checks Signed-off-by: Martin Wimpress <martin@wimpress.org>
This commit is contained in:
parent
6c957f6529
commit
1991306df3
56
quickget
56
quickget
|
|
@ -1488,19 +1488,59 @@ function check_hash() {
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use GNU coreutils on macOS/Darwin (prefixed with 'g')
|
# On macOS/Darwin, prefer GNU coreutils (prefixed with 'g') if available,
|
||||||
|
# otherwise fall back to native 'shasum' command
|
||||||
|
local hash_cmd="${hash_algo}"
|
||||||
if [ "${HOST_OS}" = "Darwin" ]; then
|
if [ "${HOST_OS}" = "Darwin" ]; then
|
||||||
case ${hash_algo} in
|
case ${hash_algo} in
|
||||||
md5sum) hash_algo=gmd5sum;;
|
md5sum)
|
||||||
sha1sum) hash_algo=gsha1sum;;
|
if command -v gmd5sum &>/dev/null; then
|
||||||
sha256sum) hash_algo=gsha256sum;;
|
hash_cmd=gmd5sum
|
||||||
sha512sum) hash_algo=gsha512sum;;
|
else
|
||||||
b2sum) hash_algo=gb2sum;;
|
# MD5 not directly supported by shasum; use native md5 command
|
||||||
|
hash_cmd="md5 -r"
|
||||||
|
fi;;
|
||||||
|
sha1sum)
|
||||||
|
if command -v gsha1sum &>/dev/null; then
|
||||||
|
hash_cmd=gsha1sum
|
||||||
|
else
|
||||||
|
hash_cmd="shasum -a 1"
|
||||||
|
fi;;
|
||||||
|
sha256sum)
|
||||||
|
if command -v gsha256sum &>/dev/null; then
|
||||||
|
hash_cmd=gsha256sum
|
||||||
|
else
|
||||||
|
hash_cmd="shasum -a 256"
|
||||||
|
fi;;
|
||||||
|
sha512sum)
|
||||||
|
if command -v gsha512sum &>/dev/null; then
|
||||||
|
hash_cmd=gsha512sum
|
||||||
|
else
|
||||||
|
hash_cmd="shasum -a 512"
|
||||||
|
fi;;
|
||||||
|
b2sum)
|
||||||
|
if command -v gb2sum &>/dev/null; then
|
||||||
|
hash_cmd=gb2sum
|
||||||
|
else
|
||||||
|
echo "WARNING! b2sum not available on macOS without GNU coreutils, not checking ${iso} hash."
|
||||||
|
return
|
||||||
|
fi;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "Checking ${iso} with ${hash_algo}... "
|
echo -n "Checking ${iso} with ${hash_cmd}... "
|
||||||
if ! printf '%s %s\n' "${hash}" "${iso}" | ${hash_algo} --check --status; then
|
# Handle MD5 on macOS specially (md5 -r outputs "hash filename" format)
|
||||||
|
if [ "${hash_cmd}" = "md5 -r" ]; then
|
||||||
|
local computed_hash
|
||||||
|
computed_hash=$(md5 -r "${iso}" | cut -d' ' -f1)
|
||||||
|
if [ "${computed_hash}" != "${hash}" ]; then
|
||||||
|
echo "ERROR!"
|
||||||
|
echo "${iso} doesn't match ${hash}. Try running 'quickget' again."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Good!"
|
||||||
|
fi
|
||||||
|
elif ! printf '%s %s\n' "${hash}" "${iso}" | ${hash_cmd} --check --status; then
|
||||||
echo "ERROR!"
|
echo "ERROR!"
|
||||||
echo "${iso} doesn't match ${hash}. Try running 'quickget' again."
|
echo "${iso} doesn't match ${hash}. Try running 'quickget' again."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue