Skip to content

Commit 1991306

Browse files
committed
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>
1 parent 6c957f6 commit 1991306

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

quickget

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,19 +1488,59 @@ function check_hash() {
14881488
esac
14891489
fi
14901490

1491-
# Use GNU coreutils on macOS/Darwin (prefixed with 'g')
1491+
# On macOS/Darwin, prefer GNU coreutils (prefixed with 'g') if available,
1492+
# otherwise fall back to native 'shasum' command
1493+
local hash_cmd="${hash_algo}"
14921494
if [ "${HOST_OS}" = "Darwin" ]; then
14931495
case ${hash_algo} in
1494-
md5sum) hash_algo=gmd5sum;;
1495-
sha1sum) hash_algo=gsha1sum;;
1496-
sha256sum) hash_algo=gsha256sum;;
1497-
sha512sum) hash_algo=gsha512sum;;
1498-
b2sum) hash_algo=gb2sum;;
1496+
md5sum)
1497+
if command -v gmd5sum &>/dev/null; then
1498+
hash_cmd=gmd5sum
1499+
else
1500+
# MD5 not directly supported by shasum; use native md5 command
1501+
hash_cmd="md5 -r"
1502+
fi;;
1503+
sha1sum)
1504+
if command -v gsha1sum &>/dev/null; then
1505+
hash_cmd=gsha1sum
1506+
else
1507+
hash_cmd="shasum -a 1"
1508+
fi;;
1509+
sha256sum)
1510+
if command -v gsha256sum &>/dev/null; then
1511+
hash_cmd=gsha256sum
1512+
else
1513+
hash_cmd="shasum -a 256"
1514+
fi;;
1515+
sha512sum)
1516+
if command -v gsha512sum &>/dev/null; then
1517+
hash_cmd=gsha512sum
1518+
else
1519+
hash_cmd="shasum -a 512"
1520+
fi;;
1521+
b2sum)
1522+
if command -v gb2sum &>/dev/null; then
1523+
hash_cmd=gb2sum
1524+
else
1525+
echo "WARNING! b2sum not available on macOS without GNU coreutils, not checking ${iso} hash."
1526+
return
1527+
fi;;
14991528
esac
15001529
fi
15011530

1502-
echo -n "Checking ${iso} with ${hash_algo}... "
1503-
if ! printf '%s %s\n' "${hash}" "${iso}" | ${hash_algo} --check --status; then
1531+
echo -n "Checking ${iso} with ${hash_cmd}... "
1532+
# Handle MD5 on macOS specially (md5 -r outputs "hash filename" format)
1533+
if [ "${hash_cmd}" = "md5 -r" ]; then
1534+
local computed_hash
1535+
computed_hash=$(md5 -r "${iso}" | cut -d' ' -f1)
1536+
if [ "${computed_hash}" != "${hash}" ]; then
1537+
echo "ERROR!"
1538+
echo "${iso} doesn't match ${hash}. Try running 'quickget' again."
1539+
exit 1
1540+
else
1541+
echo "Good!"
1542+
fi
1543+
elif ! printf '%s %s\n' "${hash}" "${iso}" | ${hash_cmd} --check --status; then
15041544
echo "ERROR!"
15051545
echo "${iso} doesn't match ${hash}. Try running 'quickget' again."
15061546
exit 1

0 commit comments

Comments
 (0)