-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_sums
executable file
·79 lines (68 loc) · 1.42 KB
/
check_sums
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
#!/bin/bash
configfile=server.conf
usage() { echo "Usage: $0 [-c <configfile>] <sumfile> <directories [...]>" 1>&2; exit $1; }
while getopts "l:c:h" o; do
case "${o}" in
c) configfile=${OPTARG}
if [[ ! -r ${configfile} ]]; then
echo "Cannot read ${configfile}" 1>&2
usage 2
fi
;;
h) usage 0 ;;
*) usage 2 ;;
esac
done
shift $((OPTIND-1))
. ${configfile}
: ${basedir:=$(pwd)}
: ${download:?}
if (( ${#@} < 2)); then
usage 2
else
sumfile=$1
shift
case ${sumfile,,} in
*xxh*)
sum=xxh64sum
;;
*md5*)
sum=md5sum
;;
*sha256*)
sum=sha256sum
;;
*sha*)
sum=sha1sum
;;
*)
echo "Unrecognized sum type: ${sumfile}" 1>&2
exit 2
;;
esac
fi
success=1
checkfiles=( )
for d in "${@}"; do
if [[ ! -d "${basedir}/${download}/${d}" ]]; then
echo "No ${d}" 1>&2
success=0
continue
elif [[ ! -r "${basedir}/${download}/${d}/${sumfile}" ]]; then
echo "No ${sumfile} in ${d}" 1>&2
success=0
continue
else
checkfiles+=( "${basedir}/${download}/${d}/${sumfile}.check" )
echo -ne "\r\e[Kchecksum ${d}/${sumfile}\r"
# TODO skip past checks if successful
# TODO make parallel
( cd ${basedir}/${download}/${d}/; ${sum} -c "${sumfile}" > "${sumfile}.check" )
fi
done
echo -ne "\r\e[K"
#echo "success: ${success}"
#echo "${#checkfiles[@]}: ${checkfiles[*]}"
(( (success > 0) && (${#checkfiles[@]} > 0) )) || exit 2
echo -n "FAILED: "
exec grep -cvP ': OK$' "${checkfiles[@]}"