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.

1662 lines
58 KiB

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