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.

1111 lines
37 KiB

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