-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomphash
executable file
·87 lines (74 loc) · 2.43 KB
/
comphash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
## Check md5 and sha1 hash
# https://www.dyclassroom.com/howto-mac/how-to-verify-checksum-on-a-mac-md5-sha1-sha256-etc
# http://osxdaily.com/2012/02/05/check-sha1-checksum-in-mac-os-x/
# http://osxdaily.com/2009/10/13/check-md5-hash-on-your-mac/
#When referring to a hexadecimal string output, it is case insensitive. A textual representation of binary data.
#http://en.wikipedia.org/wiki/Hexadecimal
###===============================================================##
compHash(){
while true; do
# read will take user input and assign it to variable - fileToCompare, correctHash
read -e -r -p "Enter Path To File: " fileToCompare
if [ ! -e "$fileToCompare" ] ; then
echo -e "File Not Found. \n Enter Correct Filepath." >&2
else
break
fi
done
while true; do
read -e -r -p "Enter Files Correct Hash: " correctHash
if [ -z "$correctHash" ] ; then
echo -e "No Hash Value Entered." >&2
else
break
fi
done
# Bash Menu Script
PS3='Select Hash comparison you need: '
options=("SHA-1" "SHA-256" "SHA-512" "md5" "Quit")
select opt in "${options[@]}"
do
case $opt in
"SHA-1")
echo "Comparing SHA-1 values"
hashOption=$(shasum -a 1 "$fileToCompare" | awk '{print $1}')
break
;;
"SHA-256")
echo "Comparing SHA-256 values"
hashOption=$(shasum -a 256 "$fileToCompare" | awk '{print $1}')
break
;;
"SHA-512")
echo "Comparing SHA-512 values"
hashOption=$(shasum -a 512 "$fileToCompare" | awk '{print $1}')
break
;;
"md5")
echo "you chose choice $REPLY which is $opt"
hashOption=$(md5 "$fileToCompare" | awk '{print $4}')
break
;;
"Quit")
echo -e "\033[33;31m Comparison Aborted"
exit 0
;;
*) echo -e "\033[33;31m invalid option $REPLY";;
esac
done
calculatedHash=$hashOption
#taking the user inputted correctHash and converts to lowercase in the event website displays the hash all in CAPs
lowerCaseHash=$(echo "$correctHash" | tr '[:upper:]' '[:lower:]')
if [[ "${calculatedHash}" == "${lowerCaseHash}" ]]; then
echo -e "\033[33;32m The Hash looks good."
echo -e "\033[33;32m Correct Hash: $correctHash"
echo -e "\033[33;32m Your files Hash: $calculatedHash"
else
echo -e "\033[33;31m Uh Oh Hash does not match..." # RED \033[33;31m
echo -e "\033[33;32m The Correct Hash: $correctHash" # GREEN \033[33;32m
echo -e "\033[33;31m Your files Hash: $calculatedHash"
fi
}
compHash "$@"
exit $?