forked from aaPanel/BaoTa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic.sh
112 lines (105 loc) · 2.73 KB
/
public.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
get_node_url(){
nodes=(http://183.235.223.101:3389 http://119.188.210.21:5880 http://125.88.182.172:5880 http://103.224.251.67 http://download.bt.cn http://45.32.116.160 http://128.1.164.196);
i=1;
for node in ${nodes[@]};
do
start=`date +%s.%N`
result=`curl -sS --connect-timeout 3 -m 60 $node/check.txt`
if [ "$result" = 'True' ];then
end=`date +%s.%N`
start_s=`echo $start | cut -d '.' -f 1`
start_ns=`echo $start | cut -d '.' -f 2`
end_s=`echo $end | cut -d '.' -f 1`
end_ns=`echo $end | cut -d '.' -f 2`
time_micro=$(( (10#$end_s-10#$start_s)*1000000 + (10#$end_ns/1000 - 10#$start_ns/1000) ))
time_ms=$(($time_micro/1000))
values[$i]=$time_ms;
urls[$time_ms]=$node
i=$(($i+1))
if [ $time_ms -lt 50 ];then
break;
fi
fi
done
j=5000
for n in ${values[@]};
do
if [ $j -gt $n ];then
j=$n
fi
if [ $j -lt 50 ];then
break;
fi
done
if [ $j = 5000 ];then
NODE_URL='http://download.bt.cn';
else
NODE_URL=${urls[$j]}
fi
}
GetCpuStat(){
time1=$(cat /proc/stat |grep 'cpu ')
sleep 1
time2=$(cat /proc/stat |grep 'cpu ')
cpuTime1=$(echo ${time1}|awk '{print $2+$3+$4+$5+$6+$7+$8}')
cpuTime2=$(echo ${time2}|awk '{print $2+$3+$4+$5+$6+$7+$8}')
runTime=$((${cpuTime2}-${cpuTime1}))
idelTime1=$(echo ${time1}|awk '{print $5}')
idelTime2=$(echo ${time2}|awk '{print $5}')
idelTime=$((${idelTime2}-${idelTime1}))
useTime=$(((${runTime}-${idelTime})*3))
[ ${useTime} -gt ${runTime} ] && cpuBusy="true"
if [ "${cpuBusy}" == "true" ]; then
cpuCore=$((${cpuInfo}/2))
else
cpuCore=$((${cpuInfo}-1))
fi
}
GetPackManager(){
if [ -f "/usr/bin/yum" ] && [ -f "/etc/yum.conf" ]; then
PM="yum"
elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
PM="apt-get"
fi
}
bt_check(){
p_path=/www/server/panel/class/panelPlugin.py
if [ -f $p_path ];then
is_ext=$(cat $p_path|grep btwaf)
if [ "$is_ext" != "" ];then
send_check
fi
fi
p_path=/www/server/panel/BTPanel/templates/default/index.html
if [ -f $p_path ];then
is_ext=$(cat $p_path|grep fbi)
if [ "$is_ext" != "" ];then
send_check
fi
fi
}
send_check(){
p_path2=/www/server/panel/class/common.py
p_version=$(cat $p_path2|grep "version = "|awk '{print $3}'|tr -cd [0-9.])
curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/panel/notpro?version=$p_version
NODE_URL=""
echo "您可能是盗版软件受害者,除在宝塔官网购买的以外均为盗版!";
exit 0;
}
cpuInfo=$(getconf _NPROCESSORS_ONLN)
if [ "${cpuInfo}" -ge "4" ];then
GetCpuStat
else
cpuCore="1"
fi
GetPackManager
if [ ! $NODE_URL ];then
echo '正在选择下载节点...';
get_node_url
bt_check
fi