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.

888 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
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 qrencode"
  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. ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
  293. if [ "${ALIYUN_CHECK}" ] && [ "${UBUNTU_22}" ];then
  294. apt-get remove libicu70 -y
  295. fi
  296. apt-get update -y
  297. apt-get install bash -y
  298. if [ -f "/usr/bin/bash" ];then
  299. ln -sf /usr/bin/bash /bin/sh
  300. fi
  301. apt-get install ruby -y
  302. apt-get install lsb-release -y
  303. #apt-get install ntp ntpdate -y
  304. #/etc/init.d/ntp stop
  305. #update-rc.d ntp remove
  306. #cat >>~/.profile<<EOF
  307. #TZ='Asia/Shanghai'; export TZ
  308. #EOF
  309. #rm -rf /etc/localtime
  310. #cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  311. #echo 'Synchronizing system time...'
  312. #ntpdate 0.asia.pool.ntp.org
  313. #apt-get upgrade -y
  314. LIBCURL_VER=$(dpkg -l|grep libcurl4|awk '{print $3}')
  315. if [ "${LIBCURL_VER}" == "7.68.0-1ubuntu2.8" ];then
  316. apt-get remove libcurl4 -y
  317. apt-get install curl -y
  318. fi
  319. 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";
  320. apt-get install -y $debPacks --force-yes
  321. for debPack in ${debPacks}
  322. do
  323. packCheck=$(dpkg -l|grep ${debPack})
  324. if [ "$?" -ne "0" ] ;then
  325. apt-get install -y $debPack
  326. fi
  327. done
  328. if [ ! -d '/etc/letsencrypt' ];then
  329. mkdir -p /etc/letsencryp
  330. mkdir -p /var/spool/cron
  331. if [ ! -f '/var/spool/cron/crontabs/root' ];then
  332. echo '' > /var/spool/cron/crontabs/root
  333. chmod 600 /var/spool/cron/crontabs/root
  334. fi
  335. fi
  336. }
  337. Get_Versions(){
  338. redhat_version_file="/etc/redhat-release"
  339. deb_version_file="/etc/issue"
  340. if [ -f $redhat_version_file ];then
  341. os_type='el'
  342. is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
  343. if [ "$is_aliyunos" != "" ];then
  344. return
  345. fi
  346. os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
  347. if [ "${os_version}" = "5" ];then
  348. os_version=""
  349. fi
  350. if [ -z "${os_version}" ];then
  351. os_version=$(cat /etc/redhat-release |grep Stream|grep -oE 8)
  352. fi
  353. else
  354. os_type='ubuntu'
  355. os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
  356. if [ "${os_version}" = "" ];then
  357. os_type='debian'
  358. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
  359. if [ "${os_version}" = "" ];then
  360. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
  361. fi
  362. if [ "${os_version}" = "8" ];then
  363. os_version=""
  364. fi
  365. if [ "${is64bit}" = '32' ];then
  366. os_version=""
  367. fi
  368. else
  369. if [ "$os_version" = "14" ];then
  370. os_version=""
  371. fi
  372. if [ "$os_version" = "12" ];then
  373. os_version=""
  374. fi
  375. if [ "$os_version" = "19" ];then
  376. os_version=""
  377. fi
  378. if [ "$os_version" = "21" ];then
  379. os_version=""
  380. fi
  381. if [ "$os_version" = "20" ];then
  382. os_version2004=$(cat /etc/issue|grep 20.04)
  383. if [ -z "${os_version2004}" ];then
  384. os_version=""
  385. fi
  386. fi
  387. fi
  388. fi
  389. }
  390. Install_Python_Lib(){
  391. curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
  392. pyenv_path="/www/server/panel"
  393. if [ -f $pyenv_path/pyenv/bin/python ];then
  394. is_ssl=$($python_bin -c "import ssl" 2>&1|grep cannot)
  395. $pyenv_path/pyenv/bin/python3.7 -V
  396. if [ $? -eq 0 ] && [ -z "${is_ssl}" ];then
  397. chmod -R 700 $pyenv_path/pyenv/bin
  398. is_package=$($python_bin -m psutil 2>&1|grep package)
  399. if [ "$is_package" = "" ];then
  400. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 5
  401. $pyenv_path/pyenv/bin/pip install -U pip
  402. $pyenv_path/pyenv/bin/pip install -U setuptools
  403. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  404. fi
  405. source $pyenv_path/pyenv/bin/activate
  406. chmod -R 700 $pyenv_path/pyenv/bin
  407. return
  408. else
  409. rm -rf $pyenv_path/pyenv
  410. fi
  411. fi
  412. is_loongarch64=$(uname -a|grep loongarch64)
  413. if [ "$is_loongarch64" != "" ] && [ -f "/usr/bin/yum" ];then
  414. yumPacks="python3-devel python3-pip python3-psutil python3-gevent python3-pyOpenSSL python3-paramiko python3-flask python3-rsa python3-requests python3-six python3-websocket-client"
  415. yum install -y ${yumPacks}
  416. for yumPack in ${yumPacks}
  417. do
  418. rpmPack=$(rpm -q ${yumPack})
  419. packCheck=$(echo ${rpmPack}|grep not)
  420. if [ "${packCheck}" ]; then
  421. yum install ${yumPack} -y
  422. fi
  423. done
  424. pip3 install -U pip
  425. pip3 install Pillow psutil pyinotify pycryptodome upyun oss2 pymysql qrcode qiniu redis pymongo Cython configparser cos-python-sdk-v5 supervisor gevent-websocket pyopenssl
  426. pip3 install flask==1.1.4
  427. pip3 install Pillow -U
  428. pyenv_bin=/www/server/panel/pyenv/bin
  429. mkdir -p $pyenv_bin
  430. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip
  431. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3
  432. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3.7
  433. if [ -f "/usr/bin/python3.7" ];then
  434. ln -sf /usr/bin/python3.7 $pyenv_bin/python
  435. ln -sf /usr/bin/python3.7 $pyenv_bin/python3
  436. ln -sf /usr/bin/python3.7 $pyenv_bin/python3.7
  437. elif [ -f "/usr/bin/python3.6" ]; then
  438. ln -sf /usr/bin/python3.6 $pyenv_bin/python
  439. ln -sf /usr/bin/python3.6 $pyenv_bin/python3
  440. ln -sf /usr/bin/python3.6 $pyenv_bin/python3.7
  441. fi
  442. echo > $pyenv_bin/activate
  443. return
  444. fi
  445. py_version="3.7.8"
  446. mkdir -p $pyenv_path
  447. echo "True" > /www/disk.pl
  448. if [ ! -w /www/disk.pl ];then
  449. Red_Error "ERROR: Install python env fielded." "ERROR: /www目录无法写入,请检查目录/用户/磁盘权限!"
  450. fi
  451. os_type='el'
  452. os_version='7'
  453. is_export_openssl=0
  454. Get_Versions
  455. echo "OS: $os_type - $os_version"
  456. is_aarch64=$(uname -a|grep aarch64)
  457. if [ "$is_aarch64" != "" ];then
  458. is64bit="aarch64"
  459. fi
  460. if [ -f "/www/server/panel/pymake.pl" ];then
  461. os_version=""
  462. rm -f /www/server/panel/pymake.pl
  463. fi
  464. if [ "${os_version}" != "" ];then
  465. pyenv_file="/www/pyenv.tar.gz"
  466. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10
  467. if [ "$?" != "0" ];then
  468. get_node_url $download_Url
  469. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10
  470. fi
  471. tmp_size=$(du -b $pyenv_file|awk '{print $1}')
  472. if [ $tmp_size -lt 703460 ];then
  473. rm -f $pyenv_file
  474. echo "ERROR: Download python env fielded."
  475. else
  476. echo "Install python env..."
  477. tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null
  478. chmod -R 700 $pyenv_path/pyenv/bin
  479. if [ ! -f $pyenv_path/pyenv/bin/python ];then
  480. rm -f $pyenv_file
  481. Red_Error "ERROR: Install python env fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
  482. fi
  483. $pyenv_path/pyenv/bin/python3.7 -V
  484. if [ $? -eq 0 ];then
  485. rm -f $pyenv_file
  486. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  487. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  488. source $pyenv_path/pyenv/bin/activate
  489. return
  490. else
  491. rm -f $pyenv_file
  492. rm -rf $pyenv_path/pyenv
  493. fi
  494. fi
  495. fi
  496. cd /www
  497. python_src='/www/python_src.tar.xz'
  498. python_src_path="/www/Python-${py_version}"
  499. wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 5
  500. tmp_size=$(du -b $python_src|awk '{print $1}')
  501. if [ $tmp_size -lt 10703460 ];then
  502. rm -f $python_src
  503. Red_Error "ERROR: Download python source code fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
  504. fi
  505. tar xvf $python_src
  506. rm -f $python_src
  507. cd $python_src_path
  508. ./configure --prefix=$pyenv_path/pyenv
  509. make -j$cpu_cpunt
  510. make install
  511. if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
  512. rm -rf $python_src_path
  513. Red_Error "ERROR: Make python env fielded." "ERROR: 编译宝塔运行环境失败!"
  514. fi
  515. cd ~
  516. rm -rf $python_src_path
  517. wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 5
  518. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.8.txt -T 5
  519. ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
  520. ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
  521. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  522. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  523. chmod -R 700 $pyenv_path/pyenv/bin
  524. $pyenv_path/pyenv/bin/pip install -U pip
  525. $pyenv_path/pyenv/bin/pip install -U setuptools
  526. $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
  527. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  528. source $pyenv_path/pyenv/bin/activate
  529. is_gevent=$($python_bin -m gevent 2>&1|grep -oE package)
  530. is_psutil=$($python_bin -m psutil 2>&1|grep -oE package)
  531. if [ "${is_gevent}" != "${is_psutil}" ];then
  532. Red_Error "ERROR: psutil/gevent install failed!"
  533. fi
  534. }
  535. Install_Bt(){
  536. panelPort="8888"
  537. if [ -f ${setup_path}/server/panel/data/port.pl ];then
  538. panelPort=$(cat ${setup_path}/server/panel/data/port.pl)
  539. else
  540. RE_NUM=$(expr $RANDOM % 3)
  541. if [ "${RE_NUM}" == "1" ];then
  542. panelPort=$(expr $RANDOM % 55535 + 10000)
  543. fi
  544. fi
  545. mkdir -p ${setup_path}/server/panel/logs
  546. mkdir -p ${setup_path}/server/panel/vhost/apache
  547. mkdir -p ${setup_path}/server/panel/vhost/nginx
  548. mkdir -p ${setup_path}/server/panel/vhost/rewrite
  549. mkdir -p ${setup_path}/server/panel/install
  550. mkdir -p /www/server
  551. mkdir -p /www/wwwroot
  552. mkdir -p /www/wwwlogs
  553. mkdir -p /www/backup/database
  554. mkdir -p /www/backup/site
  555. if [ ! -d "/etc/init.d" ];then
  556. mkdir -p /etc/init.d
  557. fi
  558. if [ -f "/etc/init.d/bt" ]; then
  559. /etc/init.d/bt stop
  560. sleep 1
  561. fi
  562. wget -O /etc/init.d/bt ${download_Url}/install/src/bt6.init -T 10
  563. wget -O /www/server/panel/install/public.sh ${Btapi_Url}/install/public.sh -T 10
  564. wget -O panel.zip ${Btapi_Url}/install/src/panel6.zip -T 10
  565. if [ -f "${setup_path}/server/panel/data/default.db" ];then
  566. if [ -d "/${setup_path}/server/panel/old_data" ];then
  567. rm -rf ${setup_path}/server/panel/old_data
  568. fi
  569. mkdir -p ${setup_path}/server/panel/old_data
  570. d_format=$(date +"%Y%m%d_%H%M%S")
  571. \cp -arf ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/data/default_backup_${d_format}.db
  572. mv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.db
  573. mv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.db
  574. mv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.pl
  575. mv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.pl
  576. fi
  577. if [ ! -f "/usr/bin/unzip" ]; then
  578. if [ "${PM}" = "yum" ]; then
  579. yum install unzip -y
  580. elif [ "${PM}" = "apt-get" ]; then
  581. apt-get update
  582. apt-get install unzip -y
  583. fi
  584. fi
  585. unzip -o panel.zip -d ${setup_path}/server/ > /dev/null
  586. if [ -d "${setup_path}/server/panel/old_data" ];then
  587. mv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.db
  588. mv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.db
  589. mv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.pl
  590. mv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.pl
  591. if [ -d "/${setup_path}/server/panel/old_data" ];then
  592. rm -rf ${setup_path}/server/panel/old_data
  593. fi
  594. fi
  595. if [ ! -f ${setup_path}/server/panel/tools.py ] || [ ! -f ${setup_path}/server/panel/BT-Panel ];then
  596. ls -lh panel.zip
  597. Red_Error "ERROR: Failed to download, please try install again!" "ERROR: 下载宝塔失败,请尝试重新安装!"
  598. fi
  599. rm -f panel.zip
  600. rm -f ${setup_path}/server/panel/class/*.pyc
  601. rm -f ${setup_path}/server/panel/*.pyc
  602. chmod +x /etc/init.d/bt
  603. chmod -R 600 ${setup_path}/server/panel
  604. chmod -R +x ${setup_path}/server/panel/script
  605. ln -sf /etc/init.d/bt /usr/bin/bt
  606. echo "${panelPort}" > ${setup_path}/server/panel/data/port.pl
  607. wget -O /etc/init.d/bt ${download_Url}/install/src/bt7.init -T 10
  608. wget -O /www/server/panel/init.sh ${download_Url}/install/src/bt7.init -T 10
  609. wget -O /www/server/panel/data/softList.conf ${download_Url}/install/conf/softList.conf
  610. rm -f /www/server/panel/class/*.so
  611. if [ ! -f /www/server/panel/data/not_workorder.pl ]; then
  612. echo "True" > /www/server/panel/data/not_workorder.pl
  613. fi
  614. if [ ! -f /www/server/panel/data/userInfo.json ]; then
  615. 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
  616. fi
  617. }
  618. Set_Bt_Panel(){
  619. Run_User="www"
  620. wwwUser=$(cat /etc/passwd|cut -d ":" -f 1|grep ^www$)
  621. if [ "${wwwUser}" != "www" ];then
  622. groupadd ${Run_User}
  623. useradd -s /sbin/nologin -g ${Run_User} ${Run_User}
  624. fi
  625. password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
  626. sleep 1
  627. admin_auth="/www/server/panel/data/admin_path.pl"
  628. if [ ! -f ${admin_auth} ];then
  629. auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
  630. echo "/${auth_path}" > ${admin_auth}
  631. fi
  632. chmod -R 700 $pyenv_path/pyenv/bin
  633. /www/server/panel/pyenv/bin/pip3 install pymongo
  634. /www/server/panel/pyenv/bin/pip3 install psycopg2-binary
  635. /www/server/panel/pyenv/bin/pip3 install flask -U
  636. /www/server/panel/pyenv/bin/pip3 install flask-sock
  637. auth_path=$(cat ${admin_auth})
  638. cd ${setup_path}/server/panel/
  639. /etc/init.d/bt start
  640. $python_bin -m py_compile tools.py
  641. $python_bin tools.py username
  642. username=$($python_bin tools.py panel ${password})
  643. cd ~
  644. echo "${password}" > ${setup_path}/server/panel/default.pl
  645. chmod 600 ${setup_path}/server/panel/default.pl
  646. sleep 3
  647. /etc/init.d/bt restart
  648. sleep 3
  649. isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}')
  650. LOCAL_CURL=$(curl 127.0.0.1:8888/login 2>&1 |grep -i html)
  651. if [ -z "${isStart}" ] && [ -z "${LOCAL_CURL}" ];then
  652. /etc/init.d/bt 22
  653. cd /www/server/panel/pyenv/bin
  654. touch t.pl
  655. ls -al python3.7 python
  656. lsattr python3.7 python
  657. Red_Error "ERROR: The BT-Panel service startup failed." "ERROR: 宝塔启动失败"
  658. fi
  659. }
  660. Set_Firewall(){
  661. sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')
  662. if [ "${PM}" = "apt-get" ]; then
  663. apt-get install -y ufw
  664. if [ -f "/usr/sbin/ufw" ];then
  665. ufw allow 20/tcp
  666. ufw allow 21/tcp
  667. ufw allow 22/tcp
  668. ufw allow 80/tcp
  669. ufw allow 443/tcp
  670. ufw allow 888/tcp
  671. ufw allow ${panelPort}/tcp
  672. ufw allow ${sshPort}/tcp
  673. ufw allow 39000:40000/tcp
  674. ufw_status=`ufw status`
  675. echo y|ufw enable
  676. ufw default deny
  677. ufw reload
  678. fi
  679. else
  680. if [ -f "/etc/init.d/iptables" ];then
  681. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
  682. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
  683. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
  684. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
  685. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
  686. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT
  687. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
  688. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
  689. #iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
  690. iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
  691. iptables -A INPUT -s localhost -d localhost -j ACCEPT
  692. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  693. iptables -P INPUT DROP
  694. service iptables save
  695. sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
  696. iptables_status=$(service iptables status | grep 'not running')
  697. if [ "${iptables_status}" == '' ];then
  698. service iptables restart
  699. fi
  700. else
  701. AliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux")
  702. [ "${AliyunCheck}" ] && return
  703. yum install firewalld -y
  704. [ "${Centos8Check}" ] && yum reinstall python3-six -y
  705. systemctl enable firewalld
  706. systemctl start firewalld
  707. firewall-cmd --set-default-zone=public > /dev/null 2>&1
  708. firewall-cmd --permanent --zone=public --add-port=20/tcp > /dev/null 2>&1
  709. firewall-cmd --permanent --zone=public --add-port=21/tcp > /dev/null 2>&1
  710. firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1
  711. firewall-cmd --permanent --zone=public --add-port=80/tcp > /dev/null 2>&1
  712. firewall-cmd --permanent --zone=public --add-port=443/tcp > /dev/null 2>&1
  713. firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1
  714. firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1
  715. firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp > /dev/null 2>&1
  716. #firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
  717. firewall-cmd --reload
  718. fi
  719. fi
  720. }
  721. Get_Ip_Address(){
  722. getIpAddress=""
  723. getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
  724. if [ -z "${getIpAddress}" ] || [ "${getIpAddress}" = "0.0.0.0" ]; then
  725. isHosts=$(cat /etc/hosts|grep 'www.bt.cn')
  726. if [ -z "${isHosts}" ];then
  727. echo "" >> /etc/hosts
  728. echo "116.213.43.206 www.bt.cn" >> /etc/hosts
  729. getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
  730. if [ -z "${getIpAddress}" ];then
  731. sed -i "/bt.cn/d" /etc/hosts
  732. fi
  733. fi
  734. fi
  735. ipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")
  736. if [ "${ipv4Check}" == "None" ];then
  737. ipv6Address=$(echo ${getIpAddress}|tr -d "[]")
  738. ipv6Check=$($python_bin -c "import re; print(re.match('^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))")
  739. if [ "${ipv6Check}" == "None" ]; then
  740. getIpAddress="SERVER_IP"
  741. else
  742. echo "True" > ${setup_path}/server/panel/data/ipv6.pl
  743. sleep 1
  744. /etc/init.d/bt restart
  745. fi
  746. fi
  747. if [ "${getIpAddress}" != "SERVER_IP" ];then
  748. echo "${getIpAddress}" > ${setup_path}/server/panel/data/iplist.txt
  749. fi
  750. 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)
  751. }
  752. Setup_Count(){
  753. curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/SetupCount?type=Linux\&o=$1 > /dev/null 2>&1
  754. if [ "$1" != "" ];then
  755. echo $1 > /www/server/panel/data/o.pl
  756. cd /www/server/panel
  757. $python_bin tools.py o
  758. fi
  759. echo /www > /var/bt_setupPath.conf
  760. }
  761. Install_Main(){
  762. startTime=`date +%s`
  763. Lock_Clear
  764. System_Check
  765. Get_Pack_Manager
  766. get_node_url
  767. MEM_TOTAL=$(free -g|grep Mem|awk '{print $2}')
  768. if [ "${MEM_TOTAL}" -le "1" ];then
  769. Auto_Swap
  770. fi
  771. if [ "${PM}" = "yum" ]; then
  772. Install_RPM_Pack
  773. elif [ "${PM}" = "apt-get" ]; then
  774. Install_Deb_Pack
  775. fi
  776. Install_Python_Lib
  777. Install_Bt
  778. Set_Bt_Panel
  779. Service_Add
  780. Set_Firewall
  781. Get_Ip_Address
  782. Setup_Count ${IDC_CODE}
  783. }
  784. echo "
  785. +----------------------------------------------------------------------
  786. | Bt-WebPanel FOR CentOS/Ubuntu/Debian
  787. +----------------------------------------------------------------------
  788. | Copyright © 2015-2099 BT-SOFT(http://www.bt.cn) All rights reserved.
  789. +----------------------------------------------------------------------
  790. | The WebPanel URL will be http://SERVER_IP:8888 when installed.
  791. +----------------------------------------------------------------------
  792. | 为了您的正常使用,请确保使用全新或纯净的系统安装宝塔面板,不支持已部署项目/环境的系统安装
  793. +----------------------------------------------------------------------
  794. "
  795. while [ "$go" != 'y' ] && [ "$go" != 'n' ]
  796. do
  797. read -p "Do you want to install Bt-Panel to the $setup_path directory now?(y/n): " go;
  798. done
  799. if [ "$go" == 'n' ];then
  800. exit;
  801. fi
  802. ARCH_LINUX=$(cat /etc/os-release |grep "Arch Linux")
  803. if [ "${ARCH_LINUX}" ] && [ -f "/usr/bin/pacman" ];then
  804. pacman -Sy
  805. pacman -S curl wget unzip firewalld openssl pkg-config make gcc cmake libxml2 libxslt libvpx gd libsodium oniguruma sqlite libzip autoconf inetutils sudo --noconfirm
  806. fi
  807. Install_Main
  808. echo > /www/server/panel/data/bind.pl
  809. echo -e "=================================================================="
  810. echo -e "\033[32mCongratulations! Installed successfully!\033[0m"
  811. echo -e "=================================================================="
  812. echo "外网面板地址: http://${getIpAddress}:${panelPort}${auth_path}"
  813. echo "内网面板地址: http://${LOCAL_IP}:${panelPort}${auth_path}"
  814. echo -e "username: $username"
  815. echo -e "password: $password"
  816. echo -e "\033[33mIf you cannot access the panel,\033[0m"
  817. echo -e "\033[33mrelease the following panel port [${panelPort}] in the security group\033[0m"
  818. echo -e "\033[33m若无法访问面板,请检查防火墙/安全组是否有放行面板[${panelPort}]端口\033[0m"
  819. echo -e "=================================================================="
  820. endTime=`date +%s`
  821. ((outTime=($endTime-$startTime)/60))
  822. echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"