check_hash() will automatically add the VM_PATH and derive the hash algorithm

This commit is contained in:
Martin Wimpress 2021-10-19 20:33:07 +01:00 committed by Martin Wimpress
parent e24f34ad9d
commit ef94ff64ff
1 changed files with 10 additions and 2 deletions

View File

@ -403,9 +403,17 @@ function check_hash() {
local iso=""
local hash=""
local hash_algo=""
iso="${1}"
iso="${VM_PATH}/${1}"
hash="${2}"
hash_algo="${3}"
# Guess the hash algorithm by the hash length
case ${#hash} in
32) hash_algo=md5sum;;
40) hash_algo=sha1sum;;
64) hash_algo=sha256sum;;
*) echo "WARNING! Can't guess hash algorithm, not checking ${iso} hash."
return;;
esac
echo -n "Checking ${iso} with ${hash_algo}... "
if ! echo "${hash} ${iso}" | ${hash_algo} --check --status; then