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.

1497 lines
52 KiB

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