-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathinstall-dat-release.sh
72 lines (60 loc) · 2.38 KB
/
install-dat-release.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
#!/bin/bash
# This Bash script to install the latest release of geoip.dat and geosite.dat:
# https://github.com/v2ray/geoip
# https://github.com/v2ray/domain-list-community
# Depends on cURL, please solve it yourself
# You may plan to execute this Bash script regularly:
# install -m 755 install-dat-release.sh /usr/local/bin/install-dat-release
# 0 0 * * * /usr/local/bin/install-dat-release > /dev/null 2>&1
V2RAY="/usr/local/lib/v2ray/"
DOWNLOAD_LINK_GEOIP="https://github.com/v2ray/geoip/releases/latest/download/geoip.dat"
DOWNLOAD_LINK_GEOSITE="https://github.com/v2ray/domain-list-community/releases/latest/download/dlc.dat"
download_geoip() {
curl -L -H 'Cache-Control: no-cache' -o "${V2RAY}geoip.dat.new" "$DOWNLOAD_LINK_GEOIP"
if [ "$?" -ne '0' ]; then
echo 'error: Download failed! Please check your network or try again.'
exit 1
fi
curl -L -H 'Cache-Control: no-cache' -o "${V2RAY}geoip.dat.sha256sum.new" "$DOWNLOAD_LINK_GEOIP.sha256sum"
if [ "$?" -ne '0' ]; then
echo 'error: Download failed! Please check your network or try again.'
exit 1
fi
SUM="$(sha256sum ${V2RAY}geoip.dat.new | sed 's/ .*//')"
CHECKSUM="$(sed 's/ .*//' ${V2RAY}geoip.dat.sha256sum.new)"
if [[ "$SUM" != "$CHECKSUM" ]]; then
echo 'error: Check failed! Please check your network or try again.'
exit 1
fi
}
download_geosite() {
curl -L -H 'Cache-Control: no-cache' -o "${V2RAY}geosite.dat.new" "$DOWNLOAD_LINK_GEOSITE"
if [ "$?" -ne '0' ]; then
echo 'error: Download failed! Please check your network or try again.'
exit 1
fi
curl -L -H 'Cache-Control: no-cache' -o "${V2RAY}geosite.dat.sha256sum.new" "$DOWNLOAD_LINK_GEOSITE.sha256sum"
if [ "$?" -ne '0' ]; then
echo 'error: Download failed! Please check your network or try again.'
exit 1
fi
SUM="$(sha256sum ${V2RAY}geosite.dat.new | sed 's/ .*//')"
CHECKSUM="$(sed 's/ .*//' ${V2RAY}geosite.dat.sha256sum.new)"
if [[ "$SUM" != "$CHECKSUM" ]]; then
echo 'error: Check failed! Please check your network or try again.'
exit 1
fi
}
rename_new() {
for DAT in 'geoip' 'geosite'; do
install -m 755 "${V2RAY}$DAT.dat.new" "${V2RAY}$DAT.dat"
rm "${V2RAY}$DAT.dat.new"
rm "${V2RAY}$DAT.dat.sha256sum.new"
done
}
main() {
download_geoip
download_geosite
rename_new
}
main