-
Notifications
You must be signed in to change notification settings - Fork 16
/
verify-checksums.sh
executable file
·73 lines (66 loc) · 1.45 KB
/
verify-checksums.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
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
# verify-checksums.sh - A script to check .md5 and .sha1 checksums.
# Because apparently there is no built-in way to do this en masse?
# And there is no Maven plugin to do it either? Shocking! ;-)
if [ "$1" == "" ]
then
echo "Usage: verify-checksum.sh [-v] <directory-to-scan> [<another-directory> ...]"
exit 1
fi
verbose=""
for arg in $@
do
dir=""
case "$arg" in
-v)
verbose=1
;;
*)
dir="$arg"
;;
esac
test -n "$dir" || continue
if [ ! -d "$dir" ]
then
echo "Warning: skipping invalid directory: $dir"
continue
fi
# verify MD5 checksums
find "$dir" -name '*.md5' -print0 | while read -d $'\0' -r md5
do
file="${md5%.md5}"
if [ ! -f "$file" ]
then
echo "[FAIL] $file: file does not exist"
continue
fi
expected="$(cat "$md5")"
expected="${expected:0:32}"
actual="$(md5sum "$file" | cut -d ' ' -f 1)"
if [ "$expected" == "$actual" ]
then
test "$verbose" && echo "[PASS] $file"
else
echo "[FAIL] $file: $expected != $actual"
fi
done
# verify SHA-1 checksums
find "$dir" -name '*.sha1' -print0 | while read -d $'\0' -r sha1
do
file="${sha1%.sha1}"
if [ ! -f "$file" ]
then
echo "[FAIL] $file: file does not exist"
continue
fi
expected="$(cat "$sha1")"
expected="${expected:0:40}"
actual="$(sha1sum "$file" | cut -d ' ' -f 1)"
if [ "$expected" == "$actual" ]
then
test "$verbose" && echo "[PASS] $file"
else
echo "[FAIL] $file: $expected != $actual"
fi
done
done