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.

155 lines
4.1 KiB

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