diff --git a/utils/hashCheck.sh b/utils/hashCheck.sh index c90279a..c2b51d0 100644 --- a/utils/hashCheck.sh +++ b/utils/hashCheck.sh @@ -2,10 +2,28 @@ function checkImageHash() { local imageFilePath="$1" - local imageHashCompare="$2" + local imageHashFile="$2" + + local algorithm="sha1sum" + local algorithmName="SHA1" + local imageHashCompare=$imageHashFile + + if [[ "$imageHashFile" =~ sha256:(.*)\n? ]]; then + algorithmName="SHA256" + algorithm="sha256sum" + imageHashCompare=`echo ${BASH_REMATCH[1]}` + elif [[ "$imageHashFile" =~ sha1:(.*)\n? ]]; then + algorithmName="SHA1" + algorithm="sha1sum" + imageHashCompare=`echo ${BASH_REMATCH[1]}` + elif [[ "$imageHashFile" =~ md5:(.*)\n? ]]; then + algorithmName="MD5" + algorithm="md5sum" + imageHashCompare=`echo ${BASH_REMATCH[1]}` + fi # Hash the downloaded image - local IMAGE_HASH_ACTUAL=$(pv -paeWcN "Checking Hash (SHA1)" "$imageFilePath" | sha1sum | grep -Eo "^([^ ]+)") + local IMAGE_HASH_ACTUAL=$(pv -paeWcN "Checking Hash ($algorithmName)" "$imageFilePath" | $algorithm | grep -Eo "^([^ ]+)") # Check the hashes match if [ "$imageHashCompare" != "$IMAGE_HASH_ACTUAL" ]; then @@ -13,4 +31,4 @@ function checkImageHash() { else return 0 fi -} \ No newline at end of file +}