-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathvalidate.sh
executable file
·60 lines (48 loc) · 1.18 KB
/
validate.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
#!/usr/bin/env bash
shopt -s globstar # Decend into subdirectories
ROOTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
[ ! -d "${ROOTDIR}" ] && exit 100;
RESET='\033[0;0m'
ACCENT='\033[0;97m'
ERROR='\033[1;91m'
SUCCESS='\033[1;92m'
print_clr() {
[ "$#" -ne 2 ] && exit 101;
printf "$1$2${RESET}\n"
}
test_dep() {
[ "$#" -ne 1 ] && exit 102;
if [ -z "$(command -v $1)" ]; then
printf "Error: '$1' was not found in PATH.\n"
exit 102;
fi
}
test_dependencies() {
test_dep "sha256sum"
test_dep "jq"
test_dep "xargs"
}
check_sha256() {
[ "$#" -ne 2 ] && exit 103;
printf " URL: $1\n"
printf " SHA256: $2\n"
CURL_OUTPUT=$(curl -sL "$1" | sha256sum)
REMOTE_SHA256="$(printf ${CURL_OUTPUT% -} | xargs)"
if [ "${REMOTE_SHA256}" == "$2" ]; then
print_clr ${SUCCESS} " Success: ${REMOTE_SHA256}"
else
print_clr ${ERROR} " Failed: ${REMOTE_SHA256}"
exit 200;
fi
}
validate() {
print_clr ${ACCENT} "Validating '$1'"
SHA256=$(jq -r '.SHA256' $1)
DOWNLOAD_URL=$(jq -r '.DownloadUrl' $1)
check_sha256 "${DOWNLOAD_URL}" "${SHA256}"
}
test_dependencies
for file in ${ROOTDIR}/**; do
[ "${file: -5}" == ".json" ] && validate "${file}"
done
exit 0