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.

466 lines
14 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years ago
2 days ago
2 years 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_ssl=$($python_bin -c "import ssl" 2>&1|grep cannot)
  81. $pyenv_path/pyenv/bin/python3.7 -V
  82. if [ $? -eq 0 ] && [ -z "${is_ssl}" ];then
  83. chmod -R 700 $pyenv_path/pyenv/bin
  84. is_package=$($python_bin -m psutil 2>&1|grep package)
  85. if [ "$is_package" = "" ];then
  86. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.16.txt -T 15
  87. $pyenv_path/pyenv/bin/pip install -U pip
  88. $pyenv_path/pyenv/bin/pip install -U setuptools==65.5.0
  89. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  90. fi
  91. source $pyenv_path/pyenv/bin/activate
  92. chmod -R 700 $pyenv_path/pyenv/bin
  93. return
  94. else
  95. rm -rf $pyenv_path/pyenv
  96. fi
  97. fi
  98. is_loongarch64=$(uname -a|grep loongarch64)
  99. if [ "$is_loongarch64" != "" ] && [ -f "/usr/bin/yum" ];then
  100. yumPacks="python3-devel python3-pip python3-psutil python3-gevent python3-pyOpenSSL python3-paramiko python3-flask python3-rsa python3-requests python3-six python3-websocket-client"
  101. yum install -y ${yumPacks}
  102. for yumPack in ${yumPacks}
  103. do
  104. rpmPack=$(rpm -q ${yumPack})
  105. packCheck=$(echo ${rpmPack}|grep not)
  106. if [ "${packCheck}" ]; then
  107. yum install ${yumPack} -y
  108. fi
  109. done
  110. pip3 install -U pip
  111. pip3 install Pillow psutil pyinotify pycryptodome upyun oss2 pymysql qrcode qiniu redis pymongo Cython configparser cos-python-sdk-v5 supervisor gevent-websocket pyopenssl
  112. pip3 install flask==1.1.4
  113. pip3 install Pillow -U
  114. pyenv_bin=/www/server/panel/pyenv/bin
  115. mkdir -p $pyenv_bin
  116. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip
  117. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3
  118. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3.7
  119. if [ -f "/usr/bin/python3.7" ];then
  120. ln -sf /usr/bin/python3.7 $pyenv_bin/python
  121. ln -sf /usr/bin/python3.7 $pyenv_bin/python3
  122. ln -sf /usr/bin/python3.7 $pyenv_bin/python3.7
  123. elif [ -f "/usr/bin/python3.6" ]; then
  124. ln -sf /usr/bin/python3.6 $pyenv_bin/python
  125. ln -sf /usr/bin/python3.6 $pyenv_bin/python3
  126. ln -sf /usr/bin/python3.6 $pyenv_bin/python3.7
  127. fi
  128. echo > $pyenv_bin/activate
  129. return
  130. fi
  131. install_pack
  132. py_version="3.7.16"
  133. mkdir -p $pyenv_path
  134. echo "True" > /www/disk.pl
  135. if [ ! -w /www/disk.pl ];then
  136. Red_Error "ERROR: Install python env fielded." "ERROR: /www目录无法写入,请检查目录/用户/磁盘权限!"
  137. fi
  138. os_type='el'
  139. os_version='7'
  140. is_export_openssl=0
  141. Get_Versions
  142. Centos6_Openssl
  143. Other_Openssl
  144. echo "OS: $os_type - $os_version"
  145. is_aarch64=$(uname -a|grep aarch64)
  146. if [ "$is_aarch64" != "" ];then
  147. is64bit="aarch64"
  148. fi
  149. up_plugin=1
  150. if [ -f "/www/server/panel/pymake.pl" ];then
  151. os_version=""
  152. rm -f /www/server/panel/pymake.pl
  153. fi
  154. echo "==============================================="
  155. echo "正在下载面板运行环境,请稍等..............."
  156. echo "==============================================="
  157. if [ "${os_version}" != "" ];then
  158. pyenv_file="/www/pyenv.tar.gz"
  159. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 20
  160. if [ "$?" != "0" ];then
  161. get_node_url $download_Url
  162. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 20
  163. fi
  164. tmp_size=$(du -b $pyenv_file|awk '{print $1}')
  165. if [ $tmp_size -gt 703460 ];then
  166. echo "Install python env..."
  167. tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null
  168. chmod -R 700 $pyenv_path/pyenv/bin
  169. if [ -f $pyenv_path/pyenv/bin/python ];then
  170. $pyenv_path/pyenv/bin/python3.7 -V
  171. if [ $? -eq 0 ];then
  172. rm -f $pyenv_file
  173. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  174. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  175. source $pyenv_path/pyenv/bin/activate
  176. return
  177. else
  178. rm -f $pyenv_file
  179. rm -rf $pyenv_path/pyenv
  180. fi
  181. else
  182. rm -f $pyenv_file
  183. rm -rf $pyenv_path/pyenv
  184. fi
  185. fi
  186. rm -f $pyenv_file
  187. echo "预编译环境下载失败,开始编译安装Python..."
  188. fi
  189. if [ -f /usr/local/openssl/lib/libssl.so ];then
  190. export LDFLAGS="-L/usr/local/openssl/lib"
  191. export CPPFLAGS="-I/usr/local/openssl/include"
  192. export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig"
  193. echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib" >> /etc/profile
  194. source /etc/profile
  195. fi
  196. cd /www
  197. python_src='/www/python_src.tar.xz'
  198. python_src_path="/www/Python-${py_version}"
  199. wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 15
  200. tmp_size=$(du -b $python_src|awk '{print $1}')
  201. if [ $tmp_size -lt 10703460 ];then
  202. rm -f $python_src
  203. Red_Error "ERROR: Download python source code fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
  204. fi
  205. tar xvf $python_src
  206. rm -f $python_src
  207. cd $python_src_path
  208. ./configure --prefix=$pyenv_path/pyenv
  209. make -j$cpu_cpunt
  210. make install
  211. if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
  212. rm -rf $python_src_path
  213. Red_Error "ERROR: Make python env fielded." "ERROR: 编译宝塔运行环境失败!"
  214. fi
  215. cd ~
  216. rm -rf $python_src_path
  217. wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 5
  218. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.16.txt -T 5
  219. ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
  220. ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
  221. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  222. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  223. chmod -R 700 $pyenv_path/pyenv/bin
  224. $pyenv_path/pyenv/bin/pip install -U pip
  225. $pyenv_path/pyenv/bin/pip install -U setuptools==65.5.0
  226. $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
  227. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  228. wget -O pip-packs.txt $download_Url/install/pyenv/pip-packs.txt
  229. echo "正在后台安装pip依赖请稍等.........."
  230. PIP_PACKS=$(cat pip-packs.txt)
  231. for P_PACK in ${PIP_PACKS};
  232. do
  233. btpip show ${P_PACK} > /dev/null 2>&1
  234. if [ "$?" == "1" ];then
  235. btpip install ${P_PACK}
  236. fi
  237. done
  238. rm -f pip-packs.txt
  239. source $pyenv_path/pyenv/bin/activate
  240. btpip install psutil
  241. btpip install gevent
  242. is_gevent=$($python_bin -m gevent 2>&1|grep -oE package)
  243. is_psutil=$($python_bin -m psutil 2>&1|grep -oE package)
  244. if [ "${is_gevent}" != "${is_psutil}" ];then
  245. Red_Error "ERROR: psutil/gevent install failed!"
  246. fi
  247. }
  248. sync_python_lib(){
  249. pip_list=$(pip list 2>/dev/null|grep -v Package|grep -v '\-\-\-\-\-\-'|awk '{print $1}'|xargs)
  250. $pyenv_path/pyenv/bin/pip install -U pip setuptools
  251. $pyenv_path/pyenv/bin/pip install $pip_list
  252. }
  253. Other_Openssl(){
  254. openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')
  255. if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];then
  256. opensslVersion="1.0.2r"
  257. if [ ! -f "/usr/local/openssl/lib/libssl.so" ];then
  258. cd /www
  259. openssl_src_file=/www/openssl.tar.gz
  260. wget -O $openssl_src_file ${download_Url}/src/openssl-${opensslVersion}.tar.gz
  261. tmp_size=$(du -b $openssl_src_file|awk '{print $1}')
  262. if [ $tmp_size -lt 703460 ];then
  263. rm -f $openssl_src_file
  264. Red_Error "ERROR: Download openssl-1.0.2 source code fielded."
  265. fi
  266. tar -zxf $openssl_src_file
  267. rm -f $openssl_src_file
  268. cd openssl-${opensslVersion}
  269. ./config --openssldir=/usr/local/openssl zlib-dynamic shared
  270. make -j${cpuCore}
  271. make install
  272. echo "/usr/local/openssl/lib" > /etc/ld.so.conf.d/zopenssl.conf
  273. ldconfig
  274. cd ..
  275. rm -rf openssl-${opensslVersion}
  276. is_export_openssl=1
  277. cd ~
  278. fi
  279. fi
  280. }
  281. Insatll_Libressl(){
  282. openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')
  283. if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];then
  284. opensslVersion="3.0.2"
  285. cd /www
  286. openssl_src_file=/www/openssl.tar.gz
  287. wget -O $openssl_src_file ${download_Url}/install/pyenv/libressl-${opensslVersion}.tar.gz
  288. tmp_size=$(du -b $openssl_src_file|awk '{print $1}')
  289. if [ $tmp_size -lt 703460 ];then
  290. rm -f $openssl_src_file
  291. Red_Error "ERROR: Download libressl-$opensslVersion source code fielded."
  292. fi
  293. tar -zxf $openssl_src_file
  294. rm -f $openssl_src_file
  295. cd libressl-${opensslVersion}
  296. ./config –prefix=/usr/local/lib
  297. make -j${cpuCore}
  298. make install
  299. ldconfig
  300. ldconfig -v
  301. cd ..
  302. rm -rf libressl-${opensslVersion}
  303. is_export_openssl=1
  304. cd ~
  305. fi
  306. }
  307. Centos6_Openssl(){
  308. if [ "$os_type" != 'el' ];then
  309. return
  310. fi
  311. if [ "$os_version" != '6' ];then
  312. return
  313. fi
  314. echo 'Centos6 install openssl-1.0.2...'
  315. openssl_rpm_file="/www/openssl.rpm"
  316. wget -O $openssl_rpm_file $download_Url/rpm/centos6/${is64bit}/bt-openssl102.rpm -T 10
  317. tmp_size=$(du -b $openssl_rpm_file|awk '{print $1}')
  318. if [ $tmp_size -lt 102400 ];then
  319. rm -f $openssl_rpm_file
  320. Red_Error "ERROR: Download python env fielded."
  321. fi
  322. rpm -ivh $openssl_rpm_file
  323. rm -f $openssl_rpm_file
  324. is_export_openssl=1
  325. }
  326. Get_Versions(){
  327. redhat_version_file="/etc/redhat-release"
  328. deb_version_file="/etc/issue"
  329. if [ -f $redhat_version_file ];then
  330. os_type='el'
  331. is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
  332. if [ "$is_aliyunos" != "" ];then
  333. return
  334. fi
  335. os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
  336. if [ "${os_version}" = "5" ];then
  337. os_version=""
  338. fi
  339. else
  340. os_type='ubuntu'
  341. os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
  342. if [ "${os_version}" = "" ];then
  343. os_type='debian'
  344. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
  345. if [ "${os_version}" = "" ];then
  346. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
  347. fi
  348. if [ "${os_version}" = "8" ];then
  349. os_version=""
  350. fi
  351. if [ "${is64bit}" = '32' ];then
  352. os_version=""
  353. fi
  354. fi
  355. fi
  356. }
  357. update_panel(){
  358. wget -T 5 -O /tmp/panel.zip $Btapi_Url/install/update/LinuxPanel-${version}.zip
  359. dsize=$(du -b /tmp/panel.zip|awk '{print $1}')
  360. if [ $dsize -lt 10240 ];then
  361. echo "获取更新包失败,请稍后更新或联系宝塔运维"
  362. exit;
  363. fi
  364. unzip -o /tmp/panel.zip -d $setup_path/server/ > /dev/null
  365. rm -f /tmp/panel.zip
  366. cd $setup_path/server/panel/
  367. check_bt=`cat /etc/init.d/bt|grep BT-Task`
  368. if [ "${check_bt}" = "" ];then
  369. rm -f /etc/init.d/bt
  370. wget -O /etc/init.d/bt $download_Url/install/src/bt7.init -T 20
  371. chmod +x /etc/init.d/bt
  372. fi
  373. rm -f /www/server/panel/*.pyc
  374. rm -f /www/server/panel/class/*.pyc
  375. if [ ! -f $setup_path/server/panel/config/config.json ];then
  376. wget -T 5 -O $setup_path/server/panel/config/config.json $download_Url/install/pyenv/config/config.json
  377. wget -T 5 -O $setup_path/server/panel/config/dns_api.json $download_Url/install/pyenv/config/dns_api.json
  378. fi
  379. chattr -i /etc/init.d/bt
  380. chmod +x /etc/init.d/bt
  381. # Install additional pip dependencies even if python already exists
  382. pyenv_path="/www/server/panel"
  383. if [ ! -f "/www/server/panel/pyenv/n.pl" ];then
  384. btpip install docxtpl==0.16.7
  385. $pyenv_path/pyenv/bin/pip3 install pymongo
  386. $pyenv_path/pyenv/bin/pip3 install psycopg2-binary
  387. $pyenv_path/pyenv/bin/pip3 install flask -U
  388. $pyenv_path/pyenv/bin/pip3 install flask-sock
  389. $pyenv_path/pyenv/bin/pip3 install -I gevent
  390. btpip install simple-websocket==0.10.0
  391. btpip install natsort
  392. btpip uninstall enum34 -y
  393. btpip install geoip2==4.7.0
  394. btpip install brotli
  395. btpip install PyMySQL
  396. fi
  397. btpip install -I pyOpenSSl 2>/dev/null
  398. # if [ $up_plugin = 1 ];then
  399. # $pyenv_bin/python /www/server/panel/tools.py update_to6
  400. # fi
  401. }
  402. update_start(){
  403. echo "====================================="
  404. echo "开始升级宝塔Linux面板,请稍候..."
  405. echo "====================================="
  406. }
  407. update_end(){
  408. echo "====================================="
  409. rm -f /dev/shm/bt_sql_tips.pl
  410. kill $(ps aux|grep -E "task.py|main.py"|grep -v grep|awk '{print $2}') &>/dev/null
  411. bash /www/server/panel/init.sh start
  412. echo 'True' > /www/server/panel/data/restart.pl
  413. pkill -9 gunicorn &>/dev/null &
  414. echo "已成功升级到[$version]${Ver}";
  415. }
  416. rm -rf /www/server/phpmyadmin/pma
  417. update_start
  418. check_panel
  419. select_node
  420. install_python
  421. get_version
  422. update_panel
  423. update_end