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.

150 lines
3.9 KiB

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