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.

1081 lines
36 KiB

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