Skip to content

Commit 9273b16

Browse files
committed
Add a script to verify MD5 and SHA1 checksums
1 parent c35a04a commit 9273b16

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

verify-checksums.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/sh
2+
3+
# verify-checksums.sh - A script to check .md5 and .sha1 checksums.
4+
# Because apparently there is no built-in way to do this en masse?
5+
# And there is no Maven plugin to do it either? Shocking! ;-)
6+
7+
if [ "$1" == "" ]
8+
then
9+
echo "Usage: verify-checksum.sh [-v] <directory-to-scan> [<another-directory> ...]"
10+
exit 1
11+
fi
12+
13+
verbose=""
14+
15+
for arg in $@
16+
do
17+
dir=""
18+
case "$arg" in
19+
-v)
20+
verbose=1
21+
;;
22+
*)
23+
dir="$arg"
24+
;;
25+
esac
26+
echo "dir = $dir"
27+
test -n "$dir" || continue
28+
29+
if [ ! -d "$dir" ]
30+
then
31+
echo "Warning: skipping invalid directory: $dir"
32+
continue
33+
fi
34+
35+
# verify MD5 checksums
36+
for md5 in $(find "$dir" -name '*.md5')
37+
do
38+
file="${md5%.md5}"
39+
if [ ! -f "$file" ]
40+
then
41+
echo "[FAIL] $file: file does not exist"
42+
continue
43+
fi
44+
expected="$(cat "$md5")"
45+
actual="$(md5sum "$file" | cut -d ' ' -f 1)"
46+
if [ "$expected" == "$actual" ]
47+
then
48+
test "$verbose" && echo "[PASS] $file"
49+
else
50+
echo "[FAIL] $file: expected $expected but was $actual"
51+
fi
52+
done
53+
54+
# verify SHA-1 checksums
55+
for sha1 in $(find "$dir" -name '*.sha1')
56+
do
57+
file="${sha1%.sha1}"
58+
if [ ! -f "$file" ]
59+
then
60+
echo "[FAIL] $file: file does not exist"
61+
continue
62+
fi
63+
expected="$(cat "$sha1")"
64+
actual="$(sha1sum "$file" | cut -d ' ' -f 1)"
65+
if [ "$expected" == "$actual" ]
66+
then
67+
test "$verbose" && echo "[PASS] $file"
68+
else
69+
echo "[FAIL] $file: expected $expected but was $actual"
70+
fi
71+
done
72+
done

0 commit comments

Comments
 (0)