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.

1291 lines
43 KiB

1 year ago
4 months ago
1 year ago
4 months ago
1 year ago
1 week ago
1 year ago
4 months ago
1 year ago
12 months ago
1 year ago
4 months ago
1 year ago
10 months ago
1 year ago
4 months ago
1 year ago
4 months ago
1 year ago
8 months ago
6 months ago
8 months ago
1 year ago
8 months ago
1 year ago
4 months ago
2 months ago
4 months ago
1 year ago
4 months ago
2 months ago
1 year ago
4 months ago
1 year ago
8 months ago
1 year ago
8 months ago
1 year ago
4 months ago
1 year ago
4 months ago
1 year ago
4 months ago
1 year ago
8 months ago
1 year ago
1 year ago
7 months ago
4 months ago
7 months ago
1 year ago
1 year ago
1 year ago
10 months ago
1 year ago
8 months ago
1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
10 months ago
8 months ago
10 months ago
1 year ago
10 months ago
7 months ago
10 months ago
1 year ago
10 months ago
7 months ago
10 months ago
1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
8 months ago
7 months ago
8 months ago
1 year ago
10 months ago
8 months ago
10 months ago
4 months ago
1 year ago
4 months ago
1 year ago
8 months ago
1 year ago
1 week ago
1 year ago
8 months ago
1 year ago
10 months ago
1 year ago
4 months ago
1 year ago
4 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
8 months ago
1 year ago
1 year ago
  1. #!/bin/bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. LANG=en_US.UTF-8
  5. INSTALL_LOGFILE="/tmp/btpanel-install.log"
  6. # exec > >(tee -a "$INSTALL_LOGFILE") 2>&1
  7. Btapi_Url='http://www.example.com'
  8. Check_Api=$(curl -Ss --connect-timeout 5 -m 2 $Btapi_Url/api/SetupCount)
  9. if [ "$Check_Api" != 'ok' ];then
  10. Red_Error "此宝塔第三方云端无法连接,因此安装过程已中止!";
  11. fi
  12. if [ $(whoami) != "root" ];then
  13. echo "请使用root权限执行宝塔安装命令!"
  14. exit 1;
  15. fi
  16. is64bit=$(getconf LONG_BIT)
  17. if [ "${is64bit}" != '64' ];then
  18. echo "抱歉, 当前面板版本不支持32位系统, 请使用64位系统或安装宝塔5.9!";
  19. exit 1
  20. fi
  21. Ready_Check(){
  22. WWW_DISK_SPACE=$(df |grep /www|awk '{print $4}')
  23. ROOT_DISK_SPACE=$(df |grep /$|awk '{print $4}')
  24. if [ "${ROOT_DISK_SPACE}" -le 412000 ];then
  25. df -h
  26. echo -e "系统盘剩余空间不足400M 无法继续安装宝塔面板!"
  27. echo -e "请尝试清理磁盘空间后再重新进行安装"
  28. exit 1
  29. fi
  30. if [ "${WWW_DISK_SPACE}" ] && [ "${WWW_DISK_SPACE}" -le 412000 ] ;then
  31. echo -e "/www盘剩余空间不足400M 无法继续安装宝塔面板!"
  32. echo -e "请尝试清理磁盘空间后再重新进行安装"
  33. exit 1
  34. fi
  35. ROOT_DISK_INODE=$(df -i|grep /$|awk '{print $2}')
  36. if [ "${ROOT_DISK_INODE}" != "0" ];then
  37. ROOT_DISK_INODE_FREE=$(df -i|grep /$|awk '{print $4}')
  38. if [ "${ROOT_DISK_INODE_FREE}" -le 1000 ];then
  39. echo -e "系统盘剩余inodes空间不足1000,无法继续安装!"
  40. echo -e "请尝试清理磁盘空间后再重新进行安装"
  41. exit 1
  42. fi
  43. fi
  44. WWW_DISK_INODE==$(df -i|grep /www|awk '{print $2}')
  45. if [ "${WWW_DISK_INODE}" ] && [ "${WWW_DISK_INODE}" != "0" ] ;then
  46. WWW_DISK_INODE_FREE=$(df -i|grep /www|awk '{print $4}')
  47. if [ "${WWW_DISK_INODE_FREE}" ] && [ "${WWW_DISK_INODE_FREE}" -le 1000 ] ;then
  48. echo -e "/www盘剩余inodes空间不足1000, 无法继续安装!"
  49. echo -e "请尝试清理磁盘空间后再重新进行安装"
  50. exit 1
  51. fi
  52. fi
  53. }
  54. Centos6Check=$(cat /etc/redhat-release | grep ' 6.' | grep -iE 'centos|Red Hat')
  55. if [ "${Centos6Check}" ];then
  56. echo "Centos6不支持安装宝塔面板,请更换Centos7/8安装宝塔面板"
  57. exit 1
  58. fi
  59. UbuntuCheck=$(cat /etc/issue|grep Ubuntu|awk '{print $2}'|cut -f 1 -d '.')
  60. if [ "${UbuntuCheck}" ] && [ "${UbuntuCheck}" -lt "16" ];then
  61. echo "Ubuntu ${UbuntuCheck}不支持安装宝塔面板,建议更换Ubuntu22/24安装宝塔面板"
  62. exit 1
  63. fi
  64. HOSTNAME_CHECK=$(cat /etc/hostname)
  65. if [ -z "${HOSTNAME_CHECK}" ];then
  66. echo "当前主机名hostname为空无法安装宝塔面板,请咨询服务器运营商设置好hostname后再重新安装"
  67. exit 1
  68. fi
  69. UBUNTU_NO_LTS=$(cat /etc/issue|grep Ubuntu|grep -E "19|21|23|25")
  70. if [ "${UBUNTU_NO_LTS}" ];then
  71. echo "当前您使用的非Ubuntu-lts版本,无法进行宝塔面板的安装"
  72. echo "请使用Ubuntu-20/20/22/24进行安装宝塔面板"
  73. exit 1
  74. fi
  75. DEBIAN_9_C=$(cat /etc/issue|grep Debian|grep -E "8 |9 ")
  76. if [ "${DEBIAN_9_C}" ];then
  77. echo "当前您使用的Debian-8/9,官方已经停止支持、无法进行宝塔面板的安装"
  78. echo "请使用Debian-11/12进行安装宝塔面板"
  79. exit 1
  80. fi
  81. cd ~
  82. setup_path="/www"
  83. python_bin=$setup_path/server/panel/pyenv/bin/python
  84. cpu_cpunt=$(cat /proc/cpuinfo|grep processor|wc -l)
  85. panelPort=$(expr $RANDOM % 55535 + 10000)
  86. # if [ "$1" ];then
  87. # IDC_CODE=$1
  88. # fi
  89. GetSysInfo(){
  90. if [ -s "/etc/redhat-release" ];then
  91. SYS_VERSION=$(cat /etc/redhat-release)
  92. elif [ -s "/etc/issue" ]; then
  93. SYS_VERSION=$(cat /etc/issue)
  94. fi
  95. SYS_INFO=$(uname -a)
  96. SYS_BIT=$(getconf LONG_BIT)
  97. MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
  98. CPU_INFO=$(getconf _NPROCESSORS_ONLN)
  99. echo -e ${SYS_VERSION}
  100. echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
  101. echo -e ${SYS_INFO}
  102. echo -e "============================================"
  103. echo -e "请截图以上报错信息发帖至论坛www.bt.cn/bbs求助"
  104. echo -e "============================================"
  105. if [ -f "/etc/redhat-release" ];then
  106. Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos')
  107. echo -e "============================================"
  108. echo -e "Centos7/8官方已经停止支持"
  109. echo -e "如是新安装系统服务器建议更换至Debian-12/Ubuntu-22/Centos-9系统安装宝塔面板"
  110. echo -e "============================================"
  111. fi
  112. }
  113. Red_Error(){
  114. echo '=================================================';
  115. printf '\033[1;31;40m%b\033[0m\n' "$@";
  116. GetSysInfo
  117. exit 1;
  118. }
  119. Lock_Clear(){
  120. if [ -f "/etc/bt_crack.pl" ];then
  121. chattr -R -ia /www
  122. chattr -ia /etc/init.d/bt
  123. \cp -rpa /www/backup/panel/vhost/* /www/server/panel/vhost/
  124. mv /www/server/panel/BTPanel/__init__.bak /www/server/panel/BTPanel/__init__.py
  125. rm -f /etc/bt_crack.pl
  126. fi
  127. }
  128. Install_Check(){
  129. if [ "${INSTALL_FORCE}" ];then
  130. return
  131. fi
  132. echo -e "----------------------------------------------------"
  133. echo -e "检查已有其他Web/mysql环境,安装宝塔可能影响现有站点及数据"
  134. echo -e "Web/mysql service is alreday installed,Can't install panel"
  135. echo -e "----------------------------------------------------"
  136. echo -e "已知风险/Enter yes to force installation"
  137. read -p "输入yes强制安装: " yes;
  138. if [ "$yes" != "yes" ];then
  139. echo -e "------------"
  140. echo "取消安装"
  141. exit;
  142. fi
  143. INSTALL_FORCE="true"
  144. }
  145. System_Check(){
  146. MYSQLD_CHECK=$(ps -ef |grep mysqld|grep -v grep|grep -v /www/server/mysql)
  147. PHP_CHECK=$(ps -ef|grep php-fpm|grep master|grep -v /www/server/php)
  148. NGINX_CHECK=$(ps -ef|grep nginx|grep master|grep -v /www/server/nginx)
  149. HTTPD_CHECK=$(ps -ef |grep -E 'httpd|apache'|grep -v /www/server/apache|grep -v grep)
  150. if [ "${PHP_CHECK}" ] || [ "${MYSQLD_CHECK}" ] || [ "${NGINX_CHECK}" ] || [ "${HTTPD_CHECK}" ];then
  151. Install_Check
  152. fi
  153. }
  154. Set_Ssl(){
  155. SET_SSL=true
  156. if [ "${SSL_PL}" ];then
  157. SET_SSL=""
  158. fi
  159. }
  160. Add_lib_Install(){
  161. Get_Versions
  162. if [ "${os_type}" == "el" ] && [ "${os_version}" == "7" ];then
  163. cd /www/server/panel/class
  164. #btpython -c "import panelPlugin; plugin = panelPlugin.panelPlugin(); plugin.check_install_lib('1')"
  165. #echo "True" > /tmp/panelTask.pl
  166. fi
  167. }
  168. Get_Pack_Manager(){
  169. if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
  170. PM="yum"
  171. elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
  172. PM="apt-get"
  173. fi
  174. }
  175. Auto_Swap()
  176. {
  177. swap=$(free |grep Swap|awk '{print $2}')
  178. if [ "${swap}" -gt 1 ];then
  179. echo "Swap total sizse: $swap";
  180. return;
  181. fi
  182. if [ ! -d /www ];then
  183. mkdir /www
  184. fi
  185. echo "正在设置虚拟内存,请稍等..........";
  186. echo '---------------------------------------------';
  187. swapFile="/www/swap"
  188. dd if=/dev/zero of=$swapFile bs=1M count=1025
  189. mkswap -f $swapFile
  190. swapon $swapFile
  191. echo "$swapFile swap swap defaults 0 0" >> /etc/fstab
  192. swap=`free |grep Swap|awk '{print $2}'`
  193. if [ $swap -gt 1 ];then
  194. echo "Swap total sizse: $swap";
  195. return;
  196. fi
  197. sed -i "/\/www\/swap/d" /etc/fstab
  198. rm -f $swapFile
  199. }
  200. Service_Add(){
  201. if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
  202. chkconfig --add bt
  203. chkconfig --level 2345 bt on
  204. Centos9Check=$(cat /etc/redhat-release |grep ' 9')
  205. if [ "${Centos9Check}" ];then
  206. wget -O /usr/lib/systemd/system/btpanel.service ${download_Url}/init/systemd/btpanel.service
  207. systemctl enable btpanel
  208. fi
  209. elif [ "${PM}" == "apt-get" ]; then
  210. update-rc.d bt defaults
  211. fi
  212. }
  213. Set_Centos7_Repo(){
  214. # CN_YUM_URL=$(grep -E "aliyun|163|tencent|tsinghua" /etc/yum.repos.d/CentOS-Base.repo)
  215. # if [ -z "${CN_YUM_URL}" ];then
  216. # if [ -z "${download_Url}" ];then
  217. # download_Url="http://download.bt.cn"
  218. # fi
  219. # curl -Ss --connect-timeout 3 -m 60 ${download_Url}/install/vault-repo.sh|bash
  220. # return
  221. # fi
  222. MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "[^#]mirror.centos.org")
  223. if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
  224. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  225. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  226. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  227. fi
  228. TSU_MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "tuna.tsinghua.edu.cn")
  229. if [ "${TSU_MIRROR_CHECK}" ];then
  230. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  231. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  232. sed -i 's|#baseurl=https://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  233. sed -i 's|#baseurl=http://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  234. sed -i 's|baseurl=https://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  235. sed -i 's|baseurl=http://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  236. fi
  237. ALI_CLOUD_CHECK=$(grep Alibaba /etc/motd)
  238. Tencent_Cloud=$(cat /etc/hostname |grep -E VM-[0-9]+-[0-9]+)
  239. if [ "${ALI_CLOUD_CHECK}" ] || [ "${Tencent_Cloud}" ];then
  240. return
  241. fi
  242. yum install unzip -y
  243. if [ "$?" != "0" ] ;then
  244. TAR_CHECK=$(which tar)
  245. if [ "$?" == "0" ] ;then
  246. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  247. if [ -z "${download_Url}" ];then
  248. download_Url="http://download.bt.cn"
  249. fi
  250. curl -Ss --connect-timeout 5 -m 60 -O ${download_Url}/src/el7repo.tar.gz
  251. rm -f /etc/yum.repos.d/*.repo
  252. tar -xvzf el7repo.tar.gz -C /etc/yum.repos.d/
  253. fi
  254. fi
  255. yum install unzip -y
  256. if [ "$?" != "0" ] ;then
  257. sed -i "s/vault.epel.cloud/mirrors.cloud.tencent.com/g" /etc/yum.repos.d/*.repo
  258. fi
  259. }
  260. # Set_Centos7_Repo(){
  261. # if [ -z "${download_Url}" ];then
  262. # download_Url="http://download.bt.cn"
  263. # fi
  264. # curl -Ss --connect-timeout 3 -m 60 ${download_Url}/install/vault-repo.sh|bash
  265. # }
  266. Set_Centos8_Repo(){
  267. HUAWEI_CHECK=$(cat /etc/motd |grep "Huawei Cloud")
  268. if [ "${HUAWEI_CHECK}" ] && [ "${is64bit}" == "64" ];then
  269. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  270. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  271. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  272. rm -f /etc/yum.repos.d/epel.repo
  273. rm -f /etc/yum.repos.d/epel-*
  274. fi
  275. ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
  276. if [ "${ALIYUN_CHECK}" ] && [ "${is64bit}" == "64" ] && [ ! -f "/etc/yum.repos.d/Centos-vault-8.5.2111.repo" ];then
  277. rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
  278. wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
  279. wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
  280. 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
  281. sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo
  282. fi
  283. MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Linux-AppStream.repo |grep "[^#]mirror.centos.org")
  284. if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
  285. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  286. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  287. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  288. fi
  289. yum install unzip tar -y
  290. if [ "$?" != "0" ] ;then
  291. if [ -z "${download_Url}" ];then
  292. download_Url="http://download.bt.cn"
  293. fi
  294. if [ ! -f "/usr/bin/tar" ] ;then
  295. curl -Ss --connect-timeout 5 -m 60 -O ${download_Url}/src/tar-1.30-5.el8.x86_64.rpm
  296. yum install tar-1.30-5.el8.x86_64.rpm -y
  297. fi
  298. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  299. curl -Ss --connect-timeout 5 -m 60 -O ${download_Url}/src/el8repo.tar.gz
  300. rm -f /etc/yum.repos.d/*.repo
  301. tar -xvzf el8repo.tar.gz -C /etc/yum.repos.d/
  302. fi
  303. yum install unzip -y
  304. if [ "$?" != "0" ] ;then
  305. sed -i "s/vault.epel.cloud/mirrors.cloud.tencent.com/g" /etc/yum.repos.d/*.repo
  306. fi
  307. }
  308. get_node_url(){
  309. if [ ! -f /bin/curl ];then
  310. if [ "${PM}" = "yum" ]; then
  311. yum install curl -y
  312. elif [ "${PM}" = "apt-get" ]; then
  313. apt-get install curl -y
  314. fi
  315. fi
  316. if [ -f "/www/node.pl" ];then
  317. download_Url=$(cat /www/node.pl)
  318. echo "Download node: $download_Url";
  319. echo '---------------------------------------------';
  320. return
  321. fi
  322. echo '---------------------------------------------';
  323. echo "Selected download node...";
  324. nodes=(https://dg2.bt.cn https://download.bt.cn https://ctcc1-node.bt.cn https://cmcc1-node.bt.cn https://ctcc2-node.bt.cn https://hk1-node.bt.cn https://na1-node.bt.cn https://jp1-node.bt.cn https://cf1-node.aapanel.com https://download.bt.cn);
  325. CURL_CHECK=$(which curl)
  326. if [ "$?" == "0" ];then
  327. CN_CHECK=$(curl -sS --connect-timeout 10 -m 10 https://api.bt.cn/api/isCN)
  328. if [ "${CN_CHECK}" == "True" ];then
  329. nodes=(https://dg2.bt.cn https://download.bt.cn https://ctcc1-node.bt.cn https://cmcc1-node.bt.cn https://ctcc2-node.bt.cn https://hk1-node.bt.cn);
  330. fi
  331. fi
  332. if [ "$1" ];then
  333. nodes=($(echo ${nodes[*]}|sed "s#${1}##"))
  334. fi
  335. tmp_file1=/dev/shm/net_test1.pl
  336. tmp_file2=/dev/shm/net_test2.pl
  337. [ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
  338. [ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
  339. touch $tmp_file1
  340. touch $tmp_file2
  341. for node in ${nodes[@]};
  342. do
  343. NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
  344. RES=$(echo ${NODE_CHECK}|awk '{print $1}')
  345. NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $2}')
  346. TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $3 * 1000 - 500 }'|cut -d '.' -f 1)
  347. if [ "${NODE_STATUS}" == "200" ];then
  348. if [ $TIME_TOTAL -lt 300 ];then
  349. if [ $RES -ge 1500 ];then
  350. echo "$RES $node" >> $tmp_file1
  351. fi
  352. else
  353. if [ $RES -ge 1500 ];then
  354. echo "$TIME_TOTAL $node" >> $tmp_file2
  355. fi
  356. fi
  357. i=$(($i+1))
  358. if [ $TIME_TOTAL -lt 300 ];then
  359. if [ $RES -ge 2390 ];then
  360. break;
  361. fi
  362. fi
  363. fi
  364. done
  365. NODE_URL=$(cat $tmp_file1|sort -r -g -t " " -k 1|head -n 1|awk '{print $2}')
  366. if [ -z "$NODE_URL" ];then
  367. NODE_URL=$(cat $tmp_file2|sort -g -t " " -k 1|head -n 1|awk '{print $2}')
  368. if [ -z "$NODE_URL" ];then
  369. NODE_URL='https://download.bt.cn';
  370. fi
  371. fi
  372. rm -f $tmp_file1
  373. rm -f $tmp_file2
  374. download_Url=$NODE_URL
  375. echo "Download node: $download_Url";
  376. echo '---------------------------------------------';
  377. }
  378. Remove_Package(){
  379. local PackageNmae=$1
  380. if [ "${PM}" == "yum" ];then
  381. isPackage=$(rpm -q ${PackageNmae}|grep "not installed")
  382. if [ -z "${isPackage}" ];then
  383. yum remove ${PackageNmae} -y
  384. fi
  385. elif [ "${PM}" == "apt-get" ];then
  386. isPackage=$(dpkg -l|grep ${PackageNmae})
  387. if [ "${PackageNmae}" ];then
  388. apt-get remove ${PackageNmae} -y
  389. fi
  390. fi
  391. }
  392. Install_RPM_Pack(){
  393. yumPath=/etc/yum.conf
  394. CentosStream8Check=$(cat /etc/redhat-release |grep Stream|grep 8)
  395. if [ "${CentosStream8Check}" ];then
  396. MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Stream-AppStream.repo|grep "[^#]mirror.centos.org")
  397. if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
  398. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  399. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  400. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  401. fi
  402. fi
  403. Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
  404. if [ "${Centos8Check}" ];then
  405. Set_Centos8_Repo
  406. fi
  407. Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos|Red Hat')
  408. if [ "${Centos7Check}" ];then
  409. Set_Centos7_Repo
  410. fi
  411. isExc=$(cat $yumPath|grep httpd)
  412. if [ "$isExc" = "" ];then
  413. echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >> $yumPath
  414. fi
  415. if [ -f "/etc/redhat-release" ] && [ $(cat /etc/os-release|grep PLATFORM_ID|grep -oE "el8") ];then
  416. yum config-manager --set-enabled powertools
  417. yum config-manager --set-enabled PowerTools
  418. fi
  419. if [ -f "/etc/redhat-release" ] && [ $(cat /etc/os-release|grep PLATFORM_ID|grep -oE "el9") ];then
  420. dnf config-manager --set-enabled crb -y
  421. fi
  422. #SYS_TYPE=$(uname -a|grep x86_64)
  423. #yumBaseUrl=$(cat /etc/yum.repos.d/CentOS-Base.repo|grep baseurl=http|cut -d '=' -f 2|cut -d '$' -f 1|head -n 1)
  424. #[ "${yumBaseUrl}" ] && checkYumRepo=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${yumBaseUrl})
  425. #if [ "${checkYumRepo}" != "200" ] && [ "${SYS_TYPE}" ];then
  426. # curl -Ss --connect-timeout 3 -m 60 http://download.bt.cn/install/yumRepo_select.sh|bash
  427. #fi
  428. #尝试同步时间(从bt.cn)
  429. echo 'Synchronizing system time...'
  430. getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time)
  431. if [ "${getBtTime}" ];then
  432. date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"
  433. fi
  434. if [ -z "${Centos8Check}" ]; then
  435. yum install ntp -y
  436. rm -rf /etc/localtime
  437. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  438. #尝试同步国际时间(从ntp服务器)
  439. ntpdate 0.asia.pool.ntp.org
  440. setenforce 0
  441. fi
  442. startTime=`date +%s`
  443. sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  444. #yum remove -y python-requests python3-requests python-greenlet python3-greenlet
  445. 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"
  446. yum install -y ${yumPacks}
  447. for yumPack in ${yumPacks}
  448. do
  449. rpmPack=$(rpm -q ${yumPack})
  450. packCheck=$(echo ${rpmPack}|grep not)
  451. if [ "${packCheck}" ]; then
  452. yum install ${yumPack} -y
  453. fi
  454. done
  455. if [ -f "/usr/bin/dnf" ]; then
  456. dnf install -y redhat-rpm-config
  457. fi
  458. ALI_OS=$(cat /etc/redhat-release |grep "Alibaba Cloud Linux release 3")
  459. if [ -z "${ALI_OS}" ];then
  460. yum install epel-release -y
  461. fi
  462. }
  463. Install_Deb_Pack(){
  464. ln -sf bash /bin/sh
  465. UBUNTU_22=$(cat /etc/issue|grep "Ubuntu 22")
  466. if [ "${UBUNTU_22}" ];then
  467. apt-get remove needrestart -y
  468. fi
  469. ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
  470. if [ "${ALIYUN_CHECK}" ] && [ "${UBUNTU_22}" ];then
  471. apt-get remove libicu70 -y
  472. fi
  473. apt-get update -y
  474. apt-get install bash -y
  475. if [ -f "/usr/bin/bash" ];then
  476. ln -sf /usr/bin/bash /bin/sh
  477. fi
  478. apt-get install ruby -y
  479. apt-get install lsb-release -y
  480. #apt-get install ntp ntpdate -y
  481. #/etc/init.d/ntp stop
  482. #update-rc.d ntp remove
  483. #cat >>~/.profile<<EOF
  484. #TZ='Asia/Shanghai'; export TZ
  485. #EOF
  486. #rm -rf /etc/localtime
  487. #cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  488. #echo 'Synchronizing system time...'
  489. #ntpdate 0.asia.pool.ntp.org
  490. #apt-get upgrade -y
  491. LIBCURL_VER=$(dpkg -l|grep libcurl4|awk '{print $3}')
  492. if [ "${LIBCURL_VER}" == "7.68.0-1ubuntu2.8" ];then
  493. apt-get remove libcurl4 -y
  494. apt-get install curl -y
  495. fi
  496. 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 sqlite3";
  497. apt-get install -y $debPacks --force-yes
  498. for debPack in ${debPacks}
  499. do
  500. packCheck=$(dpkg -l|grep ${debPack})
  501. if [ "$?" -ne "0" ] ;then
  502. apt-get install -y $debPack
  503. fi
  504. done
  505. if [ ! -d '/etc/letsencrypt' ];then
  506. mkdir -p /etc/letsencryp
  507. mkdir -p /var/spool/cron
  508. if [ ! -f '/var/spool/cron/crontabs/root' ];then
  509. echo '' > /var/spool/cron/crontabs/root
  510. chmod 600 /var/spool/cron/crontabs/root
  511. fi
  512. fi
  513. }
  514. Get_Versions(){
  515. redhat_version_file="/etc/redhat-release"
  516. deb_version_file="/etc/issue"
  517. if [[ $(grep Anolis /etc/os-release) ]] && [[ $(grep VERSION /etc/os-release|grep 8.8) ]];then
  518. if [ -f "/usr/bin/yum" ];then
  519. os_type="anolis"
  520. os_version="8"
  521. return
  522. fi
  523. fi
  524. if [ -f "/etc/os-release" ];then
  525. . /etc/os-release
  526. OS_V=${VERSION_ID%%.*}
  527. if [ "${ID}" == "opencloudos" ] && [[ "${OS_V}" =~ ^(9)$ ]];then
  528. os_type="opencloudos"
  529. os_version="9"
  530. pyenv_tt="true"
  531. elif { [ "${ID}" == "almalinux" ] || [ "${ID}" == "centos" ] || [ "${ID}" == "rocky" ]; } && [[ "${OS_V}" =~ ^(9)$ ]]; then
  532. os_type="el"
  533. os_version="9"
  534. pyenv_tt="true"
  535. fi
  536. if [ "${pyenv_tt}" ];then
  537. return
  538. fi
  539. fi
  540. if [ -f $redhat_version_file ];then
  541. os_type='el'
  542. is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
  543. if [ "$is_aliyunos" != "" ];then
  544. return
  545. fi
  546. if [[ $(grep "Alibaba Cloud" /etc/redhat-release) ]] && [[ $(grep al8 /etc/os-release) ]];then
  547. os_type="ali-linux-"
  548. os_version="al8"
  549. return
  550. fi
  551. if [[ $(grep "TencentOS Server" /etc/redhat-release|grep 3.1) ]];then
  552. os_type="TencentOS-"
  553. os_version="3.1"
  554. return
  555. fi
  556. os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
  557. if [ "${os_version}" = "5" ];then
  558. os_version=""
  559. fi
  560. if [ -z "${os_version}" ];then
  561. os_version=$(cat /etc/redhat-release |grep Stream|grep -oE 8)
  562. fi
  563. else
  564. os_type='ubuntu'
  565. os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
  566. if [ "${os_version}" = "" ];then
  567. os_type='debian'
  568. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
  569. if [ "${os_version}" = "" ];then
  570. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
  571. fi
  572. if [ "${os_version}" = "8" ];then
  573. os_version=""
  574. fi
  575. if [ "${is64bit}" = '32' ];then
  576. os_version=""
  577. fi
  578. else
  579. if [ "$os_version" = "14" ];then
  580. os_version=""
  581. fi
  582. if [ "$os_version" = "12" ];then
  583. os_version=""
  584. fi
  585. if [ "$os_version" = "19" ];then
  586. os_version=""
  587. fi
  588. if [ "$os_version" = "21" ];then
  589. os_version=""
  590. fi
  591. if [ "$os_version" = "20" ];then
  592. os_version2004=$(cat /etc/issue|grep 20.04)
  593. if [ -z "${os_version2004}" ];then
  594. os_version=""
  595. fi
  596. fi
  597. fi
  598. fi
  599. }
  600. Install_Python_Lib(){
  601. curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
  602. pyenv_path="/www/server/panel"
  603. if [ -f $pyenv_path/pyenv/bin/python ];then
  604. is_ssl=$($python_bin -c "import ssl" 2>&1|grep cannot)
  605. $pyenv_path/pyenv/bin/python3.7 -V
  606. if [ $? -eq 0 ] && [ -z "${is_ssl}" ];then
  607. chmod -R 700 $pyenv_path/pyenv/bin
  608. is_package=$($python_bin -m psutil 2>&1|grep package)
  609. if [ "$is_package" = "" ];then
  610. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 15
  611. $pyenv_path/pyenv/bin/pip install -U pip
  612. $pyenv_path/pyenv/bin/pip install -U setuptools==65.5.0
  613. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  614. fi
  615. source $pyenv_path/pyenv/bin/activate
  616. chmod -R 700 $pyenv_path/pyenv/bin
  617. return
  618. else
  619. rm -rf $pyenv_path/pyenv
  620. fi
  621. fi
  622. is_loongarch64=$(uname -a|grep loongarch64)
  623. if [ "$is_loongarch64" != "" ] && [ -f "/usr/bin/yum" ];then
  624. yumPacks="python3-devel python3-pip python3-psutil python3-gevent python3-pyOpenSSL python3-paramiko python3-flask python3-rsa python3-requests python3-six python3-websocket-client"
  625. yum install -y ${yumPacks}
  626. for yumPack in ${yumPacks}
  627. do
  628. rpmPack=$(rpm -q ${yumPack})
  629. packCheck=$(echo ${rpmPack}|grep not)
  630. if [ "${packCheck}" ]; then
  631. yum install ${yumPack} -y
  632. fi
  633. done
  634. pip3 install -U pip
  635. pip3 install Pillow psutil pyinotify pycryptodome upyun oss2 pymysql qrcode qiniu redis pymongo Cython configparser cos-python-sdk-v5 supervisor gevent-websocket pyopenssl
  636. pip3 install flask==1.1.4
  637. pip3 install Pillow -U
  638. pyenv_bin=/www/server/panel/pyenv/bin
  639. mkdir -p $pyenv_bin
  640. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip
  641. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3
  642. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3.7
  643. if [ -f "/usr/bin/python3.7" ];then
  644. ln -sf /usr/bin/python3.7 $pyenv_bin/python
  645. ln -sf /usr/bin/python3.7 $pyenv_bin/python3
  646. ln -sf /usr/bin/python3.7 $pyenv_bin/python3.7
  647. elif [ -f "/usr/bin/python3.6" ]; then
  648. ln -sf /usr/bin/python3.6 $pyenv_bin/python
  649. ln -sf /usr/bin/python3.6 $pyenv_bin/python3
  650. ln -sf /usr/bin/python3.6 $pyenv_bin/python3.7
  651. fi
  652. echo > $pyenv_bin/activate
  653. return
  654. fi
  655. py_version="3.7.16"
  656. mkdir -p $pyenv_path
  657. echo "True" > /www/disk.pl
  658. if [ ! -w /www/disk.pl ];then
  659. Red_Error "ERROR: Install python env fielded." "ERROR: /www目录无法写入,请检查目录/用户/磁盘权限!"
  660. fi
  661. os_type='el'
  662. os_version='7'
  663. is_export_openssl=0
  664. Get_Versions
  665. echo "OS: $os_type - $os_version"
  666. is_aarch64=$(uname -a|grep aarch64)
  667. if [ "$is_aarch64" != "" ];then
  668. is64bit="aarch64"
  669. fi
  670. if [ -f "/www/server/panel/pymake.pl" ];then
  671. os_version=""
  672. rm -f /www/server/panel/pymake.pl
  673. fi
  674. echo "==============================================="
  675. echo "正在下载面板运行环境,请稍等..............."
  676. echo "==============================================="
  677. if [ "${os_version}" != "" ];then
  678. pyenv_file="/www/pyenv.tar.gz"
  679. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 15
  680. if [ "$?" != "0" ];then
  681. get_node_url $download_Url
  682. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 15
  683. fi
  684. tmp_size=$(du -b $pyenv_file|awk '{print $1}')
  685. if [ $tmp_size -lt 703460 ];then
  686. rm -f $pyenv_file
  687. echo "ERROR: Download python env fielded."
  688. else
  689. echo "Install python env..."
  690. tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null
  691. chmod -R 700 $pyenv_path/pyenv/bin
  692. if [ ! -f $pyenv_path/pyenv/bin/python ];then
  693. rm -f $pyenv_file
  694. Red_Error "ERROR: Install python env fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
  695. fi
  696. $pyenv_path/pyenv/bin/python3.7 -V
  697. if [ $? -eq 0 ];then
  698. rm -f $pyenv_file
  699. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  700. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  701. source $pyenv_path/pyenv/bin/activate
  702. return
  703. else
  704. rm -f $pyenv_file
  705. rm -rf $pyenv_path/pyenv
  706. fi
  707. fi
  708. fi
  709. cd /www
  710. python_src='/www/python_src.tar.xz'
  711. python_src_path="/www/Python-${py_version}"
  712. wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 15
  713. tmp_size=$(du -b $python_src|awk '{print $1}')
  714. if [ $tmp_size -lt 10703460 ];then
  715. rm -f $python_src
  716. Red_Error "ERROR: Download python source code fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
  717. fi
  718. tar xvf $python_src
  719. rm -f $python_src
  720. cd $python_src_path
  721. ./configure --prefix=$pyenv_path/pyenv
  722. make -j$cpu_cpunt
  723. make install
  724. if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
  725. rm -rf $python_src_path
  726. Red_Error "ERROR: Make python env fielded." "ERROR: 编译宝塔运行环境失败!"
  727. fi
  728. cd ~
  729. rm -rf $python_src_path
  730. wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 5
  731. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.16.txt -T 5
  732. ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
  733. ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
  734. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
  735. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
  736. chmod -R 700 $pyenv_path/pyenv/bin
  737. $pyenv_path/pyenv/bin/pip install -U pip
  738. $pyenv_path/pyenv/bin/pip install -U setuptools==65.5.0
  739. $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
  740. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  741. wget -O pip-packs.txt $download_Url/install/pyenv/pip-packs.txt
  742. PIP_PACKS=$(cat pip-packs.txt)
  743. for P_PACK in ${PIP_PACKS};
  744. do
  745. btpip show ${P_PACK} > /dev/null 2>&1
  746. if [ "$?" == "1" ];then
  747. btpip install ${P_PACK}
  748. fi
  749. done
  750. rm -f pip-packs.txt
  751. source $pyenv_path/pyenv/bin/activate
  752. btpip install psutil
  753. btpip install gevent
  754. is_gevent=$($python_bin -m gevent 2>&1|grep -oE package)
  755. is_psutil=$($python_bin -m psutil 2>&1|grep -oE package)
  756. if [ "${is_gevent}" != "${is_psutil}" ];then
  757. Red_Error "ERROR: psutil/gevent install failed!"
  758. fi
  759. }
  760. Install_Bt(){
  761. if [ -f ${setup_path}/server/panel/data/port.pl ];then
  762. panelPort=$(cat ${setup_path}/server/panel/data/port.pl)
  763. fi
  764. if [ "${PANEL_PORT}" ];then
  765. panelPort=$PANEL_PORT
  766. fi
  767. mkdir -p ${setup_path}/server/panel/logs
  768. mkdir -p ${setup_path}/server/panel/vhost/apache
  769. mkdir -p ${setup_path}/server/panel/vhost/nginx
  770. mkdir -p ${setup_path}/server/panel/vhost/rewrite
  771. mkdir -p ${setup_path}/server/panel/install
  772. mkdir -p /www/server
  773. mkdir -p /www/wwwroot
  774. mkdir -p /www/wwwlogs
  775. mkdir -p /www/backup/database
  776. mkdir -p /www/backup/site
  777. if [ ! -d "/etc/init.d" ];then
  778. mkdir -p /etc/init.d
  779. fi
  780. if [ -f "/etc/init.d/bt" ]; then
  781. /etc/init.d/bt stop
  782. sleep 1
  783. fi
  784. wget -O /etc/init.d/bt ${download_Url}/install/src/bt6.init -T 15
  785. wget -O /www/server/panel/install/public.sh ${Btapi_Url}/install/public.sh -T 15
  786. echo "=============================================="
  787. echo "正在下载面板文件,请稍等..................."
  788. echo "=============================================="
  789. wget -O panel.zip ${Btapi_Url}/install/src/panel6.zip -T 15
  790. if [ -f "${setup_path}/server/panel/data/default.db" ];then
  791. if [ -d "/${setup_path}/server/panel/old_data" ];then
  792. rm -rf ${setup_path}/server/panel/old_data
  793. fi
  794. mkdir -p ${setup_path}/server/panel/old_data
  795. d_format=$(date +"%Y%m%d_%H%M%S")
  796. \cp -arf ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/data/default_backup_${d_format}.db
  797. mv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.db
  798. mv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.db
  799. mv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.pl
  800. mv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.pl
  801. if [ -d "${setup_path}/server/panel/data/db" ];then
  802. \cp -r ${setup_path}/server/panel/data/db ${setup_path}/server/panel/old_data/
  803. fi
  804. fi
  805. if [ ! -f "/usr/bin/unzip" ]; then
  806. if [ "${PM}" = "yum" ]; then
  807. yum install unzip -y
  808. elif [ "${PM}" = "apt-get" ]; then
  809. apt-get update
  810. apt-get install unzip -y
  811. fi
  812. fi
  813. unzip -o panel.zip -d ${setup_path}/server/ > /dev/null
  814. if [ -d "${setup_path}/server/panel/old_data" ];then
  815. mv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.db
  816. mv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.db
  817. mv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.pl
  818. mv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.pl
  819. if [ -d "${setup_path}/server/panel/old_data/db" ];then
  820. \cp -r ${setup_path}/server/panel/old_data/db ${setup_path}/server/panel/data/
  821. fi
  822. if [ -d "/${setup_path}/server/panel/old_data" ];then
  823. rm -rf ${setup_path}/server/panel/old_data
  824. fi
  825. fi
  826. if [ ! -f ${setup_path}/server/panel/tools.py ] || [ ! -f ${setup_path}/server/panel/BT-Panel ];then
  827. ls -lh panel.zip
  828. Red_Error "ERROR: Failed to download, please try install again!" "ERROR: 下载宝塔失败,请尝试重新安装!"
  829. fi
  830. SYS_LOG_CHECK=$(grep ^weekly /etc/logrotate.conf)
  831. if [ "${SYS_LOG_CHECK}" ];then
  832. sed -i 's/rotate [0-9]*/rotate 8/g' /etc/logrotate.conf
  833. fi
  834. rm -f panel.zip
  835. rm -f ${setup_path}/server/panel/class/*.pyc
  836. rm -f ${setup_path}/server/panel/*.pyc
  837. chmod +x /etc/init.d/bt
  838. chmod -R 600 ${setup_path}/server/panel
  839. chmod -R +x ${setup_path}/server/panel/script
  840. ln -sf /etc/init.d/bt /usr/bin/bt
  841. echo "${panelPort}" > ${setup_path}/server/panel/data/port.pl
  842. wget -O /etc/init.d/bt ${download_Url}/install/src/bt7.init -T 15
  843. wget -O /www/server/panel/init.sh ${download_Url}/install/src/bt7.init -T 15
  844. wget -O /www/server/panel/data/softList.conf ${download_Url}/install/conf/softList.conf
  845. rm -f /www/server/panel/class/*.so
  846. if [ ! -f /www/server/panel/data/not_workorder.pl ]; then
  847. echo "True" > /www/server/panel/data/not_workorder.pl
  848. fi
  849. if [ ! -f /www/server/panel/data/userInfo.json ]; then
  850. 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
  851. fi
  852. if [ ! -f /www/server/panel/data/panel_nps.pl ]; then
  853. echo "" > /www/server/panel/data/panel_nps.pl
  854. fi
  855. if [ ! -f /www/server/panel/data/btwaf_nps.pl ]; then
  856. echo "" > /www/server/panel/data/btwaf_nps.pl
  857. fi
  858. if [ ! -f /www/server/panel/data/tamper_proof_nps.pl ]; then
  859. echo "" > /www/server/panel/data/tamper_proof_nps.pl
  860. fi
  861. if [ ! -f /www/server/panel/data/total_nps.pl ]; then
  862. echo "" > /www/server/panel/data/total_nps.pl
  863. fi
  864. }
  865. Set_Bt_Panel(){
  866. Run_User="www"
  867. wwwUser=$(cat /etc/passwd|cut -d ":" -f 1|grep ^www$)
  868. if [ "${wwwUser}" != "www" ];then
  869. groupadd ${Run_User}
  870. useradd -s /sbin/nologin -g ${Run_User} ${Run_User}
  871. fi
  872. password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
  873. if [ "$PANEL_PASSWORD" ];then
  874. password=$PANEL_PASSWORD
  875. fi
  876. sleep 1
  877. admin_auth="/www/server/panel/data/admin_path.pl"
  878. if [ ! -f ${admin_auth} ];then
  879. auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
  880. echo "/${auth_path}" > ${admin_auth}
  881. fi
  882. if [ "${SAFE_PATH}" ];then
  883. auth_path=$SAFE_PATH
  884. echo "/${auth_path}" > ${admin_auth}
  885. fi
  886. chmod -R 700 $pyenv_path/pyenv/bin
  887. if [ ! -f "/www/server/panel/pyenv/n.pl" ];then
  888. btpip install docxtpl==0.16.7
  889. /www/server/panel/pyenv/bin/pip3 install pymongo
  890. /www/server/panel/pyenv/bin/pip3 install psycopg2-binary
  891. /www/server/panel/pyenv/bin/pip3 install flask -U
  892. /www/server/panel/pyenv/bin/pip3 install flask-sock
  893. /www/server/panel/pyenv/bin/pip3 install -I gevent
  894. btpip install simple-websocket==0.10.0
  895. btpip install natsort
  896. btpip uninstall enum34 -y
  897. btpip install geoip2==4.7.0
  898. btpip install brotli
  899. btpip install PyMySQL
  900. fi
  901. auth_path=$(cat ${admin_auth})
  902. cd ${setup_path}/server/panel/
  903. /etc/init.d/bt start
  904. $python_bin -m py_compile tools.py
  905. $python_bin tools.py username
  906. username=$($python_bin tools.py panel ${password})
  907. if [ "$PANEL_USER" ];then
  908. username=$PANEL_USER
  909. fi
  910. cd ~
  911. echo "${password}" > ${setup_path}/server/panel/default.pl
  912. chmod 600 ${setup_path}/server/panel/default.pl
  913. sleep 3
  914. if [ "$SET_SSL" == true ]; then
  915. if [ ! -f "/www/server/panel/pyenv/n.pl" ];then
  916. btpip install -I pyOpenSSl 2>/dev/null
  917. fi
  918. echo "========================================"
  919. echo "正在开启面板SSL,请稍等............ "
  920. echo "========================================"
  921. SSL_STATUS=$(btpython /www/server/panel/tools.py ssl)
  922. if [ "${SSL_STATUS}" == "0" ] ;then
  923. echo -n " -4 " > /www/server/panel/data/v4.pl
  924. btpython /www/server/panel/tools.py ssl
  925. fi
  926. echo "证书开启成功!"
  927. echo "========================================"
  928. fi
  929. /etc/init.d/bt stop
  930. sleep 5
  931. /etc/init.d/bt start
  932. sleep 5
  933. isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}')
  934. LOCAL_CURL=$(curl 127.0.0.1:${panelPort}/login 2>&1 |grep -i html)
  935. if [ -z "${isStart}" ];then
  936. /etc/init.d/bt 22
  937. cd /www/server/panel/pyenv/bin
  938. touch t.pl
  939. ls -al python3.7 python
  940. lsattr python3.7 python
  941. Red_Error "ERROR: The BT-Panel service startup failed." "ERROR: 宝塔启动失败"
  942. fi
  943. if [ "$PANEL_USER" ];then
  944. cd ${setup_path}/server/panel/
  945. btpython -c 'import tools;tools.set_panel_username("'$PANEL_USER'")'
  946. cd ~
  947. fi
  948. if [ -f "/usr/bin/sqlite3" ] ;then
  949. sqlite3 /www/server/panel/data/db/panel.db "UPDATE config SET status = '1' WHERE id = '1';" > /dev/null 2>&1
  950. fi
  951. }
  952. Set_Firewall(){
  953. sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')
  954. if [ "${PM}" = "apt-get" ]; then
  955. apt-get install -y ufw
  956. if [ -f "/usr/sbin/ufw" ];then
  957. ufw allow 20/tcp
  958. ufw allow 21/tcp
  959. ufw allow 22/tcp
  960. ufw allow 80/tcp
  961. ufw allow 443/tcp
  962. ufw allow 888/tcp
  963. ufw allow ${panelPort}/tcp
  964. ufw allow ${sshPort}/tcp
  965. ufw allow 39000:40000/tcp
  966. ufw_status=`ufw status`
  967. echo y|ufw enable
  968. ufw default deny
  969. ufw reload
  970. fi
  971. else
  972. if [ -f "/etc/init.d/iptables" ];then
  973. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
  974. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
  975. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
  976. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
  977. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
  978. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT
  979. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
  980. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
  981. #iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
  982. iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
  983. iptables -A INPUT -s localhost -d localhost -j ACCEPT
  984. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  985. iptables -P INPUT DROP
  986. service iptables save
  987. sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
  988. iptables_status=$(service iptables status | grep 'not running')
  989. if [ "${iptables_status}" == '' ];then
  990. service iptables restart
  991. fi
  992. else
  993. AliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux")
  994. [ "${AliyunCheck}" ] && return
  995. yum install firewalld -y
  996. [ "${Centos8Check}" ] && yum reinstall python3-six -y
  997. systemctl enable firewalld
  998. systemctl start firewalld
  999. firewall-cmd --set-default-zone=public > /dev/null 2>&1
  1000. firewall-cmd --permanent --zone=public --add-port=20/tcp > /dev/null 2>&1
  1001. firewall-cmd --permanent --zone=public --add-port=21/tcp > /dev/null 2>&1
  1002. firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1
  1003. firewall-cmd --permanent --zone=public --add-port=80/tcp > /dev/null 2>&1
  1004. firewall-cmd --permanent --zone=public --add-port=443/tcp > /dev/null 2>&1
  1005. firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1
  1006. firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1
  1007. firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp > /dev/null 2>&1
  1008. #firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
  1009. firewall-cmd --reload
  1010. fi
  1011. fi
  1012. }
  1013. Get_Ip_Address(){
  1014. getIpAddress=""
  1015. getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
  1016. if [ -z "${getIpAddress}" ] || [ "${getIpAddress}" = "0.0.0.0" ]; then
  1017. isHosts=$(cat /etc/hosts|grep 'www.bt.cn')
  1018. if [ -z "${isHosts}" ];then
  1019. echo "" >> /etc/hosts
  1020. getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
  1021. if [ -z "${getIpAddress}" ];then
  1022. sed -i "/bt.cn/d" /etc/hosts
  1023. fi
  1024. fi
  1025. fi
  1026. ipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")
  1027. if [ "${ipv4Check}" == "None" ];then
  1028. ipv6Address=$(echo ${getIpAddress}|tr -d "[]")
  1029. ipv6Check=$($python_bin -c "import re; print(re.match('^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))")
  1030. if [ "${ipv6Check}" == "None" ]; then
  1031. getIpAddress="SERVER_IP"
  1032. else
  1033. echo "True" > ${setup_path}/server/panel/data/ipv6.pl
  1034. sleep 1
  1035. /etc/init.d/bt restart
  1036. fi
  1037. fi
  1038. if [ "${getIpAddress}" != "SERVER_IP" ];then
  1039. echo "${getIpAddress}" > ${setup_path}/server/panel/data/iplist.txt
  1040. fi
  1041. 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)
  1042. }
  1043. Setup_Count(){
  1044. curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/SetupCount?type=Linux\&o=$1 > /dev/null 2>&1
  1045. if [ "$1" != "" ];then
  1046. echo $1 > /www/server/panel/data/o.pl
  1047. cd /www/server/panel
  1048. $python_bin tools.py o
  1049. fi
  1050. echo /www > /var/bt_setupPath.conf
  1051. }
  1052. Install_Main(){
  1053. Ready_Check
  1054. #Set_Ssl
  1055. startTime=`date +%s`
  1056. Lock_Clear
  1057. System_Check
  1058. Get_Pack_Manager
  1059. get_node_url
  1060. MEM_TOTAL=$(free -g|grep Mem|awk '{print $2}')
  1061. if [ "${MEM_TOTAL}" -le "1" ];then
  1062. Auto_Swap
  1063. fi
  1064. if [ "${PM}" = "yum" ]; then
  1065. Install_RPM_Pack
  1066. elif [ "${PM}" = "apt-get" ]; then
  1067. Install_Deb_Pack
  1068. fi
  1069. Install_Python_Lib
  1070. Install_Bt
  1071. Set_Bt_Panel
  1072. Service_Add
  1073. Set_Firewall
  1074. Get_Ip_Address
  1075. Setup_Count ${IDC_CODE}
  1076. Add_lib_Install
  1077. }
  1078. echo "
  1079. +----------------------------------------------------------------------
  1080. | Bt-WebPanel FOR CentOS/Ubuntu/Debian
  1081. +----------------------------------------------------------------------
  1082. | Copyright © 2015-2099 BT-SOFT(http://www.bt.cn) All rights reserved.
  1083. +----------------------------------------------------------------------
  1084. | The WebPanel URL will be http://SERVER_IP:${panelPort} when installed.
  1085. +----------------------------------------------------------------------
  1086. | 为了您的正常使用,请确保使用全新或纯净的系统安装宝塔面板,不支持已部署项目/环境的系统安装
  1087. +----------------------------------------------------------------------
  1088. "
  1089. while [ ${#} -gt 0 ]; do
  1090. case $1 in
  1091. -u|--user)
  1092. PANEL_USER=$2
  1093. shift 1
  1094. ;;
  1095. -p|--password)
  1096. PANEL_PASSWORD=$2
  1097. shift 1
  1098. ;;
  1099. -P|--port)
  1100. PANEL_PORT=$2
  1101. shift 1
  1102. ;;
  1103. --safe-path)
  1104. SAFE_PATH=$2
  1105. shift 1
  1106. ;;
  1107. --ssl-disable)
  1108. SSL_PL="disable"
  1109. ;;
  1110. -y)
  1111. go="y"
  1112. ;;
  1113. *)
  1114. IDC_CODE=$1
  1115. ;;
  1116. esac
  1117. shift 1
  1118. done
  1119. while [ "$go" != 'y' ] && [ "$go" != 'n' ]
  1120. do
  1121. read -p "Do you want to install Bt-Panel to the $setup_path directory now?(y/n): " go;
  1122. done
  1123. if [ "$go" == 'n' ];then
  1124. exit;
  1125. fi
  1126. if [ -f "/www/server/panel/BT-Panel" ];then
  1127. AAPANEL_CHECK=$(grep www.aapanel.com /www/server/panel/BT-Panel)
  1128. if [ "${AAPANEL_CHECK}" ];then
  1129. echo -e "----------------------------------------------------"
  1130. echo -e "检查已安装有aapanel,无法进行覆盖安装宝塔面板"
  1131. echo -e "如继续执行安装将移去aapanel面板数据(备份至/www/server/aapanel路径) 全新安装宝塔面板"
  1132. echo -e "aapanel is alreday installed,Can't install panel"
  1133. echo -e "is install Baota panel, aapanel data will be removed (backed up to /www/server/aapanel)"
  1134. echo -e "Beginning new Baota panel installation."
  1135. echo -e "----------------------------------------------------"
  1136. echo -e "已知风险/Enter yes to force installation"
  1137. read -p "输入yes开始安装: " yes;
  1138. if [ "$yes" != "yes" ];then
  1139. echo -e "------------"
  1140. echo "取消安装"
  1141. exit;
  1142. fi
  1143. bt stop
  1144. sleep 1
  1145. mv /www/server/panel /www/server/aapanel
  1146. fi
  1147. fi
  1148. ARCH_LINUX=$(cat /etc/os-release |grep "Arch Linux")
  1149. if [ "${ARCH_LINUX}" ] && [ -f "/usr/bin/pacman" ];then
  1150. pacman -Sy
  1151. pacman -S curl wget unzip firewalld openssl pkg-config make gcc cmake libxml2 libxslt libvpx gd libsodium oniguruma sqlite libzip autoconf inetutils sudo --noconfirm
  1152. fi
  1153. Install_Main
  1154. PANEL_SSL=$(cat /www/server/panel/data/ssl.pl 2> /dev/null)
  1155. if [ "${PANEL_SSL}" == "True" ];then
  1156. HTTP_S="https"
  1157. else
  1158. HTTP_S="http"
  1159. fi
  1160. echo > /www/server/panel/data/bind.pl
  1161. echo -e "=================================================================="
  1162. echo -e "\033[32mCongratulations! Installed successfully!\033[0m"
  1163. echo -e "========================面板账户登录信息=========================="
  1164. echo -e ""
  1165. echo -e " 外网面板地址: ${HTTP_S}://${getIpAddress}:${panelPort}${auth_path}"
  1166. echo -e " 内网面板地址: ${HTTP_S}://${LOCAL_IP}:${panelPort}${auth_path}"
  1167. echo -e " username: $username"
  1168. echo -e " password: $password"
  1169. echo -e " "
  1170. echo -e "=========================打开面板前请看==========================="
  1171. echo -e ""
  1172. echo -e " 【云服务器】请在安全组放行 $panelPort 端口"
  1173. echo -e " 因默认启用自签证书https加密访问,浏览器将提示不安全"
  1174. echo -e " 点击【高级】-【继续访问】或【接受风险并继续】访问"
  1175. echo -e " 教程:https://www.bt.cn/bbs/thread-117246-1-1.html"
  1176. echo -e ""
  1177. echo -e "=================================================================="
  1178. endTime=`date +%s`
  1179. ((outTime=($endTime-$startTime)/60))
  1180. if [ "${outTime}" == "0" ];then
  1181. ((outTime=($endTime-$startTime)))
  1182. echo -e "Time consumed:\033[32m $outTime \033[0mseconds!"
  1183. else
  1184. echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"
  1185. fi