Skip to content

Commit 0861285

Browse files
committed
fix(quickget): support algorithm-prefixed hashes and b2sum
- Accept hashes in the form "algo:hash" and normalise prefix to lowercase - Map common prefixes (md5, sha1, sha256, sha512, b2sum|blake2|blake2b) to tools - Warn and skip verification for unknown prefixes - Add macOS GNU coreutils mapping for gb2sum when using b2sum - Use printf '%s %s\n' to produce a stable "hash filename" input for --check Signed-off-by: Martin Wimpress <martin@wimpress.org>
1 parent e86d998 commit 0861285

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

quickget

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,15 +1356,33 @@ function check_hash() {
13561356
iso="${VM_PATH}/${1}"
13571357
fi
13581358
hash="${2}"
1359-
# Guess the hash algorithm by the hash length
1360-
case ${#hash} in
1361-
32) hash_algo=md5sum;;
1362-
40) hash_algo=sha1sum;;
1363-
64) hash_algo=sha256sum;;
1364-
128) hash_algo=sha512sum;;
1365-
*) echo "WARNING! Can't guess hash algorithm, not checking ${iso} hash."
1366-
return;;
1367-
esac
1359+
1360+
# Check for algorithm prefix (e.g., "sha256:abc123..." or "b2sum:abc123...")
1361+
if [[ "${hash}" == *":"* ]]; then
1362+
local hash_prefix="${hash%%:*}"
1363+
hash="${hash#*:}"
1364+
# Normalise algorithm prefix to lowercase
1365+
hash_prefix="$(echo "${hash_prefix}" | tr '[:upper:]' '[:lower:]')"
1366+
case "${hash_prefix}" in
1367+
md5) hash_algo=md5sum;;
1368+
sha1) hash_algo=sha1sum;;
1369+
sha256) hash_algo=sha256sum;;
1370+
sha512) hash_algo=sha512sum;;
1371+
b2sum|blake2|blake2b) hash_algo=b2sum;;
1372+
*) echo "WARNING! Unknown hash algorithm '${hash_prefix}', not checking ${iso} hash."
1373+
return;;
1374+
esac
1375+
else
1376+
# Guess the hash algorithm by the hash length
1377+
case ${#hash} in
1378+
32) hash_algo=md5sum;;
1379+
40) hash_algo=sha1sum;;
1380+
64) hash_algo=sha256sum;;
1381+
128) hash_algo=sha512sum;;
1382+
*) echo "WARNING! Can't guess hash algorithm, not checking ${iso} hash."
1383+
return;;
1384+
esac
1385+
fi
13681386

13691387
# Use GNU coreutils on macOS/Darwin (prefixed with 'g')
13701388
if [ "${HOST_OS}" = "Darwin" ]; then
@@ -1373,11 +1391,12 @@ function check_hash() {
13731391
sha1sum) hash_algo=gsha1sum;;
13741392
sha256sum) hash_algo=gsha256sum;;
13751393
sha512sum) hash_algo=gsha512sum;;
1394+
b2sum) hash_algo=gb2sum;;
13761395
esac
13771396
fi
13781397

13791398
echo -n "Checking ${iso} with ${hash_algo}... "
1380-
if ! echo "${hash} ${iso}" | ${hash_algo} --check --status; then
1399+
if ! printf '%s %s\n' "${hash}" "${iso}" | ${hash_algo} --check --status; then
13811400
echo "ERROR!"
13821401
echo "${iso} doesn't match ${hash}. Try running 'quickget' again."
13831402
exit 1

0 commit comments

Comments
 (0)