Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adds support for other hashing algorithms #23

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions utils/hashCheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@
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
return 1
else
return 0
fi
}
}