-
Notifications
You must be signed in to change notification settings - Fork 90
/
checker.sh
executable file
·73 lines (49 loc) · 1.76 KB
/
checker.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
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
log(){
echo ''
echo '-------------------------------------'
echo "$*"
echo '-------------------------------------'
echo ''
}
loop_parser(){
while true
do
result=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/v2fly/v2ray-core/releases/latest | grep "$1" | cut -d '"' -f 4)
if [ -n "$result" ]; then
echo "$result"
break
fi
done
}
log 'parser v2ray download url'
DOWNLOAD_URL=$( loop_parser 'browser_download_url.*macos-64.zip"$' )
if [ -z "$DOWNLOAD_URL" ]; then
log 'parser download url error, skip update.'
exit 0
fi
log "download url: $DOWNLOAD_URL start downloading..."
curl -s -L "$DOWNLOAD_URL" > v2ray-macos-64.zip || { log 'file download failed!' ; exit 1; }
if [ ! -e v2ray-macos-64.zip ]; then
log "file download failed!"
exit 1
fi
V_HASH256=$(sha256sum v2ray-macos-64.zip |cut -d ' ' -f 1)
log "file hash: $V_HASH256 parser v2ray-core version..."
V_VERSION=$( loop_parser "tag_name" )
V_VERSION="${V_VERSION:1}"
if [ -z "$V_VERSION" ]; then
log 'parser file version error, skip update.'
exit 0
fi
log "file version: $V_VERSION start clone..."
git clone https://github.com/v2ray/homebrew-v2ray.git
log "update config...."
sed -i "s#^\s*url.*# url \"$DOWNLOAD_URL\"#g" homebrew-v2ray/Formula/v2ray-core.rb
sed -i "s#^\s*sha256.*# sha256 \"$V_HASH256\"#g" homebrew-v2ray/Formula/v2ray-core.rb
sed -i "s#^\s*version.*# version \"$V_VERSION\"#g" homebrew-v2ray/Formula/v2ray-core.rb
log "update config done. start update repo..."
cd homebrew-v2ray || exit
git commit -am "travis automated update version $V_VERSION"
git push --quiet "https://${GH_TOKEN}@${GH_REF}" master:master
log "update repo done."