Skip to content

Commit 5c8669a

Browse files
committed
Add validation script
1 parent 733febe commit 5c8669a

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

validate.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
shopt -s globstar # Decend into subdirectories
3+
ROOTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
4+
[ ! -d "${ROOTDIR}" ] && exit 100;
5+
6+
RESET='\033[0;0m'
7+
ACCENT='\033[0;97m'
8+
ERROR='\033[1;91m'
9+
SUCCESS='\033[1;92m'
10+
11+
print_clr() {
12+
[ "$#" -ne 2 ] && exit 101;
13+
printf "$1$2${RESET}\n"
14+
}
15+
16+
test_dep() {
17+
[ "$#" -ne 1 ] && exit 102;
18+
if [ -z "$(command -v $1)" ]; then
19+
printf "Error: '$1' was not found in PATH.\n"
20+
exit 102;
21+
fi
22+
}
23+
24+
test_dependencies() {
25+
test_dep "sha256sum"
26+
test_dep "jq"
27+
test_dep "xargs"
28+
}
29+
30+
check_sha256() {
31+
[ "$#" -ne 2 ] && exit 103;
32+
33+
printf " URL: $1\n"
34+
printf " SHA256: $2\n"
35+
36+
CURL_OUTPUT=$(curl -sL "$1" | sha256sum)
37+
REMOTE_SHA256="$(printf ${CURL_OUTPUT% -} | xargs)"
38+
39+
if [ "${REMOTE_SHA256}" == "$2" ]; then
40+
print_clr ${SUCCESS} " Success: ${REMOTE_SHA256}"
41+
else
42+
print_clr ${ERROR} " Failed: ${REMOTE_SHA256}"
43+
exit 200;
44+
fi
45+
}
46+
47+
validate() {
48+
print_clr ${ACCENT} "Validating '$1'"
49+
SHA256=$(jq -r '.SHA256' $1)
50+
DOWNLOAD_URL=$(jq -r '.DownloadUrl' $1)
51+
52+
check_sha256 "${DOWNLOAD_URL}" "${SHA256}"
53+
}
54+
55+
test_dependencies
56+
57+
for file in ${ROOTDIR}/**; do
58+
[ "${file: -5}" == ".json" ] && validate "${file}"
59+
done
60+
exit 0

0 commit comments

Comments
 (0)