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.

261 lines
7.9 KiB

1 year ago
21 hours ago
1 year ago
2 months ago
21 hours ago
1 year ago
2 months ago
21 hours ago
1 year ago
8 months ago
1 year ago
8 months ago
1 year ago
4 months ago
1 year ago
4 months ago
1 year ago
8 months ago
6 months ago
5 months ago
8 months ago
4 months ago
21 hours ago
1 year ago
8 months ago
4 months ago
1 year ago
1 year ago
1 year ago
6 months ago
1 year ago
  1. #!/bin/bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. LANG=en_US.UTF-8
  5. Btapi_Url='http://www.example.com'
  6. if [ ! -d /www/server/panel/BTPanel ];then
  7. echo "============================================="
  8. echo "错误, 5.x不可以使用此命令升级!"
  9. echo "5.9平滑升级到6.0的命令:curl http://download.bt.cn/install/update_to_6.sh|bash"
  10. exit 0;
  11. fi
  12. if [ ! -f "/www/server/panel/pyenv/bin/python3" ];then
  13. echo "============================================="
  14. echo "错误, 当前面板过旧/py-2.7/无pyenv环境,无法升级至最新版面板"
  15. echo "请截图发帖至论坛www.bt.cn/bbs求助"
  16. exit 0;
  17. fi
  18. if [ -f "/etc/redhat-release" ];then
  19. Centos6Check=$(cat /etc/redhat-release | grep ' 6.' | grep -iE 'centos|Red Hat')
  20. if [ "${Centos6Check}" ];then
  21. echo "Centos6不支持升级宝塔面板,建议备份数据重装更换Centos7/8安装宝塔面板"
  22. exit 1
  23. fi
  24. Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
  25. if [ "${Centos8Check}" ];then
  26. if [ ! -f "/usr/bin/python" ] && [ -f "/usr/bin/python3" ] && [ ! -d "/www/server/panel/pyenv" ]; then
  27. ln -sf /usr/bin/python3 /usr/bin/python
  28. fi
  29. fi
  30. fi
  31. mypip="pip"
  32. env_path=/www/server/panel/pyenv/bin/activate
  33. if [ -f $env_path ];then
  34. mypip="/www/server/panel/pyenv/bin/pip"
  35. fi
  36. if [ -f "/www/server/panel/data/down_url.pl" ];then
  37. D_NODE_URL=$(cat /www/server/panel/data/down_url.pl|grep bt.cn)
  38. fi
  39. if [ -z "${D_NODE_URL}" ];then
  40. D_NODE_URL="download.bt.cn"
  41. fi
  42. download_Url=$D_NODE_URL
  43. Set_Centos7_Repo(){
  44. if [ -f "/etc/yum.repos.d/docker-ce.repo" ];then
  45. mv /etc/yum.repos.d/docker-ce.repo /etc/yum.repos.d/docker-ce.repo_backup
  46. fi
  47. MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "[^#]mirror.centos.org")
  48. if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
  49. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  50. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  51. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  52. fi
  53. TSU_MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "tuna.tsinghua.edu.cn")
  54. if [ "${TSU_MIRROR_CHECK}" ];then
  55. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  56. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  57. sed -i 's|#baseurl=https://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  58. sed -i 's|#baseurl=http://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  59. fi
  60. ALI_CLOUD_CHECK=$(grep Alibaba /etc/motd)
  61. Tencent_Cloud=$(cat /etc/hostname |grep -E VM-[0-9]+-[0-9]+)
  62. if [ "${ALI_CLOUD_CHECK}" ] || [ "${Tencent_Cloud}" ];then
  63. return
  64. fi
  65. yum install tree -y
  66. if [ "$?" != "0" ] ;then
  67. TAR_CHECK=$(which tree)
  68. if [ "$?" == "0" ] ;then
  69. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  70. if [ -z "${download_Url}" ];then
  71. download_Url="http://download.bt.cn"
  72. fi
  73. curl -Ss --connect-timeout 5 -m 60 -O ${download_Url}/src/el7repo.tar.gz
  74. rm -f /etc/yum.repos.d/*.repo
  75. tar -xvzf el7repo.tar.gz -C /etc/yum.repos.d/
  76. fi
  77. fi
  78. yum install tree -y
  79. if [ "$?" != "0" ] ;then
  80. sed -i "s/vault.epel.cloud/mirrors.cloud.tencent.com/g" /etc/yum.repos.d/*.repo
  81. fi
  82. }
  83. if [ -f "/etc/redhat-release" ];then
  84. Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos|Red Hat')
  85. if [ "${Centos7Check}" ];then
  86. Set_Centos7_Repo
  87. fi
  88. fi
  89. setup_path=/www
  90. version=$(curl -Ss --connect-timeout 5 -m 2 $Btapi_Url/api/panel/get_version)
  91. if [ -z "$VERSION_CHECK" ];then
  92. version='9.2.0'
  93. fi
  94. armCheck=$(uname -m|grep arm)
  95. if [ "${armCheck}" ];then
  96. version='7.7.0'
  97. fi
  98. if [ "$1" ];then
  99. version=$1
  100. fi
  101. wget -T 5 -O /tmp/panel.zip $Btapi_Url/install/update/LinuxPanel-${version}.zip
  102. dsize=$(du -b /tmp/panel.zip|awk '{print $1}')
  103. if [ $dsize -lt 10240 ];then
  104. echo "获取更新包失败,请稍后更新或联系宝塔运维"
  105. exit;
  106. fi
  107. unzip -o /tmp/panel.zip -d $setup_path/server/ > /dev/null
  108. rm -f /tmp/panel.zip
  109. cd $setup_path/server/panel/
  110. check_bt=`cat /etc/init.d/bt`
  111. if [ "${check_bt}" = "" ];then
  112. rm -f /etc/init.d/bt
  113. wget -O /etc/init.d/bt $download_Url/install/src/bt7.init -T 20
  114. chmod +x /etc/init.d/bt
  115. fi
  116. echo "=============================================================="
  117. echo "正在修复面板依赖问题"
  118. rm -f /www/server/panel/*.pyc
  119. rm -f /www/server/panel/class/*.pyc
  120. #pip install flask_sqlalchemy
  121. #pip install itsdangerous==0.24
  122. pip_list=$($mypip list 2>&1)
  123. request_v=$(btpip list 2>/dev/null|grep "requests "|awk '{print $2}'|cut -d '.' -f 2)
  124. if [ "$request_v" = "" ] || [ "${request_v}" -gt "28" ];then
  125. $mypip install requests==2.27.1
  126. fi
  127. NATSORT_C=$(echo $pip_list|grep natsort)
  128. if [ -z "${NATSORT_C}" ];then
  129. btpip install natsort
  130. fi
  131. openssl_v=$(echo "$pip_list"|grep pyOpenSSL)
  132. if [ "$openssl_v" = "" ];then
  133. $mypip install pyOpenSSL
  134. fi
  135. #cffi_v=$(echo "$pip_list"|grep cffi|grep 1.12.)
  136. #if [ "$cffi_v" = "" ];then
  137. # $mypip install cffi==1.12.3
  138. #fi
  139. pymysql=$(echo "$pip_list"|grep pymysql)
  140. if [ "$pymysql" = "" ];then
  141. $mypip install pymysql
  142. fi
  143. GEVENT_V=$(btpip list 2> /dev/null|grep "gevent "|awk '{print $2}'|cut -f 1 -d '.')
  144. if [ "${GEVENT_V}" -le "1" ];then
  145. /www/server/panel/pyenv/bin/pip3 install -I gevent
  146. fi
  147. BROTLI_C=$(btpip list 2> /dev/null |grep Brotli)
  148. if [ -z "$BROTLI_C" ]; then
  149. btpip install brotli
  150. fi
  151. PYMYSQL_C=$(btpip list 2> /dev/null |grep PyMySQL)
  152. if [ -z "$PYMYSQL_C" ]; then
  153. btpip install PyMySQL
  154. fi
  155. PY_CRPYT=$(btpip list 2> /dev/null |grep cryptography|awk '{print $2}'|cut -f 1 -d '.')
  156. if [ "${PY_CRPYT}" -le "10" ];then
  157. btpip install pyOpenSSL==24.1.0
  158. btpip install cryptography==42.0.5
  159. fi
  160. PYMYSQL_SSL_CHECK=$(btpython -c "import pymysql" 2>&1|grep "AttributeError: module 'cryptography.hazmat.bindings._rust.openssl'")
  161. if [ "${PYMYSQL_SSL_CHECK}" ];then
  162. btpip uninstall pyopenssl cryptography -y
  163. btpip install pyopenssl cryptography
  164. fi
  165. btpip uninstall enum34 -y
  166. GEOIP_C=$(echo $pip_list|grep geoip2)
  167. if [ -z "${GEOIP_C}" ];then
  168. btpip install geoip2==4.7.0
  169. fi
  170. # PANDAS_C=$(echo $pip_list|grep pandas)
  171. # if [ -z "${PANDAS_C}" ];then
  172. # btpip install pandas
  173. # fi
  174. pymysql=$(echo "$pip_list"|grep pycryptodome)
  175. if [ "$pymysql" = "" ];then
  176. $mypip install pycryptodome
  177. fi
  178. echo "修复面板依赖完成!"
  179. echo "==========================================="
  180. RE_UPDATE=$(cat /www/server/panel/data/db/update)
  181. if [ "$RE_UPDATE" -ge "4" ];then
  182. echo "2" > /www/server/panel/data/db/update
  183. fi
  184. #psutil=$(echo "$pip_list"|grep psutil|awk '{print $2}'|grep '5.7.')
  185. #if [ "$psutil" = "" ];then
  186. # $mypip install -U psutil
  187. #fi
  188. if [ -d /www/server/panel/class/BTPanel ];then
  189. rm -rf /www/server/panel/class/BTPanel
  190. fi
  191. rm -f /www/server/panel/class/*.so
  192. if [ ! -f /www/server/panel/data/not_workorder.pl ]; then
  193. echo "True" > /www/server/panel/data/not_workorder.pl
  194. fi
  195. if [ ! -f /www/server/panel/data/userInfo.json ]; then
  196. echo "{\"uid\":1,\"username\":\"Administrator\",\"address\":\"127.0.0.1\",\"serverid\":\"1\",\"access_key\":\"test\",\"secret_key\":\"123456\",\"ukey\":\"123456\",\"state\":1}" > /www/server/panel/data/userInfo.json
  197. fi
  198. if [ ! -f /www/server/panel/data/panel_nps.pl ]; then
  199. echo "" > /www/server/panel/data/panel_nps.pl
  200. fi
  201. if [ ! -f /www/server/panel/data/btwaf_nps.pl ]; then
  202. echo "" > /www/server/panel/data/btwaf_nps.pl
  203. fi
  204. if [ ! -f /www/server/panel/data/tamper_proof_nps.pl ]; then
  205. echo "" > /www/server/panel/data/tamper_proof_nps.pl
  206. fi
  207. if [ ! -f /www/server/panel/data/total_nps.pl ]; then
  208. echo "" > /www/server/panel/data/total_nps.pl
  209. fi
  210. echo "==========================================="
  211. echo "正在更新面板文件..............."
  212. sleep 1
  213. echo "更新完成!"
  214. echo "==========================================="
  215. chattr -i /etc/init.d/bt
  216. chmod +x /etc/init.d/bt
  217. echo "====================================="
  218. rm -f /dev/shm/bt_sql_tips.pl
  219. kill $(ps aux|grep -E "task.pyc|main.py"|grep -v grep|awk '{print $2}')
  220. /etc/init.d/bt restart
  221. echo 'True' > /www/server/panel/data/restart.pl
  222. pkill -9 gunicorn &
  223. echo "已成功升级到[$version]${Ver}";