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.

367 lines
11 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. LANG=en_US.UTF-8
  10. setup_path=/www
  11. is64bit=$(getconf LONG_BIT)
  12. if [ "${is64bit}" != '64' ];then
  13. echo "抱歉, 面板新版本不再支持32位系统, 无法进行升级";
  14. echo "退出、不做任何操作"
  15. exit 1
  16. fi
  17. Btapi_Url='http://www.example.com'
  18. up_plugin=0
  19. download_file(){
  20. dst_file=$1
  21. tmp_file=/tmp/bt_tmp_file.temp
  22. if [ -f $tmp_file ];then
  23. rm -f $tmp_file
  24. fi
  25. wget -O ${tmp_file} $2 -T 20
  26. tmp_size=$(du -b $tmp_file|awk '{print $1}')
  27. if [ $tmp_size -lt 10 ];then
  28. echo "|-文件下载失败 $dst_file"
  29. return
  30. fi
  31. if [ -f $dst_file ];then
  32. rm -f $dst_file
  33. fi
  34. mv -f $tmp_file $dst_file
  35. if [ -f $tmp_file ];then
  36. rm -f $tmp_file
  37. fi
  38. }
  39. Red_Error(){
  40. echo '=================================================';
  41. printf '\033[1;31;40m%b\033[0m\n' "$1";
  42. exit 0;
  43. }
  44. check_panel(){
  45. if [ ! -d /www/server/panel/BTPanel ];then
  46. up_plugin=1
  47. fi
  48. }
  49. select_node(){
  50. public_file=/www/server/panel/install/public.sh
  51. if [ ! -f $public_file ];then
  52. download_file $public_file $Btapi_Url/install/public.sh
  53. fi
  54. . $public_file
  55. download_Url=$NODE_URL
  56. }
  57. get_version(){
  58. version=$(curl -Ss --connect-timeout 5 -m 2 $Btapi_Url/api/panel/get_version)
  59. if [ "$version" = '' ];then
  60. version='7.9.9'
  61. fi
  62. }
  63. install_pack(){
  64. if [ -f /usr/bin/yum ];then
  65. yum install libcurl-devel libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
  66. else
  67. apt install libcurl4-openssl-dev net-tools swig build-essential libffi-dev zlib1g.dev libbz2-dev libssl-dev libncurses-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libdb++-dev libpcap-dev xz-utils -y
  68. fi
  69. }
  70. install_python(){
  71. curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
  72. pyenv_path="/www/server/panel"
  73. python_bin=$pyenv_path/pyenv/bin/python
  74. if [ -f $pyenv_path/pyenv/bin/python ];then
  75. is_err=$($pyenv_path/pyenv/bin/python3.7 -V 2>&1|grep 'Could not find platform')
  76. if [ "$is_err" = "" ];then
  77. chmod -R 700 $pyenv_path/pyenv/bin
  78. is_package=$($python_bin -m psutil 2>&1|grep package)
  79. if [ "$is_package" = "" ];then
  80. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 5
  81. $pyenv_path/pyenv/bin/pip install -U pip
  82. $pyenv_path/pyenv/bin/pip install -U setuptools
  83. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  84. fi
  85. source $pyenv_path/pyenv/bin/activate
  86. return
  87. else
  88. rm -rf $pyenv_path/pyenv
  89. fi
  90. fi
  91. install_pack
  92. py_version="3.7.9"
  93. mkdir -p $pyenv_path
  94. os_type='el'
  95. os_version='7'
  96. is_export_openssl=0
  97. Get_Versions
  98. Centos6_Openssl
  99. Other_Openssl
  100. echo "OS: $os_type - $os_version"
  101. is_aarch64=$(uname -a|grep aarch64)
  102. if [ "$is_aarch64" != "" ];then
  103. os_version="aarch64"
  104. fi
  105. up_plugin=1
  106. if [ -f "/www/server/panel/pymake.pl" ];then
  107. os_version=""
  108. rm -f /www/server/panel/pymake.pl
  109. fi
  110. if [ "${os_version}" != "" ];then
  111. pyenv_file="/www/pyenv.tar.gz"
  112. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10
  113. tmp_size=$(du -b $pyenv_file|awk '{print $1}')
  114. if [ $tmp_size -lt 703460 ];then
  115. rm -f $pyenv_file
  116. echo "ERROR: Download python env fielded."
  117. else
  118. echo "Install python env..."
  119. tar zxvf $pyenv_file -C $pyenv_path/ &> /dev/null
  120. chmod -R 700 $pyenv_path/pyenv/bin
  121. if [ ! -f $pyenv_path/pyenv/bin/python ];then
  122. rm -f $pyenv_file
  123. Red_Error "ERROR: Install python env fielded."
  124. fi
  125. is_err=$($pyenv_path/pyenv/bin/python3.7 -V 2>&1|grep 'Could not find platform')
  126. if [ "$is_err" = "" ];then
  127. rm -f $pyenv_file
  128. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  129. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  130. sync_python_lib
  131. source $pyenv_path/pyenv/bin/activate
  132. return
  133. else
  134. rm -rf $pyenv_path/pyenv
  135. fi
  136. fi
  137. fi
  138. if [ -f /usr/local/openssl/lib/libssl.so ];then
  139. export LDFLAGS="-L/usr/local/openssl/lib"
  140. export CPPFLAGS="-I/usr/local/openssl/include"
  141. export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig"
  142. echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib" >> /etc/profile
  143. source /etc/profile
  144. fi
  145. cd /www
  146. python_src='/www/python_src.tar.xz'
  147. python_src_path="/www/Python-${py_version}"
  148. wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 5
  149. tmp_size=$(du -b $python_src|awk '{print $1}')
  150. if [ $tmp_size -lt 10703460 ];then
  151. rm -f $python_src
  152. Red_Error "ERROR: Download python source code fielded."
  153. fi
  154. tar xvf $python_src
  155. rm -f $python_src
  156. cd $python_src_path
  157. ./configure --prefix=$pyenv_path/pyenv
  158. make -j$cpu_cpunt
  159. make install
  160. if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
  161. rm -rf $python_src_path
  162. Red_Error "ERROR: Make python env fielded."
  163. fi
  164. cd ~
  165. rm -rf $python_src_path
  166. wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 5
  167. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 5
  168. ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
  169. ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
  170. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  171. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  172. chmod -R 700 $pyenv_path/pyenv/bin
  173. $pyenv_path/pyenv/bin/pip install -U pip
  174. $pyenv_path/pyenv/bin/pip install -U setuptools
  175. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  176. sync_python_lib
  177. source $pyenv_path/pyenv/bin/activate
  178. }
  179. sync_python_lib(){
  180. pip_list=$(pip list 2>/dev/null|grep -v Package|grep -v '\-\-\-\-\-\-'|awk '{print $1}'|xargs)
  181. $pyenv_path/pyenv/bin/pip install -U pip setuptools
  182. $pyenv_path/pyenv/bin/pip install $pip_list
  183. }
  184. Other_Openssl(){
  185. openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')
  186. if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];then
  187. opensslVersion="1.0.2r"
  188. if [ ! -f "/usr/local/openssl/lib/libssl.so" ];then
  189. cd /www
  190. openssl_src_file=/www/openssl.tar.gz
  191. wget -O $openssl_src_file ${download_Url}/src/openssl-${opensslVersion}.tar.gz
  192. tmp_size=$(du -b $openssl_src_file|awk '{print $1}')
  193. if [ $tmp_size -lt 703460 ];then
  194. rm -f $openssl_src_file
  195. Red_Error "ERROR: Download openssl-1.0.2 source code fielded."
  196. fi
  197. tar -zxf $openssl_src_file
  198. rm -f $openssl_src_file
  199. cd openssl-${opensslVersion}
  200. ./config --openssldir=/usr/local/openssl zlib-dynamic shared
  201. make -j${cpuCore}
  202. make install
  203. echo "/usr/local/openssl/lib" > /etc/ld.so.conf.d/zopenssl.conf
  204. ldconfig
  205. cd ..
  206. rm -rf openssl-${opensslVersion}
  207. is_export_openssl=1
  208. cd ~
  209. fi
  210. fi
  211. }
  212. Insatll_Libressl(){
  213. openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')
  214. if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];then
  215. opensslVersion="3.0.2"
  216. cd /www
  217. openssl_src_file=/www/openssl.tar.gz
  218. wget -O $openssl_src_file ${download_Url}/install/pyenv/libressl-${opensslVersion}.tar.gz
  219. tmp_size=$(du -b $openssl_src_file|awk '{print $1}')
  220. if [ $tmp_size -lt 703460 ];then
  221. rm -f $openssl_src_file
  222. Red_Error "ERROR: Download libressl-$opensslVersion source code fielded."
  223. fi
  224. tar -zxf $openssl_src_file
  225. rm -f $openssl_src_file
  226. cd libressl-${opensslVersion}
  227. ./config –prefix=/usr/local/lib
  228. make -j${cpuCore}
  229. make install
  230. ldconfig
  231. ldconfig -v
  232. cd ..
  233. rm -rf libressl-${opensslVersion}
  234. is_export_openssl=1
  235. cd ~
  236. fi
  237. }
  238. Centos6_Openssl(){
  239. if [ "$os_type" != 'el' ];then
  240. return
  241. fi
  242. if [ "$os_version" != '6' ];then
  243. return
  244. fi
  245. echo 'Centos6 install openssl-1.0.2...'
  246. openssl_rpm_file="/www/openssl.rpm"
  247. wget -O $openssl_rpm_file $download_Url/rpm/centos6/${is64bit}/bt-openssl102.rpm -T 10
  248. tmp_size=$(du -b $openssl_rpm_file|awk '{print $1}')
  249. if [ $tmp_size -lt 102400 ];then
  250. rm -f $openssl_rpm_file
  251. Red_Error "ERROR: Download python env fielded."
  252. fi
  253. rpm -ivh $openssl_rpm_file
  254. rm -f $openssl_rpm_file
  255. is_export_openssl=1
  256. }
  257. Get_Versions(){
  258. redhat_version_file="/etc/redhat-release"
  259. deb_version_file="/etc/issue"
  260. if [ -f $redhat_version_file ];then
  261. os_type='el'
  262. is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
  263. if [ "$is_aliyunos" != "" ];then
  264. return
  265. fi
  266. os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
  267. if [ "${os_version}" = "5" ];then
  268. os_version=""
  269. fi
  270. else
  271. os_type='ubuntu'
  272. os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
  273. if [ "${os_version}" = "" ];then
  274. os_type='debian'
  275. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
  276. if [ "${os_version}" = "" ];then
  277. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
  278. fi
  279. if [ "${os_version}" = "8" ];then
  280. os_version=""
  281. fi
  282. if [ "${is64bit}" = '32' ];then
  283. os_version=""
  284. fi
  285. fi
  286. fi
  287. }
  288. update_panel(){
  289. wget -T 5 -O /tmp/panel.zip $Btapi_Url/install/update/LinuxPanel-${version}.zip
  290. dsize=$(du -b /tmp/panel.zip|awk '{print $1}')
  291. if [ $dsize -lt 10240 ];then
  292. echo "获取更新包失败,请稍后更新或联系宝塔运维"
  293. exit;
  294. fi
  295. unzip -o /tmp/panel.zip -d $setup_path/server/ > /dev/null
  296. rm -f /tmp/panel.zip
  297. cd $setup_path/server/panel/
  298. check_bt=`cat /etc/init.d/bt|grep BT-Task`
  299. if [ "${check_bt}" = "" ];then
  300. rm -f /etc/init.d/bt
  301. wget -O /etc/init.d/bt $download_Url/install/src/bt7.init -T 20
  302. chmod +x /etc/init.d/bt
  303. fi
  304. rm -f /www/server/panel/*.pyc
  305. rm -f /www/server/panel/class/*.pyc
  306. if [ ! -f $setup_path/server/panel/config/config.json ];then
  307. wget -T 5 -O $setup_path/server/panel/config/config.json $download_Url/install/pyenv/config/config.json
  308. wget -T 5 -O $setup_path/server/panel/config/dns_api.json $download_Url/install/pyenv/config/dns_api.json
  309. fi
  310. chattr -i /etc/init.d/bt
  311. chmod +x /etc/init.d/bt
  312. # if [ $up_plugin = 1 ];then
  313. # $pyenv_bin/python /www/server/panel/tools.py update_to6
  314. # fi
  315. }
  316. update_start(){
  317. echo "====================================="
  318. echo "开始升级宝塔Linux面板,请稍候..."
  319. echo "====================================="
  320. }
  321. update_end(){
  322. echo "====================================="
  323. rm -f /dev/shm/bt_sql_tips.pl
  324. kill $(ps aux|grep -E "task.py|main.py"|grep -v grep|awk '{print $2}') &>/dev/null
  325. bash /www/server/panel/init.sh start
  326. echo 'True' > /www/server/panel/data/restart.pl
  327. pkill -9 gunicorn &>/dev/null &
  328. echo "已成功升级到[$version]${Ver}";
  329. }
  330. rm -rf /www/server/phpmyadmin/pma
  331. update_start
  332. check_panel
  333. select_node
  334. install_python
  335. get_version
  336. update_panel
  337. update_end