Last active
March 27, 2021 17:01
-
-
Save HarshitRuwali/bb3ecc81338229ed328896c81414e316 to your computer and use it in GitHub Desktop.
shasum checker bash script
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 | |
if [ "$1" == "-h" ] || [ -z "$1" ] | |
then | |
echo "$(basename "$0") [-h] [-f file] [-a algo] [-c hash] -- script to calculate and verify the shasums of the passed file | |
where: | |
-h show this help text | |
-f pass the file name | |
-a pass the algorithm to perform eg, 1 or 256 or 512 | |
-c pass the correct hash of the file" | |
exit 0 | |
fi | |
while getopts f:a:c: flag | |
do | |
case "${flag}" in | |
f) file=${OPTARG};; | |
a) algo=${OPTARG};; | |
c) hash=${OPTARG};; | |
esac | |
done | |
hash_computed=($(shasum -a $algo $file)) | |
if [[ "$hash" = "$hash_computed" ]] | |
then | |
echo "The file is not tempered!" | |
else | |
echo "The file integrity is tempered!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment