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.

371 lines
11 KiB

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