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.

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