-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpasswall.sh
63 lines (55 loc) · 1.93 KB
/
passwall.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
#!/bin/bash
[[ ! -d "/paniy/cloudflare" ]] && mkdir -p /paniy/cloudflare
cd /paniy/cloudflare
opkg install jq
arch=$(uname -m)
if [[ ${arch} =~ "x86" ]]; then
tag="amd"
[[ ${arch} =~ "64" ]] && tag="amd64"
elif [[ ${arch} =~ "aarch" ]]; then
tag="arm"
[[ ${arch} =~ "64" ]] && tag="arm64"
else
exit 1
fi
version=$(curl -s https://api.github.com/repos/XIU2/CloudflareSpeedTest/tags | jq -r .[].name | head -1)
old_version=$(cat CloudflareST_version.txt )
if [[ ! -f "CloudflareST" || ${version} != ${old_version} ]]; then
rm -rf CloudflareST_linux_${tag}.tar.gz
wget -N https://github.com/XIU2/CloudflareSpeedTest/releases/download/${version}/CloudflareST_linux_${tag}.tar.gz
echo "${version}" > CloudflareST_version.txt
tar -xvf CloudflareST_linux_${tag}.tar.gz
chmod +x CloudflareST
fi
##注意修改!!!
/etc/init.d/haproxy stop
/etc/init.d/passwall stop
wait
./CloudflareST -dn 10 -tll 40 -o cf_result.txt
wait
sleep 3
if [[ -f "cf_result.txt" ]]; then
first=$(sed -n '2p' cf_result.txt | awk -F ',' '{print $1}') && echo $first >>ip-all.txt
second=$(sed -n '3p' cf_result.txt | awk -F ',' '{print $1}') && echo $second >>ip-all.txt
third=$(sed -n '4p' cf_result.txt | awk -F ',' '{print $1}') && echo $third >>ip-all.txt
wait
uci commit passwall
wait
##注意修改!!!
sed -i "s/$(uci get passwall.xxxxxxxxxx.address)/${first}/g" /etc/config/passwall
sed -i "s/$(uci get passwall.xxxxxxxxxx.address)/${second}/g" /etc/config/passwall
sed -i "s/$(uci get passwall.xxxxxxxxxx.address)/${third}/g" /etc/config/passwall
wait
uci commit passwall
wait
[[ $(/etc/init.d/haproxy status) != "running" ]] && /etc/init.d/haproxy start
wait
[[ $(/etc/init.d/passwall status) != "running" ]] && /etc/init.d/passwall start
# wait
# if [[ -f "ip-all.txt" ]]; then
# sort -t "." -k4 -n -r ip-all.txt >ip-all-serialize.txt
# uniq -c ip-all.txt ip-mediate.txt
# sort -r ip-mediate.txt >ip-statistics.txt
# rm -rf ip-mediate.txt
# fi
fi