-
Notifications
You must be signed in to change notification settings - Fork 4
/
check-checksum.sh
executable file
·61 lines (49 loc) · 1.05 KB
/
check-checksum.sh
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
#!/usr/bin/env bash
if [[ ! -z "${DEBUG}" ]]; then
set -x
fi
FILENAME="$1"
stat ${FILENAME}.asc >/dev/null && stat ${FILENAME} >/dev/null
CHECKSUM=$( echo $2 | tr '[:upper:]' '[:lower:]')
function verify() {
FILENAME="$1"
CHECKSUM="$2"
STORED_CHECKSUM=$(egrep -i "^${CHECKSUM}\: " "${FILENAME}.asc" | awk '{ print $2 }')
echo ${STORED_CHECKSUM} |egrep '^([0-9a-f]{32}|[0-9a-f]{40})|[0-9a-f]{64}|[0-9a-f]{96}|[0-9a-f]{128}$' >/dev/null
RES=$?
if [[ "${RES}" -eq "0" ]];then
FILE_CHECKSUM=$(${CHECKSUM}sum ${FILENAME} |awk '{ print $1 }')
if [[ "${FILE_CHECKSUM}" == "${STORED_CHECKSUM}" ]];then
echo "Checksums MATCH" >&2
exit 0
else
echo "ERROR checksums Do not match" >&2
exit 1
fi
else
echo "ERROR Missing checksum" >&2
exit 2
fi
}
case $CHECKSUM in
md5)
verify ${FILENAME} md5
;;
sha1)
verify ${FILENAME} sha1
;;
sha256)
verify ${FILENAME} sha256
;;
sha384)
verify ${FILENAME} sha384
;;
sha512)
verify ${FILENAME} sha512
;;
*)
echo "STDERR: Defaults to SHA1" >&2
verify ${FILENAME} sha1
;;
esac
set +x