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.

877 lines
30 KiB

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