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.

1242 lines
42 KiB

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