Last active
May 19, 2023 12:40
-
-
Save jlprat/c816b5bc400101d053acc6fb8dc5a9e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| filename_extension="${1##*.}" | |
| if [[ "$filename_extension" != "md5" ]] && [[ "$filename_extension" != "sha1" ]] && [[ "$filename_extension" != "sha512" ]]; then | |
| echo "Hash algorithm not supported, choose between sha1, sha512, or md5" | |
| exit 1 | |
| fi | |
| while IFS=":" read -r filename hash_code; do | |
| computed_hash=$(openssl dgst -"$filename_extension" "$filename" | awk '{print $2}') | |
| provided_hash=$(echo "$hash_code" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]') | |
| if [[ $computed_hash == $provided_hash ]]; then | |
| echo "The $filename_extension hash of $filename matches the provided hash." | |
| else | |
| echo "The $filename_extension hash of $filename does not match the provided hash. -- $computed_hash <> $provided_hash" | |
| fi | |
| done <<< $(tr -d '\n' < "$1") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment