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.

1475 lines
51 KiB

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