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.

1546 lines
54 KiB

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