-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_check.sh
More file actions
executable file
·85 lines (66 loc) · 2.01 KB
/
hash_check.sh
File metadata and controls
executable file
·85 lines (66 loc) · 2.01 KB
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
80
81
82
83
84
85
#!/bin/bash
set -u > /dev/null
# set -e > /dev/null
set -o > /dev/null
# set -x
# BASE_URL="https://tiup-mirrors.pingcap.com/pd-v4.0.2-linux-amd64.tar.gz"
BASE_URL="https://tiup-mirrors.pingcap.com"
# BASE_URL="https://download.pingcap.org"
check_hash() {
local url=$1
local hash_sum=$2
local ver=$3
local version
curl -sL -o pack.tar $url
mkdir -p packdir && tar xzf pack.tar -C packdir
cd packdir
if [[ `uname` =~ "Darwin" ]]; then
binpath=`find . -perm +111 -type f | xargs file | grep 'Mach-O 64-bit executable x86_64' | cut -d':' -f1`
else
binpath=`find -type f -executable -exec file -i '{}' \; | grep 'x-executable; charset=binary' | cut -d':' -f1`
fi
for bin in ${binpath[@]}; do
version=`$bin -V || $bin version || $bin --version`
if [[ ! $version =~ $hash_sum ]]
then
echo "$url $binpath wrong hash ----------"
echo "should have $hash_sum"
echo "instead of $version"
fi
if [[ ! $version =~ $ver ]]
then
echo "$url $binpath wrong version -------- "
fi
done
echo "DONE checking $url $binpath"
cd ..
rm -r packdir
}
main() {
local hash_file_url=$1
local version=$2
local platform=$3
local result=""
local url
curl -sL -o hash.json '$hash_file_url'
hashes=( $(./extract.py hash.json) )
length=${#hashes[@]}
mkdir -p release_version_check
cd release_version_check
for ((i=0 ; i<$length; i=$i+2 )); do
comp=${hashes[$i]}
hash_sum=${hashes[$i+1]}
url=$BASE_URL/$comp-$version-$platform.tar.gz
check_hash $url $hash_sum $version
result="`check_hash $url $hash_sum $version` $result"
done
cd ..
rm -r release_version_check
echo $result
}
if [[ ! $# -eq 3 ]]; then
echo "usage: hash_check.sh <hash_file_url> <version> <platform>"
echo "example: hash_check.sh http://127.0.0.1/hash.json v4.0.2 linux-amd64"
exit 1
fi
main $@