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.

909 lines
31 KiB

3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years 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. Check_Api=$(curl -Ss --connect-timeout 5 -m 2 $Btapi_Url/api/SetupCount)
  7. if [ "$Check_Api" != 'ok' ];then
  8. Red_Error "此宝塔第三方云端无法连接,因此安装过程已中止!";
  9. fi
  10. if [ $(whoami) != "root" ];then
  11. echo "请使用root权限执行宝塔安装命令!"
  12. exit 1;
  13. fi
  14. is64bit=$(getconf LONG_BIT)
  15. if [ "${is64bit}" != '64' ];then
  16. Red_Error "抱歉, 当前面板版本不支持32位系统, 请使用64位系统或安装宝塔5.9!";
  17. fi
  18. Centos6Check=$(cat /etc/redhat-release | grep ' 6.' | grep -iE 'centos|Red Hat')
  19. if [ "${Centos6Check}" ];then
  20. echo "Centos6不支持安装宝塔面板,请更换Centos7/8安装宝塔面板"
  21. exit 1
  22. fi
  23. UbuntuCheck=$(cat /etc/issue|grep Ubuntu|awk '{print $2}'|cut -f 1 -d '.')
  24. if [ "${UbuntuCheck}" ] && [ "${UbuntuCheck}" -lt "16" ];then
  25. echo "Ubuntu ${UbuntuCheck}不支持安装宝塔面板,建议更换Ubuntu18/20安装宝塔面板"
  26. exit 1
  27. fi
  28. cd ~
  29. setup_path="/www"
  30. python_bin=$setup_path/server/panel/pyenv/bin/python
  31. cpu_cpunt=$(cat /proc/cpuinfo|grep processor|wc -l)
  32. if [ "$1" ];then
  33. IDC_CODE=$1
  34. fi
  35. GetSysInfo(){
  36. if [ -s "/etc/redhat-release" ];then
  37. SYS_VERSION=$(cat /etc/redhat-release)
  38. elif [ -s "/etc/issue" ]; then
  39. SYS_VERSION=$(cat /etc/issue)
  40. fi
  41. SYS_INFO=$(uname -a)
  42. SYS_BIT=$(getconf LONG_BIT)
  43. MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
  44. CPU_INFO=$(getconf _NPROCESSORS_ONLN)
  45. echo -e ${SYS_VERSION}
  46. echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
  47. echo -e ${SYS_INFO}
  48. if [ -z "${os_version}" ];then
  49. echo -e "============================================"
  50. echo -e "检测到为非常用系统安装,建议更换至Centos-7或Debian-10+或Ubuntu-20+系统安装宝塔面板"
  51. echo -e "详情请查看系统兼容表:https://docs.qq.com/sheet/DUm54VUtyTVNlc21H?tab=BB08J2"
  52. echo -e "特殊情况可通过以下联系方式寻求安装协助情况"
  53. fi
  54. is64bit=$(getconf LONG_BIT)
  55. if [ "${is64bit}" == '32' ];then
  56. echo -e "宝塔面板不支持32位系统进行安装,请使用64位系统/服务器架构进行安装宝塔"
  57. exit 1
  58. fi
  59. S390X_CHECK=$(uname -a|grep s390x)
  60. if [ "${S390X_CHECK}" ];then
  61. echo -e "宝塔面板不支持s390x架构进行安装,请使用64位系统/服务器架构进行安装宝塔"
  62. exit 1
  63. fi
  64. echo -e "============================================"
  65. echo -e "请截图以上报错信息发帖至论坛www.bt.cn/bbs求助"
  66. }
  67. Red_Error(){
  68. echo '=================================================';
  69. printf '\033[1;31;40m%b\033[0m\n' "$@";
  70. GetSysInfo
  71. exit 1;
  72. }
  73. Lock_Clear(){
  74. if [ -f "/etc/bt_crack.pl" ];then
  75. chattr -R -ia /www
  76. chattr -ia /etc/init.d/bt
  77. \cp -rpa /www/backup/panel/vhost/* /www/server/panel/vhost/
  78. mv /www/server/panel/BTPanel/__init__.bak /www/server/panel/BTPanel/__init__.py
  79. rm -f /etc/bt_crack.pl
  80. fi
  81. }
  82. Install_Check(){
  83. if [ "${INSTALL_FORCE}" ];then
  84. return
  85. fi
  86. echo -e "----------------------------------------------------"
  87. echo -e "检查已有其他Web/mysql环境,安装宝塔可能影响现有站点及数据"
  88. echo -e "Web/mysql service is alreday installed,Can't install panel"
  89. echo -e "----------------------------------------------------"
  90. echo -e "已知风险/Enter yes to force installation"
  91. read -p "输入yes强制安装: " yes;
  92. if [ "$yes" != "yes" ];then
  93. echo -e "------------"
  94. echo "取消安装"
  95. exit;
  96. fi
  97. INSTALL_FORCE="true"
  98. }
  99. System_Check(){
  100. MYSQLD_CHECK=$(ps -ef |grep mysqld|grep -v grep|grep -v /www/server/mysql)
  101. PHP_CHECK=$(ps -ef|grep php-fpm|grep master|grep -v /www/server/php)
  102. NGINX_CHECK=$(ps -ef|grep nginx|grep master|grep -v /www/server/nginx)
  103. HTTPD_CHECK=$(ps -ef |grep -E 'httpd|apache'|grep -v /www/server/apache|grep -v grep)
  104. if [ "${PHP_CHECK}" ] || [ "${MYSQLD_CHECK}" ] || [ "${NGINX_CHECK}" ] || [ "${HTTPD_CHECK}" ];then
  105. Install_Check
  106. fi
  107. }
  108. Get_Pack_Manager(){
  109. if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
  110. PM="yum"
  111. elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
  112. PM="apt-get"
  113. fi
  114. }
  115. Auto_Swap()
  116. {
  117. swap=$(free |grep Swap|awk '{print $2}')
  118. if [ "${swap}" -gt 1 ];then
  119. echo "Swap total sizse: $swap";
  120. return;
  121. fi
  122. if [ ! -d /www ];then
  123. mkdir /www
  124. fi
  125. swapFile="/www/swap"
  126. dd if=/dev/zero of=$swapFile bs=1M count=1025
  127. mkswap -f $swapFile
  128. swapon $swapFile
  129. echo "$swapFile swap swap defaults 0 0" >> /etc/fstab
  130. swap=`free |grep Swap|awk '{print $2}'`
  131. if [ $swap -gt 1 ];then
  132. echo "Swap total sizse: $swap";
  133. return;
  134. fi
  135. sed -i "/\/www\/swap/d" /etc/fstab
  136. rm -f $swapFile
  137. }
  138. Service_Add(){
  139. if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
  140. chkconfig --add bt
  141. chkconfig --level 2345 bt on
  142. Centos9Check=$(cat /etc/redhat-release |grep ' 9')
  143. if [ "${Centos9Check}" ];then
  144. wget -O /usr/lib/systemd/system/btpanel.service ${download_Url}/init/systemd/btpanel.service
  145. systemctl enable btpanel
  146. fi
  147. elif [ "${PM}" == "apt-get" ]; then
  148. update-rc.d bt defaults
  149. fi
  150. }
  151. Set_Centos_Repo(){
  152. HUAWEI_CHECK=$(cat /etc/motd |grep "Huawei Cloud")
  153. if [ "${HUAWEI_CHECK}" ] && [ "${is64bit}" == "64" ];then
  154. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  155. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  156. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  157. rm -f /etc/yum.repos.d/epel.repo
  158. rm -f /etc/yum.repos.d/epel-*
  159. fi
  160. ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
  161. if [ "${ALIYUN_CHECK}" ] && [ "${is64bit}" == "64" ] && [ ! -f "/etc/yum.repos.d/Centos-vault-8.5.2111.repo" ];then
  162. rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
  163. wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
  164. wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
  165. sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
  166. sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo
  167. fi
  168. MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Linux-AppStream.repo |grep "[^#]mirror.centos.org")
  169. if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
  170. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  171. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  172. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  173. fi
  174. }
  175. get_node_url(){
  176. if [ ! -f /bin/curl ];then
  177. if [ "${PM}" = "yum" ]; then
  178. yum install curl -y
  179. elif [ "${PM}" = "apt-get" ]; then
  180. apt-get install curl -y
  181. fi
  182. fi
  183. if [ -f "/www/node.pl" ];then
  184. download_Url=$(cat /www/node.pl)
  185. echo "Download node: $download_Url";
  186. echo '---------------------------------------------';
  187. return
  188. fi
  189. echo '---------------------------------------------';
  190. echo "Selected download node...";
  191. nodes=(http://dg2.bt.cn http://dg1.bt.cn http://download.bt.cn http://125.90.93.52:5880 http://36.133.1.8:5880 http://123.129.198.197 http://103.179.243.14:5880 http://128.1.164.196);
  192. if [ "$1" ];then
  193. nodes=($(echo ${nodes[*]}|sed "s#${1}##"))
  194. fi
  195. tmp_file1=/dev/shm/net_test1.pl
  196. tmp_file2=/dev/shm/net_test2.pl
  197. [ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
  198. [ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
  199. touch $tmp_file1
  200. touch $tmp_file2
  201. for node in ${nodes[@]};
  202. do
  203. NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
  204. RES=$(echo ${NODE_CHECK}|awk '{print $1}')
  205. NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $2}')
  206. TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $3 * 1000 - 500 }'|cut -d '.' -f 1)
  207. if [ "${NODE_STATUS}" == "200" ];then
  208. if [ $TIME_TOTAL -lt 100 ];then
  209. if [ $RES -ge 1500 ];then
  210. echo "$RES $node" >> $tmp_file1
  211. fi
  212. else
  213. if [ $RES -ge 1500 ];then
  214. echo "$TIME_TOTAL $node" >> $tmp_file2
  215. fi
  216. fi
  217. i=$(($i+1))
  218. if [ $TIME_TOTAL -lt 100 ];then
  219. if [ $RES -ge 3000 ];then
  220. break;
  221. fi
  222. fi
  223. fi
  224. done
  225. NODE_URL=$(cat $tmp_file1|sort -r -g -t " " -k 1|head -n 1|awk '{print $2}')
  226. if [ -z "$NODE_URL" ];then
  227. NODE_URL=$(cat $tmp_file2|sort -g -t " " -k 1|head -n 1|awk '{print $2}')
  228. if [ -z "$NODE_URL" ];then
  229. NODE_URL='http://download.bt.cn';
  230. fi
  231. fi
  232. rm -f $tmp_file1
  233. rm -f $tmp_file2
  234. download_Url=$NODE_URL
  235. echo "Download node: $download_Url";
  236. echo '---------------------------------------------';
  237. }
  238. Remove_Package(){
  239. local PackageNmae=$1
  240. if [ "${PM}" == "yum" ];then
  241. isPackage=$(rpm -q ${PackageNmae}|grep "not installed")
  242. if [ -z "${isPackage}" ];then
  243. yum remove ${PackageNmae} -y
  244. fi
  245. elif [ "${PM}" == "apt-get" ];then
  246. isPackage=$(dpkg -l|grep ${PackageNmae})
  247. if [ "${PackageNmae}" ];then
  248. apt-get remove ${PackageNmae} -y
  249. fi
  250. fi
  251. }
  252. Install_RPM_Pack(){
  253. yumPath=/etc/yum.conf
  254. Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
  255. if [ "${Centos8Check}" ];then
  256. Set_Centos_Repo
  257. fi
  258. isExc=$(cat $yumPath|grep httpd)
  259. if [ "$isExc" = "" ];then
  260. echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >> $yumPath
  261. fi
  262. #SYS_TYPE=$(uname -a|grep x86_64)
  263. #yumBaseUrl=$(cat /etc/yum.repos.d/CentOS-Base.repo|grep baseurl=http|cut -d '=' -f 2|cut -d '$' -f 1|head -n 1)
  264. #[ "${yumBaseUrl}" ] && checkYumRepo=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${yumBaseUrl})
  265. #if [ "${checkYumRepo}" != "200" ] && [ "${SYS_TYPE}" ];then
  266. # curl -Ss --connect-timeout 3 -m 60 http://download.bt.cn/install/yumRepo_select.sh|bash
  267. #fi
  268. #尝试同步时间(从bt.cn)
  269. echo 'Synchronizing system time...'
  270. getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time)
  271. if [ "${getBtTime}" ];then
  272. date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"
  273. fi
  274. if [ -z "${Centos8Check}" ]; then
  275. yum install ntp -y
  276. rm -rf /etc/localtime
  277. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  278. #尝试同步国际时间(从ntp服务器)
  279. ntpdate 0.asia.pool.ntp.org
  280. setenforce 0
  281. fi
  282. startTime=`date +%s`
  283. sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  284. #yum remove -y python-requests python3-requests python-greenlet python3-greenlet
  285. yumPacks="libcurl-devel wget tar gcc make zip unzip openssl openssl-devel gcc libxml2 libxml2-devel libxslt* zlib zlib-devel libjpeg-devel libpng-devel libwebp libwebp-devel freetype freetype-devel lsof pcre pcre-devel vixie-cron crontabs icu libicu-devel c-ares libffi-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel qrencode"
  286. yum install -y ${yumPacks}
  287. for yumPack in ${yumPacks}
  288. do
  289. rpmPack=$(rpm -q ${yumPack})
  290. packCheck=$(echo ${rpmPack}|grep not)
  291. if [ "${packCheck}" ]; then
  292. yum install ${yumPack} -y
  293. fi
  294. done
  295. if [ -f "/usr/bin/dnf" ]; then
  296. dnf install -y redhat-rpm-config
  297. fi
  298. ALI_OS=$(cat /etc/redhat-release |grep "Alibaba Cloud Linux release 3")
  299. if [ -z "${ALI_OS}" ];then
  300. yum install epel-release -y
  301. fi
  302. }
  303. Install_Deb_Pack(){
  304. ln -sf bash /bin/sh
  305. UBUNTU_22=$(cat /etc/issue|grep "Ubuntu 22")
  306. if [ "${UBUNTU_22}" ];then
  307. apt-get remove needrestart -y
  308. fi
  309. ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
  310. if [ "${ALIYUN_CHECK}" ] && [ "${UBUNTU_22}" ];then
  311. apt-get remove libicu70 -y
  312. fi
  313. apt-get update -y
  314. apt-get install bash -y
  315. if [ -f "/usr/bin/bash" ];then
  316. ln -sf /usr/bin/bash /bin/sh
  317. fi
  318. apt-get install ruby -y
  319. apt-get install lsb-release -y
  320. #apt-get install ntp ntpdate -y
  321. #/etc/init.d/ntp stop
  322. #update-rc.d ntp remove
  323. #cat >>~/.profile<<EOF
  324. #TZ='Asia/Shanghai'; export TZ
  325. #EOF
  326. #rm -rf /etc/localtime
  327. #cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  328. #echo 'Synchronizing system time...'
  329. #ntpdate 0.asia.pool.ntp.org
  330. #apt-get upgrade -y
  331. LIBCURL_VER=$(dpkg -l|grep libcurl4|awk '{print $3}')
  332. if [ "${LIBCURL_VER}" == "7.68.0-1ubuntu2.8" ];then
  333. apt-get remove libcurl4 -y
  334. apt-get install curl -y
  335. fi
  336. debPacks="wget curl libcurl4-openssl-dev gcc make zip unzip tar openssl libssl-dev gcc libxml2 libxml2-dev zlib1g zlib1g-dev libjpeg-dev libpng-dev lsof libpcre3 libpcre3-dev cron net-tools swig build-essential libffi-dev libbz2-dev libncurses-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libdb++-dev libpcap-dev xz-utils git qrencode";
  337. apt-get install -y $debPacks --force-yes
  338. for debPack in ${debPacks}
  339. do
  340. packCheck=$(dpkg -l|grep ${debPack})
  341. if [ "$?" -ne "0" ] ;then
  342. apt-get install -y $debPack
  343. fi
  344. done
  345. if [ ! -d '/etc/letsencrypt' ];then
  346. mkdir -p /etc/letsencryp
  347. mkdir -p /var/spool/cron
  348. if [ ! -f '/var/spool/cron/crontabs/root' ];then
  349. echo '' > /var/spool/cron/crontabs/root
  350. chmod 600 /var/spool/cron/crontabs/root
  351. fi
  352. fi
  353. }
  354. Get_Versions(){
  355. redhat_version_file="/etc/redhat-release"
  356. deb_version_file="/etc/issue"
  357. if [ -f $redhat_version_file ];then
  358. os_type='el'
  359. is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
  360. if [ "$is_aliyunos" != "" ];then
  361. return
  362. fi
  363. os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
  364. if [ "${os_version}" = "5" ];then
  365. os_version=""
  366. fi
  367. if [ -z "${os_version}" ];then
  368. os_version=$(cat /etc/redhat-release |grep Stream|grep -oE 8)
  369. fi
  370. else
  371. os_type='ubuntu'
  372. os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
  373. if [ "${os_version}" = "" ];then
  374. os_type='debian'
  375. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
  376. if [ "${os_version}" = "" ];then
  377. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
  378. fi
  379. if [ "${os_version}" = "8" ];then
  380. os_version=""
  381. fi
  382. if [ "${is64bit}" = '32' ];then
  383. os_version=""
  384. fi
  385. else
  386. if [ "$os_version" = "14" ];then
  387. os_version=""
  388. fi
  389. if [ "$os_version" = "12" ];then
  390. os_version=""
  391. fi
  392. if [ "$os_version" = "19" ];then
  393. os_version=""
  394. fi
  395. if [ "$os_version" = "21" ];then
  396. os_version=""
  397. fi
  398. if [ "$os_version" = "20" ];then
  399. os_version2004=$(cat /etc/issue|grep 20.04)
  400. if [ -z "${os_version2004}" ];then
  401. os_version=""
  402. fi
  403. fi
  404. fi
  405. fi
  406. }
  407. Install_Python_Lib(){
  408. curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
  409. pyenv_path="/www/server/panel"
  410. if [ -f $pyenv_path/pyenv/bin/python ];then
  411. is_ssl=$($python_bin -c "import ssl" 2>&1|grep cannot)
  412. $pyenv_path/pyenv/bin/python3.7 -V
  413. if [ $? -eq 0 ] && [ -z "${is_ssl}" ];then
  414. chmod -R 700 $pyenv_path/pyenv/bin
  415. is_package=$($python_bin -m psutil 2>&1|grep package)
  416. if [ "$is_package" = "" ];then
  417. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 5
  418. $pyenv_path/pyenv/bin/pip install -U pip
  419. $pyenv_path/pyenv/bin/pip install -U setuptools==65.5.0
  420. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  421. fi
  422. source $pyenv_path/pyenv/bin/activate
  423. chmod -R 700 $pyenv_path/pyenv/bin
  424. return
  425. else
  426. rm -rf $pyenv_path/pyenv
  427. fi
  428. fi
  429. is_loongarch64=$(uname -a|grep loongarch64)
  430. if [ "$is_loongarch64" != "" ] && [ -f "/usr/bin/yum" ];then
  431. yumPacks="python3-devel python3-pip python3-psutil python3-gevent python3-pyOpenSSL python3-paramiko python3-flask python3-rsa python3-requests python3-six python3-websocket-client"
  432. yum install -y ${yumPacks}
  433. for yumPack in ${yumPacks}
  434. do
  435. rpmPack=$(rpm -q ${yumPack})
  436. packCheck=$(echo ${rpmPack}|grep not)
  437. if [ "${packCheck}" ]; then
  438. yum install ${yumPack} -y
  439. fi
  440. done
  441. pip3 install -U pip
  442. pip3 install Pillow psutil pyinotify pycryptodome upyun oss2 pymysql qrcode qiniu redis pymongo Cython configparser cos-python-sdk-v5 supervisor gevent-websocket pyopenssl
  443. pip3 install flask==1.1.4
  444. pip3 install Pillow -U
  445. pyenv_bin=/www/server/panel/pyenv/bin
  446. mkdir -p $pyenv_bin
  447. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip
  448. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3
  449. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3.7
  450. if [ -f "/usr/bin/python3.7" ];then
  451. ln -sf /usr/bin/python3.7 $pyenv_bin/python
  452. ln -sf /usr/bin/python3.7 $pyenv_bin/python3
  453. ln -sf /usr/bin/python3.7 $pyenv_bin/python3.7
  454. elif [ -f "/usr/bin/python3.6" ]; then
  455. ln -sf /usr/bin/python3.6 $pyenv_bin/python
  456. ln -sf /usr/bin/python3.6 $pyenv_bin/python3
  457. ln -sf /usr/bin/python3.6 $pyenv_bin/python3.7
  458. fi
  459. echo > $pyenv_bin/activate
  460. return
  461. fi
  462. py_version="3.7.8"
  463. mkdir -p $pyenv_path
  464. echo "True" > /www/disk.pl
  465. if [ ! -w /www/disk.pl ];then
  466. Red_Error "ERROR: Install python env fielded." "ERROR: /www目录无法写入,请检查目录/用户/磁盘权限!"
  467. fi
  468. os_type='el'
  469. os_version='7'
  470. is_export_openssl=0
  471. Get_Versions
  472. echo "OS: $os_type - $os_version"
  473. is_aarch64=$(uname -a|grep aarch64)
  474. if [ "$is_aarch64" != "" ];then
  475. is64bit="aarch64"
  476. fi
  477. if [ -f "/www/server/panel/pymake.pl" ];then
  478. os_version=""
  479. rm -f /www/server/panel/pymake.pl
  480. fi
  481. if [ "${os_version}" != "" ];then
  482. pyenv_file="/www/pyenv.tar.gz"
  483. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10
  484. if [ "$?" != "0" ];then
  485. get_node_url $download_Url
  486. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10
  487. fi
  488. tmp_size=$(du -b $pyenv_file|awk '{print $1}')
  489. if [ $tmp_size -lt 703460 ];then
  490. rm -f $pyenv_file
  491. echo "ERROR: Download python env fielded."
  492. else
  493. echo "Install python env..."
  494. tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null
  495. chmod -R 700 $pyenv_path/pyenv/bin
  496. if [ ! -f $pyenv_path/pyenv/bin/python ];then
  497. rm -f $pyenv_file
  498. Red_Error "ERROR: Install python env fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
  499. fi
  500. $pyenv_path/pyenv/bin/python3.7 -V
  501. if [ $? -eq 0 ];then
  502. rm -f $pyenv_file
  503. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  504. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  505. source $pyenv_path/pyenv/bin/activate
  506. return
  507. else
  508. rm -f $pyenv_file
  509. rm -rf $pyenv_path/pyenv
  510. fi
  511. fi
  512. fi
  513. cd /www
  514. python_src='/www/python_src.tar.xz'
  515. python_src_path="/www/Python-${py_version}"
  516. wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 5
  517. tmp_size=$(du -b $python_src|awk '{print $1}')
  518. if [ $tmp_size -lt 10703460 ];then
  519. rm -f $python_src
  520. Red_Error "ERROR: Download python source code fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
  521. fi
  522. tar xvf $python_src
  523. rm -f $python_src
  524. cd $python_src_path
  525. ./configure --prefix=$pyenv_path/pyenv
  526. make -j$cpu_cpunt
  527. make install
  528. if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
  529. rm -rf $python_src_path
  530. Red_Error "ERROR: Make python env fielded." "ERROR: 编译宝塔运行环境失败!"
  531. fi
  532. cd ~
  533. rm -rf $python_src_path
  534. wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 5
  535. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.8.txt -T 5
  536. ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
  537. ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
  538. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  539. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  540. chmod -R 700 $pyenv_path/pyenv/bin
  541. $pyenv_path/pyenv/bin/pip install -U pip
  542. $pyenv_path/pyenv/bin/pip install -U setuptools==65.5.0
  543. $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
  544. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  545. source $pyenv_path/pyenv/bin/activate
  546. is_gevent=$($python_bin -m gevent 2>&1|grep -oE package)
  547. is_psutil=$($python_bin -m psutil 2>&1|grep -oE package)
  548. if [ "${is_gevent}" != "${is_psutil}" ];then
  549. Red_Error "ERROR: psutil/gevent install failed!"
  550. fi
  551. }
  552. Install_Bt(){
  553. panelPort="8888"
  554. if [ -f ${setup_path}/server/panel/data/port.pl ];then
  555. panelPort=$(cat ${setup_path}/server/panel/data/port.pl)
  556. else
  557. RE_NUM=$(expr $RANDOM % 3)
  558. if [ "${RE_NUM}" == "1" ];then
  559. panelPort=$(expr $RANDOM % 55535 + 10000)
  560. fi
  561. fi
  562. mkdir -p ${setup_path}/server/panel/logs
  563. mkdir -p ${setup_path}/server/panel/vhost/apache
  564. mkdir -p ${setup_path}/server/panel/vhost/nginx
  565. mkdir -p ${setup_path}/server/panel/vhost/rewrite
  566. mkdir -p ${setup_path}/server/panel/install
  567. mkdir -p /www/server
  568. mkdir -p /www/wwwroot
  569. mkdir -p /www/wwwlogs
  570. mkdir -p /www/backup/database
  571. mkdir -p /www/backup/site
  572. if [ ! -d "/etc/init.d" ];then
  573. mkdir -p /etc/init.d
  574. fi
  575. if [ -f "/etc/init.d/bt" ]; then
  576. /etc/init.d/bt stop
  577. sleep 1
  578. fi
  579. wget -O /etc/init.d/bt ${download_Url}/install/src/bt6.init -T 10
  580. wget -O /www/server/panel/install/public.sh ${Btapi_Url}/install/public.sh -T 10
  581. wget -O panel.zip ${Btapi_Url}/install/src/panel6.zip -T 10
  582. if [ -f "${setup_path}/server/panel/data/default.db" ];then
  583. if [ -d "/${setup_path}/server/panel/old_data" ];then
  584. rm -rf ${setup_path}/server/panel/old_data
  585. fi
  586. mkdir -p ${setup_path}/server/panel/old_data
  587. d_format=$(date +"%Y%m%d_%H%M%S")
  588. \cp -arf ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/data/default_backup_${d_format}.db
  589. mv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.db
  590. mv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.db
  591. mv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.pl
  592. mv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.pl
  593. fi
  594. if [ ! -f "/usr/bin/unzip" ]; then
  595. if [ "${PM}" = "yum" ]; then
  596. yum install unzip -y
  597. elif [ "${PM}" = "apt-get" ]; then
  598. apt-get update
  599. apt-get install unzip -y
  600. fi
  601. fi
  602. unzip -o panel.zip -d ${setup_path}/server/ > /dev/null
  603. if [ -d "${setup_path}/server/panel/old_data" ];then
  604. mv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.db
  605. mv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.db
  606. mv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.pl
  607. mv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.pl
  608. if [ -d "/${setup_path}/server/panel/old_data" ];then
  609. rm -rf ${setup_path}/server/panel/old_data
  610. fi
  611. fi
  612. if [ ! -f ${setup_path}/server/panel/tools.py ] || [ ! -f ${setup_path}/server/panel/BT-Panel ];then
  613. ls -lh panel.zip
  614. Red_Error "ERROR: Failed to download, please try install again!" "ERROR: 下载宝塔失败,请尝试重新安装!"
  615. fi
  616. rm -f panel.zip
  617. rm -f ${setup_path}/server/panel/class/*.pyc
  618. rm -f ${setup_path}/server/panel/*.pyc
  619. chmod +x /etc/init.d/bt
  620. chmod -R 600 ${setup_path}/server/panel
  621. chmod -R +x ${setup_path}/server/panel/script
  622. ln -sf /etc/init.d/bt /usr/bin/bt
  623. echo "${panelPort}" > ${setup_path}/server/panel/data/port.pl
  624. wget -O /etc/init.d/bt ${download_Url}/install/src/bt7.init -T 10
  625. wget -O /www/server/panel/init.sh ${download_Url}/install/src/bt7.init -T 10
  626. wget -O /www/server/panel/data/softList.conf ${download_Url}/install/conf/softList.conf
  627. rm -f /www/server/panel/class/*.so
  628. if [ ! -f /www/server/panel/data/not_workorder.pl ]; then
  629. echo "True" > /www/server/panel/data/not_workorder.pl
  630. fi
  631. if [ ! -f /www/server/panel/data/userInfo.json ]; then
  632. 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
  633. fi
  634. }
  635. Set_Bt_Panel(){
  636. Run_User="www"
  637. wwwUser=$(cat /etc/passwd|cut -d ":" -f 1|grep ^www$)
  638. if [ "${wwwUser}" != "www" ];then
  639. groupadd ${Run_User}
  640. useradd -s /sbin/nologin -g ${Run_User} ${Run_User}
  641. fi
  642. password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
  643. sleep 1
  644. admin_auth="/www/server/panel/data/admin_path.pl"
  645. if [ ! -f ${admin_auth} ];then
  646. auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
  647. echo "/${auth_path}" > ${admin_auth}
  648. fi
  649. chmod -R 700 $pyenv_path/pyenv/bin
  650. /www/server/panel/pyenv/bin/pip3 install pymongo
  651. /www/server/panel/pyenv/bin/pip3 install psycopg2-binary
  652. /www/server/panel/pyenv/bin/pip3 install flask -U
  653. /www/server/panel/pyenv/bin/pip3 install flask-sock
  654. auth_path=$(cat ${admin_auth})
  655. cd ${setup_path}/server/panel/
  656. /etc/init.d/bt start
  657. $python_bin -m py_compile tools.py
  658. $python_bin tools.py username
  659. username=$($python_bin tools.py panel ${password})
  660. cd ~
  661. echo "${password}" > ${setup_path}/server/panel/default.pl
  662. chmod 600 ${setup_path}/server/panel/default.pl
  663. sleep 3
  664. /etc/init.d/bt restart
  665. sleep 3
  666. isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}')
  667. LOCAL_CURL=$(curl 127.0.0.1:8888/login 2>&1 |grep -i html)
  668. if [ -z "${isStart}" ] && [ -z "${LOCAL_CURL}" ];then
  669. /etc/init.d/bt 22
  670. cd /www/server/panel/pyenv/bin
  671. touch t.pl
  672. ls -al python3.7 python
  673. lsattr python3.7 python
  674. Red_Error "ERROR: The BT-Panel service startup failed." "ERROR: 宝塔启动失败"
  675. fi
  676. }
  677. Set_Firewall(){
  678. sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')
  679. if [ "${PM}" = "apt-get" ]; then
  680. apt-get install -y ufw
  681. if [ -f "/usr/sbin/ufw" ];then
  682. ufw allow 20/tcp
  683. ufw allow 21/tcp
  684. ufw allow 22/tcp
  685. ufw allow 80/tcp
  686. ufw allow 443/tcp
  687. ufw allow 888/tcp
  688. ufw allow ${panelPort}/tcp
  689. ufw allow ${sshPort}/tcp
  690. ufw allow 39000:40000/tcp
  691. ufw_status=`ufw status`
  692. echo y|ufw enable
  693. ufw default deny
  694. ufw reload
  695. fi
  696. else
  697. if [ -f "/etc/init.d/iptables" ];then
  698. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
  699. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
  700. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
  701. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
  702. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
  703. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT
  704. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
  705. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
  706. #iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
  707. iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
  708. iptables -A INPUT -s localhost -d localhost -j ACCEPT
  709. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  710. iptables -P INPUT DROP
  711. service iptables save
  712. sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
  713. iptables_status=$(service iptables status | grep 'not running')
  714. if [ "${iptables_status}" == '' ];then
  715. service iptables restart
  716. fi
  717. else
  718. AliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux")
  719. [ "${AliyunCheck}" ] && return
  720. yum install firewalld -y
  721. [ "${Centos8Check}" ] && yum reinstall python3-six -y
  722. systemctl enable firewalld
  723. systemctl start firewalld
  724. firewall-cmd --set-default-zone=public > /dev/null 2>&1
  725. firewall-cmd --permanent --zone=public --add-port=20/tcp > /dev/null 2>&1
  726. firewall-cmd --permanent --zone=public --add-port=21/tcp > /dev/null 2>&1
  727. firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1
  728. firewall-cmd --permanent --zone=public --add-port=80/tcp > /dev/null 2>&1
  729. firewall-cmd --permanent --zone=public --add-port=443/tcp > /dev/null 2>&1
  730. firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1
  731. firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1
  732. firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp > /dev/null 2>&1
  733. #firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
  734. firewall-cmd --reload
  735. fi
  736. fi
  737. }
  738. Get_Ip_Address(){
  739. getIpAddress=""
  740. getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
  741. if [ -z "${getIpAddress}" ] || [ "${getIpAddress}" = "0.0.0.0" ]; then
  742. isHosts=$(cat /etc/hosts|grep 'www.bt.cn')
  743. if [ -z "${isHosts}" ];then
  744. echo "" >> /etc/hosts
  745. echo "116.213.43.206 www.bt.cn" >> /etc/hosts
  746. getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
  747. if [ -z "${getIpAddress}" ];then
  748. sed -i "/bt.cn/d" /etc/hosts
  749. fi
  750. fi
  751. fi
  752. ipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")
  753. if [ "${ipv4Check}" == "None" ];then
  754. ipv6Address=$(echo ${getIpAddress}|tr -d "[]")
  755. ipv6Check=$($python_bin -c "import re; print(re.match('^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))")
  756. if [ "${ipv6Check}" == "None" ]; then
  757. getIpAddress="SERVER_IP"
  758. else
  759. echo "True" > ${setup_path}/server/panel/data/ipv6.pl
  760. sleep 1
  761. /etc/init.d/bt restart
  762. fi
  763. fi
  764. if [ "${getIpAddress}" != "SERVER_IP" ];then
  765. echo "${getIpAddress}" > ${setup_path}/server/panel/data/iplist.txt
  766. fi
  767. LOCAL_IP=$(ip addr | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -E -v "^127\.|^255\.|^0\." | head -n 1)
  768. }
  769. Setup_Count(){
  770. curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/SetupCount?type=Linux\&o=$1 > /dev/null 2>&1
  771. if [ "$1" != "" ];then
  772. echo $1 > /www/server/panel/data/o.pl
  773. cd /www/server/panel
  774. $python_bin tools.py o
  775. fi
  776. echo /www > /var/bt_setupPath.conf
  777. }
  778. Install_Main(){
  779. startTime=`date +%s`
  780. Lock_Clear
  781. System_Check
  782. Get_Pack_Manager
  783. get_node_url
  784. MEM_TOTAL=$(free -g|grep Mem|awk '{print $2}')
  785. if [ "${MEM_TOTAL}" -le "1" ];then
  786. Auto_Swap
  787. fi
  788. if [ "${PM}" = "yum" ]; then
  789. Install_RPM_Pack
  790. elif [ "${PM}" = "apt-get" ]; then
  791. Install_Deb_Pack
  792. fi
  793. Install_Python_Lib
  794. Install_Bt
  795. Set_Bt_Panel
  796. Service_Add
  797. Set_Firewall
  798. Get_Ip_Address
  799. Setup_Count ${IDC_CODE}
  800. }
  801. echo "
  802. +----------------------------------------------------------------------
  803. | Bt-WebPanel FOR CentOS/Ubuntu/Debian
  804. +----------------------------------------------------------------------
  805. | Copyright © 2015-2099 BT-SOFT(http://www.bt.cn) All rights reserved.
  806. +----------------------------------------------------------------------
  807. | The WebPanel URL will be http://SERVER_IP:8888 when installed.
  808. +----------------------------------------------------------------------
  809. | 为了您的正常使用,请确保使用全新或纯净的系统安装宝塔面板,不支持已部署项目/环境的系统安装
  810. +----------------------------------------------------------------------
  811. "
  812. while [ "$go" != 'y' ] && [ "$go" != 'n' ]
  813. do
  814. read -p "Do you want to install Bt-Panel to the $setup_path directory now?(y/n): " go;
  815. done
  816. if [ "$go" == 'n' ];then
  817. exit;
  818. fi
  819. ARCH_LINUX=$(cat /etc/os-release |grep "Arch Linux")
  820. if [ "${ARCH_LINUX}" ] && [ -f "/usr/bin/pacman" ];then
  821. pacman -Sy
  822. pacman -S curl wget unzip firewalld openssl pkg-config make gcc cmake libxml2 libxslt libvpx gd libsodium oniguruma sqlite libzip autoconf inetutils sudo --noconfirm
  823. fi
  824. Install_Main
  825. echo > /www/server/panel/data/bind.pl
  826. echo -e "=================================================================="
  827. echo -e "\033[32mCongratulations! Installed successfully!\033[0m"
  828. echo -e "=================================================================="
  829. echo "外网面板地址: http://${getIpAddress}:${panelPort}${auth_path}"
  830. echo "内网面板地址: http://${LOCAL_IP}:${panelPort}${auth_path}"
  831. echo -e "username: $username"
  832. echo -e "password: $password"
  833. echo -e "\033[33mIf you cannot access the panel,\033[0m"
  834. echo -e "\033[33mrelease the following panel port [${panelPort}] in the security group\033[0m"
  835. echo -e "\033[33m若无法访问面板,请检查防火墙/安全组是否有放行面板[${panelPort}]端口\033[0m"
  836. echo -e "=================================================================="
  837. endTime=`date +%s`
  838. ((outTime=($endTime-$startTime)/60))
  839. echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"