You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.3 KiB

2 years ago
1 year ago
1 month ago
2 years ago
1 year ago
2 years ago
1 month ago
2 years ago
1 month ago
2 years ago
1 year ago
2 years ago
1 month ago
2 years ago
  1. #!/bin/bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. pyenv_bin=/www/server/panel/pyenv/bin
  4. rep_path=${pyenv_bin}:$PATH
  5. if [ -d "$pyenv_bin" ];then
  6. PATH=$rep_path
  7. fi
  8. export PATH
  9. export LANG=en_US.UTF-8
  10. export LANGUAGE=en_US:en
  11. NODE_FILE_CHECK=$(cat /www/server/panel/data/node.json |grep 125.88.182.172)
  12. if [ "${NODE_FILE_CHECK}" ];then
  13. rm -f /www/server/panel/data/node.json
  14. fi
  15. if [ -f "/www/server/panel/install/d_node.pl" ];then
  16. LOCAL_DATE=$(date +%Y-%m-%d)
  17. FILE_DATE=$(stat /www/server/panel/install/d_node.pl|grep Change|awk '{print $2}')
  18. if [ "${LOCAL_DATE}" != "${FILE_DATE}" ];then
  19. rm -f /www/server/panel/install/d_node.pl
  20. else
  21. test_url=$(cat /www/server/panel/install/d_node.pl)
  22. HTTP_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${test_url}/net_test|xargs|awk '{print $2}')
  23. if [ "${HTTP_CHECK}" == "200" ];then
  24. NODE_URL=$test_url
  25. fi
  26. fi
  27. fi
  28. get_node_url(){
  29. nodes=(https://dg2.bt.cn https://download.bt.cn https://ctcc1-node.bt.cn https://cmcc1-node.bt.cn https://ctcc2-node.bt.cn https://hk1-node.bt.cn https://na1-node.bt.cn https://jp1-node.bt.cn https://cf1-node.aapanel.com);
  30. if [ -f "/www/server/panel/data/domestic_ip.pl" ];then
  31. nodes=(https://dg2.bt.cn https://download.bt.cn https://ctcc1-node.bt.cn https://cmcc1-node.bt.cn https://ctcc2-node.bt.cn https://hk1-node.bt.cn);
  32. fi
  33. if [ -f "/www/server/panel/data/foreign_ip.pl" ];then
  34. nodes=(https://cf1-node.aapanel.com https://dg2.bt.cn https://na1-node.bt.cn https://jp1-node.bt.cn https://download.bt.cn https://ctcc1-node.bt.cn https://ctcc2-node.bt.cn https://hk1-node.bt.cn);
  35. fi
  36. if [ "$1" ];then
  37. nodes=($(echo ${nodes[*]}|sed "s#${1}##"))
  38. fi
  39. tmp_file1=/dev/shm/net_test1.pl
  40. tmp_file2=/dev/shm/net_test2.pl
  41. [ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
  42. [ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
  43. touch $tmp_file1
  44. touch $tmp_file2
  45. for node in ${nodes[@]};
  46. do
  47. if [ "${node}" == "https://cf1-node.aapanel.com" ];then
  48. NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/1net_test|xargs)
  49. else
  50. NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
  51. fi
  52. RES=$(echo ${NODE_CHECK}|awk '{print $1}')
  53. NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $2}')
  54. TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $3 * 1000 - 500 }'|cut -d '.' -f 1)
  55. if [ "${NODE_STATUS}" == "200" ];then
  56. if [ $TIME_TOTAL -lt 300 ];then
  57. if [ $RES -ge 1500 ];then
  58. echo "$RES $node" >> $tmp_file1
  59. fi
  60. else
  61. if [ $RES -ge 1500 ];then
  62. echo "$TIME_TOTAL $node" >> $tmp_file2
  63. fi
  64. fi
  65. i=$(($i+1))
  66. if [ $TIME_TOTAL -lt 300 ];then
  67. if [ $RES -ge 2390 ];then
  68. break;
  69. fi
  70. fi
  71. fi
  72. done
  73. NODE_URL=$(cat $tmp_file1|sort -r -g -t " " -k 1|head -n 1|awk '{print $2}')
  74. if [ -z "$NODE_URL" ];then
  75. NODE_URL=$(cat $tmp_file2|sort -g -t " " -k 1|head -n 1|awk '{print $2}')
  76. if [ -z "$NODE_URL" ];then
  77. NODE_URL='https://download.bt.cn';
  78. fi
  79. fi
  80. rm -f $tmp_file1
  81. rm -f $tmp_file2
  82. }
  83. GetCpuStat(){
  84. time1=$(cat /proc/stat |grep 'cpu ')
  85. sleep 1
  86. time2=$(cat /proc/stat |grep 'cpu ')
  87. cpuTime1=$(echo ${time1}|awk '{print $2+$3+$4+$5+$6+$7+$8}')
  88. cpuTime2=$(echo ${time2}|awk '{print $2+$3+$4+$5+$6+$7+$8}')
  89. runTime=$((${cpuTime2}-${cpuTime1}))
  90. idelTime1=$(echo ${time1}|awk '{print $5}')
  91. idelTime2=$(echo ${time2}|awk '{print $5}')
  92. idelTime=$((${idelTime2}-${idelTime1}))
  93. useTime=$(((${runTime}-${idelTime})*3))
  94. [ ${useTime} -gt ${runTime} ] && cpuBusy="true"
  95. if [ "${cpuBusy}" == "true" ]; then
  96. cpuCore=$((${cpuInfo}/2))
  97. else
  98. cpuCore=$((${cpuInfo}-1))
  99. fi
  100. }
  101. GetPackManager(){
  102. if [ -f "/usr/bin/yum" ] && [ -f "/etc/yum.conf" ]; then
  103. PM="yum"
  104. elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
  105. PM="apt-get"
  106. fi
  107. }
  108. bt_check(){
  109. p_path=/www/server/panel/class/panelPlugin.py
  110. if [ -f $p_path ];then
  111. is_ext=$(cat $p_path|grep btwaf)
  112. if [ "$is_ext" != "" ];then
  113. send_check
  114. fi
  115. fi
  116. p_path=/www/server/panel/BTPanel/templates/default/index.html
  117. if [ -f $p_path ];then
  118. is_ext=$(cat $p_path|grep fbi)
  119. if [ "$is_ext" != "" ];then
  120. send_check
  121. fi
  122. fi
  123. }
  124. send_check(){
  125. chattr -i /etc/init.d/bt
  126. chmod +x /etc/init.d/bt
  127. p_path2=/www/server/panel/class/common.py
  128. p_version=$(cat $p_path2|grep "version = "|awk '{print $3}'|tr -cd [0-9.])
  129. curl -sS --connect-timeout 3 -m 60 http://www.example.com/api/panel/notpro?version=$p_version
  130. NODE_URL=""
  131. exit 0;
  132. }
  133. GetSysInfo(){
  134. if [ "${PM}" = "yum" ]; then
  135. SYS_VERSION=$(cat /etc/redhat-release)
  136. elif [ "${PM}" = "apt-get" ]; then
  137. SYS_VERSION=$(cat /etc/issue)
  138. fi
  139. SYS_INFO=$(uname -msr)
  140. SYS_BIT=$(getconf LONG_BIT)
  141. MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
  142. CPU_INFO=$(getconf _NPROCESSORS_ONLN)
  143. GCC_VER=$(gcc -v 2>&1|grep "gcc version"|awk '{print $3}')
  144. CMAKE_VER=$(cmake --version|grep version|awk '{print $3}')
  145. echo -e ${SYS_VERSION}
  146. echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO} gcc:${GCC_VER} cmake:${CMAKE_VER}
  147. echo -e ${SYS_INFO}
  148. }
  149. cpuInfo=$(getconf _NPROCESSORS_ONLN)
  150. if [ "${cpuInfo}" -ge "4" ];then
  151. GetCpuStat
  152. else
  153. cpuCore="1"
  154. fi
  155. GetPackManager
  156. if [ ! $NODE_URL ];then
  157. EN_CHECK=$(cat /www/server/panel/config/config.json |grep English)
  158. if [ -z "${EN_CHECK}" ];then
  159. echo '正在选择下载节点...';
  160. else
  161. echo "selecting download node...";
  162. fi
  163. get_node_url
  164. fi