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.

2033 lines
79 KiB

2 months 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 "The BT cloud could not be connected, so the installation process has been aborted!";
  9. fi
  10. if [ $(whoami) != "root" ]; then
  11. # echo "Please use the [root] user to execute the aapanel installation script!"
  12. echo -e "Non-root install, please try the following solutions: \n 1.Please switch to [root] user install \n 2.Try executing the following install commands: \n sudo bash $0 $@"
  13. exit 1
  14. fi
  15. is64bit=$(getconf LONG_BIT)
  16. if [ "${is64bit}" != '64' ]; then
  17. Red_Error "Sorry, aaPanel does not support 32-bit systems"
  18. fi
  19. HOSTNAME_CHECK=$(cat /etc/hostname)
  20. if [ -z "${HOSTNAME_CHECK}" ];then
  21. echo "hostname is empty. Already set as aaPanel"
  22. echo "aaPanel" > /etc/hostname
  23. hostnamectl set-hostname aaPanel
  24. fi
  25. if [ -f "/etc/SUSE-brand" ];then
  26. openSUSE_check=$(cat /etc/SUSE-brand |grep openSUSE)
  27. if [ "${openSUSE_check}" ];then
  28. echo "Error: openSUSE not supported, Recommended that you use:"
  29. echo "Debian 11/12, Ubuntu 20/22/24, Rocky/Alma 8, Rocky/Alma/Centos 9"
  30. exit 1
  31. fi
  32. fi
  33. cd ~
  34. setup_path="/www"
  35. python_bin=$setup_path/server/panel/pyenv/bin/python
  36. cpu_cpunt=$(cat /proc/cpuinfo | grep ^processor | wc -l)
  37. panelPort=$(expr $RANDOM % 55535 + 10000)
  38. if [ "$1" ]; then
  39. IDC_CODE=$1
  40. fi
  41. Command_Exists() {
  42. command -v "$@" >/dev/null 2>&1
  43. }
  44. GetSysInfo() {
  45. if [ -s "/etc/redhat-release" ]; then
  46. SYS_VERSION=$(cat /etc/redhat-release)
  47. elif [ -s "/etc/issue" ]; then
  48. SYS_VERSION=$(cat /etc/issue)
  49. fi
  50. SYS_INFO=$(uname -a)
  51. SYS_BIT=$(getconf LONG_BIT)
  52. MEM_TOTAL=$(free -m | grep Mem | awk '{print $2}')
  53. CPU_INFO=$(getconf _NPROCESSORS_ONLN)
  54. echo -e ${SYS_VERSION}
  55. echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
  56. echo -e ${SYS_INFO}
  57. echo -e "Please screenshot above error message and post forum forum.aapanel.com or send email: kern@aapanel.com for help"
  58. }
  59. Replace_symbol(){
  60. # 更换符号为__
  61. text="${text#"${text%%[![:space:]]*}"}"
  62. text=${text%% }
  63. text=${text// /__}
  64. text=${text//\(/__}
  65. text=${text//\)/__}
  66. text=${text//\"/__}
  67. text=${text//\“/__}
  68. text=${text//\”/__}
  69. text=${text//\(/__}
  70. text=${text//\)/__}
  71. text=${text//\!/__}
  72. text=${text//\!/__}
  73. text=${text//:/__}
  74. text=${text//:/__}
  75. text=${text//,/__}
  76. text=${text//,/__}
  77. text=${text//。/__}
  78. text=${text//\$/__}
  79. text=${text//\{/__}
  80. text=${text//\}/__}
  81. text=${text//\[/__}
  82. text=${text//\]/__}
  83. text=${text//./__}
  84. text=${text//-/__}
  85. text=${text//>/__}
  86. text=${text//=/__}
  87. text=${text//\//__}
  88. text=${text//\'/__}
  89. }
  90. Red_Error() {
  91. echo '================================================='
  92. printf '\033[1;31;40m%b\033[0m\n' "$@"
  93. GetSysInfo
  94. if [[ "$@" == "" ]]; then
  95. url_err_msg="aaPanel_install_failed_vP"
  96. else
  97. text="$@"
  98. Replace_symbol
  99. url_err_msg="${text}_vP"
  100. #echo "url_err_msg:$url_err_msg"
  101. fi
  102. exit 1
  103. }
  104. if [ -f "/etc/redhat-release" ]; then
  105. Centos6Check=$(cat /etc/redhat-release | grep ' 6.' | grep -iE 'centos|Red Hat')
  106. if [ "${Centos6Check}" ]; then
  107. Red_Error "Sorry, Centos6 does not support installing aaPanel"
  108. fi
  109. Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos|Red Hat')
  110. Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
  111. if [ "${Centos7Check}" ] || [ "${Centos8Check}" ];then
  112. echo "Centos 7/8 provider no longer maintained, Recommended that you use:"
  113. echo "Debian 11/12, Ubuntu 20/22/24, Rocky/Alma 8, Rocky/Alma/Centos 9"
  114. echo "Press Ctrl+C to cancel or Wait 10 seconds before install"
  115. sleep 10
  116. fi
  117. fi
  118. if [ -f "/etc/issue" ]; then
  119. UbuntuCheck=$(cat /etc/issue | grep Ubuntu | awk '{print $2}' | cut -f 1 -d '.')
  120. if [[ ! -z "${UbuntuCheck}" ]] && [[ "${UbuntuCheck}" =~ ^[0-9]+$ ]] && [[ "${UbuntuCheck}" -lt "18" ]]; then
  121. Red_Error "Ubuntu ${UbuntuCheck} is not supported to the aaPanel, it is recommended to replace the Ubuntu 20/22/24 to install"
  122. fi
  123. DebianCheck=$(cat /etc/issue | grep Debian | awk '{print $3}' | cut -f 1 -d '.')
  124. if [[ ! -z "${DebianCheck}" ]] && [[ "${DebianCheck}" =~ ^[0-9]+$ ]] && [[ "${DebianCheck}" -lt "10" ]]; then
  125. Red_Error "Debian ${DebianCheck} is not supported to the aaPanel, it is recommended to replace the Debian 11/12 to install"
  126. fi
  127. fi
  128. Check_Disk_Space() {
  129. # Get the available space of the partition where the /www directory is located (in kb)
  130. if [ -d "/www" ]; then
  131. available_kb=$(df -k /www | awk 'NR==2 {print $4}')
  132. else
  133. available_kb=$(df -k / | awk 'NR==2 {print $4}')
  134. fi
  135. # 1GB = 1024MB = 1024*1024KB
  136. available_gb=$((available_kb / 1024 / 1024))
  137. echo "Available disk space on the install partition: "$available_gb" G"
  138. # Determine if available space is less than 1 gb
  139. if [ "$available_gb" -lt 1 ]; then
  140. echo -e "\033[31m The available space is less than 1G.\033[0m"
  141. echo -e "\033[31m It is recommended to clean or upgrade the server space before upgrading.\033[0m"
  142. Red_Error "Error: The available space is less than 1G"
  143. fi
  144. }
  145. Lock_Clear() {
  146. if [ -f "/etc/bt_crack.pl" ]; then
  147. chattr -R -ia /www
  148. chattr -ia /etc/init.d/bt
  149. \cp -rpa /www/backup/panel/vhost/* /www/server/panel/vhost/
  150. mv /www/server/panel/BTPanel/__init__.bak /www/server/panel/BTPanel/__init__.py
  151. rm -f /etc/bt_crack.pl
  152. fi
  153. }
  154. Install_Check() {
  155. if [ "${INSTALL_FORCE}" ]; then
  156. return
  157. fi
  158. echo -e "----------------------------------------------------"
  159. echo -e "Web service is already installed,installing aaPanel may affect existing sites."
  160. echo -e "----------------------------------------------------"
  161. echo -e "Enter [yes] to force installation"
  162. read -p "Enter yes to force installation: " yes
  163. if [ "$yes" != "yes" ]; then
  164. echo -e "------------"
  165. echo "Installation canceled"
  166. exit
  167. fi
  168. INSTALL_FORCE="true"
  169. }
  170. System_Check() {
  171. MYSQLD_CHECK=$(ps -ef | grep mysqld | grep -v grep | grep -v /www/server/mysql)
  172. PHP_CHECK=$(ps -ef | grep php-fpm | grep master | grep -v /www/server/php)
  173. NGINX_CHECK=$(ps -ef | grep nginx | grep master | grep -v /www/server/nginx)
  174. HTTPD_CHECK=$(ps -ef | grep -E 'httpd|apache' | grep -v /www/server/apache | grep -v grep)
  175. if [ "${PHP_CHECK}" ] || [ "${MYSQLD_CHECK}" ] || [ "${NGINX_CHECK}" ] || [ "${HTTPD_CHECK}" ]; then
  176. Install_Check
  177. fi
  178. }
  179. Set_Ssl() {
  180. SET_SSL=true
  181. if [ "${SSL_PL}" ];then
  182. SET_SSL=""
  183. fi
  184. }
  185. Get_Pack_Manager() {
  186. if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
  187. PM="yum"
  188. elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
  189. PM="apt-get"
  190. fi
  191. }
  192. Auto_Swap() {
  193. swap=$(free | grep Swap | awk '{print $2}')
  194. if [ "${swap}" -gt 1 ]; then
  195. echo "Swap total sizse: $swap"
  196. return
  197. fi
  198. if [ ! -d /www ]; then
  199. mkdir /www
  200. fi
  201. swapFile="/www/swap"
  202. dd if=/dev/zero of=$swapFile bs=1M count=1025
  203. mkswap -f $swapFile
  204. swapon $swapFile
  205. echo "$swapFile swap swap defaults 0 0" >>/etc/fstab
  206. swap=$(free | grep Swap | awk '{print $2}')
  207. if [ $swap -gt 1 ]; then
  208. echo "Swap total sizse: $swap"
  209. return
  210. fi
  211. sed -i "/\/www\/swap/d" /etc/fstab
  212. rm -f $swapFile
  213. }
  214. Service_Add() {
  215. if Command_Exists systemctl ; then
  216. wget --no-check-certificate -O /usr/lib/systemd/system/btpanel.service ${download_Url}/init/systemd/btpanel.service -t 5 -T 20
  217. systemctl daemon-reload
  218. systemctl enable btpanel
  219. else
  220. if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
  221. chkconfig --add bt
  222. chkconfig --level 2345 bt on
  223. elif [ "${PM}" == "apt-get" ]; then
  224. update-rc.d bt defaults
  225. fi
  226. fi
  227. }
  228. Set_Centos7_Repo(){
  229. MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "[^#]mirror.centos.org")
  230. if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
  231. echo "Centos7 official repository source has been discontinued , Replacement in progress."
  232. if [ -d "/etc/yumBak" ];then
  233. mv /etc/yumBak /etc/yumBak_$(date +%Y_%m_%d_%H_%M_%S)
  234. fi
  235. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  236. sed -i 's/mirrorlist=/#mirrorlist=/g' /etc/yum.repos.d/CentOS-*.repo
  237. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  238. fi
  239. MIRROR_CHECK22=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "mirrorlist.centos.org"|grep -v '^#')
  240. if [ "${MIRROR_CHECK22}" ] && [ "${is64bit}" == "64" ];then
  241. echo "Centos7 official repository source has been discontinued , Replacement in progress."
  242. if [ -d "/etc/yumBak" ];then
  243. mv /etc/yumBak /etc/yumBak_$(date +%Y_%m_%d_%H_%M_%S)
  244. fi
  245. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  246. \cp -rpa /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bt_bak
  247. cat > /etc/yum.repos.d/CentOS-Base.repo << EOF
  248. # CentOS-Base.repo
  249. [base]
  250. name=CentOS-\$releasever - Base
  251. #mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os&infra=\$infra
  252. baseurl=http://vault.epel.cloud/centos/\$releasever/os/\$basearch/
  253. gpgcheck=1
  254. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  255. #released updates
  256. [updates]
  257. name=CentOS-\$releasever - Updates
  258. #mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates&infra=\$infra
  259. baseurl=http://vault.epel.cloud/centos/\$releasever/updates/\$basearch/
  260. gpgcheck=1
  261. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  262. #additional packages that may be useful
  263. [extras]
  264. name=CentOS-\$releasever - Extras
  265. #mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras&infra=\$infra
  266. baseurl=http://vault.epel.cloud/centos/\$releasever/extras/\$basearch/
  267. gpgcheck=1
  268. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  269. #additional packages that extend functionality of existing packages
  270. [centosplus]
  271. name=CentOS-\$releasever - Plus
  272. #mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus&infra=\$infra
  273. baseurl=http://vault.epel.cloud/centos/\$releasever/centosplus/\$basearch/
  274. gpgcheck=1
  275. enabled=0
  276. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  277. EOF
  278. fi
  279. ALI_CLOUD_CHECK=$(grep Alibaba /etc/motd)
  280. Tencent_Cloud=$(cat /etc/hostname |grep -E VM-[0-9]+-[0-9]+)
  281. if [ "${ALI_CLOUD_CHECK}" ] || [ "${Tencent_Cloud}" ];then
  282. return
  283. fi
  284. yum install unzip -y
  285. if [ "$?" != "0" ] ;then
  286. TAR_CHECK=$(which tar)
  287. if [ "$?" == "0" ] ;then
  288. if [ -d "/etc/yumBak" ];then
  289. mv /etc/yumBak /etc/yumBak_$(date +%Y_%m_%d_%H_%M_%S)
  290. fi
  291. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  292. if [ -z "${download_Url}" ];then
  293. download_Url="https://node.aapanel.com"
  294. fi
  295. curl -Ssk --connect-timeout 20 -m 60 -O ${download_Url}/src/el7repo.tar.gz
  296. if [ -f "/usr/bin/wget" ] && [ ! -s "el7repo.tar.gz" ];then
  297. wget --no-check-certificate -O el7repo.tar.gz ${download_Url}/src/el7repo.tar.gz -t 3 -T 20
  298. fi
  299. rm -f /etc/yum.repos.d/*.repo
  300. tar -xvzf el7repo.tar.gz -C /etc/yum.repos.d/
  301. rm -f el7repo.tar.gz
  302. fi
  303. fi
  304. }
  305. Set_Centos8_Repo(){
  306. HUAWEI_CHECK=$(cat /etc/motd |grep "Huawei Cloud")
  307. if [ "${HUAWEI_CHECK}" ] && [ "${is64bit}" == "64" ];then
  308. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  309. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  310. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  311. rm -f /etc/yum.repos.d/epel.repo
  312. rm -f /etc/yum.repos.d/epel-*
  313. fi
  314. ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
  315. if [ "${ALIYUN_CHECK}" ] && [ "${is64bit}" == "64" ] && [ ! -f "/etc/yum.repos.d/Centos-vault-8.5.2111.repo" ];then
  316. rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
  317. wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
  318. wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
  319. 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
  320. sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo
  321. fi
  322. MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Linux-AppStream.repo |grep "[^#]mirror.centos.org")
  323. if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
  324. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  325. sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
  326. sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
  327. fi
  328. yum install unzip tar -y
  329. if [ "$?" != "0" ] ;then
  330. if [ -z "${download_Url}" ];then
  331. download_Url="https://node.aapanel.com"
  332. fi
  333. if [ ! -f "/usr/bin/tar" ] ;then
  334. curl -Ss --connect-timeout 20 -m 60 -O ${download_Url}/src/tar-1.30-5.el8.x86_64.rpm
  335. if [ -f "/usr/bin/wget" ] && [ ! -s "tar-1.30-5.el8.x86_64.rpm" ];then
  336. wget --no-check-certificate -O tar-1.30-5.el8.x86_64.rpm ${download_Url}/src/tar-1.30-5.el8.x86_64.rpm -t 3 -T 20
  337. fi
  338. # yum install tar-1.30-5.el8.x86_64.rpm -y
  339. rpm -ivh tar-1.30-5.el8.x86_64.rpm
  340. rm -f tar-1.30-5.el8.x86_64.rpm
  341. fi
  342. if [ -d "/etc/yumBak" ];then
  343. mv /etc/yumBak /etc/yumBak_$(date +%Y_%m_%d_%H_%M_%S)
  344. fi
  345. \cp -rpa /etc/yum.repos.d/ /etc/yumBak
  346. curl -Ss --connect-timeout 20 -m 60 -O ${download_Url}/src/el8repo.tar.gz
  347. if [ -f "/usr/bin/wget" ] && [ ! -s "el8repo.tar.gz" ];then
  348. wget --no-check-certificate -O el8repo.tar.gz ${download_Url}/src/el8repo.tar.gz -t 3 -T 20
  349. fi
  350. rm -f /etc/yum.repos.d/*.repo
  351. tar -xvzf el8repo.tar.gz -C /etc/yum.repos.d/
  352. rm -f el8repo.tar.gz
  353. fi
  354. }
  355. Bored_waiting(){
  356. w_time="$wait_time"
  357. msg="$wait_msg"
  358. progress="."
  359. for ((i=0; i<${w_time}; i++))
  360. do
  361. printf "$msg %-10s %d\r" "$progress" "$((i+1))"
  362. sleep 1
  363. if [ "$progress" == ".........." ]; then
  364. progress="."
  365. else
  366. progress+="."
  367. fi
  368. done
  369. printf "$msg %-10s %d\r" ".........." "$w_time"
  370. #echo ""
  371. }
  372. Check_apt_status(){
  373. MAX_RETRIES=30
  374. retries=0
  375. while [ $retries -lt $MAX_RETRIES ]; do
  376. output=$(ps aux| grep -E '(apt|apt-get)\s' 2>&1)
  377. check_output=$(echo "$output" | grep -E '(apt|apt-get)\s')
  378. #If check_output is empty, terminate the loop
  379. if [ -z "$check_output" ]; then
  380. break
  381. fi
  382. retries=$((retries + 1))
  383. echo "apt-get is in use, it will automatically exit after ${retries}/${MAX_RETRIES} times, try again after 10 seconds..."
  384. echo "$check_output"
  385. wait_msg="Please wait"
  386. wait_time="10"
  387. Bored_waiting
  388. done
  389. if [ $retries -ge $MAX_RETRIES ]; then
  390. Red_Error "ERROR: apt-get command exceeds the maximum wait times: ${MAX_RETRIES}." "Do not use the apt/apt-get command or install software during installation, please try to reinstall!"
  391. fi
  392. }
  393. get_node_url() {
  394. download_Url='https://node.aapanel.com'
  395. if [ ! -f /bin/curl ]; then
  396. if [ "${PM}" = "yum" ]; then
  397. yum install curl -y
  398. elif [ "${PM}" = "apt-get" ]; then
  399. apt-get install curl -y
  400. fi
  401. fi
  402. if [ -f "/www/node.pl" ];then
  403. download_Url=$(cat /www/node.pl)
  404. echo "Download node: $download_Url";
  405. echo '---------------------------------------------';
  406. return
  407. fi
  408. # echo '---------------------------------------------';
  409. # echo "Selected download node...";
  410. # nodes=(https://node.aapanel.com);
  411. # if [ "$1" ];then
  412. # nodes=($(echo ${nodes[*]}|sed "s#${1}##"))
  413. # fi
  414. # tmp_file1=/dev/shm/net_test1.pl
  415. # tmp_file2=/dev/shm/net_test2.pl
  416. # [ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
  417. # [ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
  418. # touch $tmp_file1
  419. # touch $tmp_file2
  420. # for node in ${nodes[@]}; do
  421. # NODE_CHECK=$(curl -k --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
  422. # RES=$(echo ${NODE_CHECK} | awk '{print $1}')
  423. # NODE_STATUS=$(echo ${NODE_CHECK} | awk '{print $2}')
  424. # TIME_TOTAL=$(echo ${NODE_CHECK} | awk '{print $3 * 1000 - 500 }' | cut -d '.' -f 1)
  425. # if [ "${NODE_STATUS}" == "200" ]; then
  426. # if [ $TIME_TOTAL -lt 100 ]; then
  427. # if [ $RES -ge 1500 ]; then
  428. # echo "$RES $node" >>$tmp_file1
  429. # fi
  430. # else
  431. # if [ $RES -ge 1500 ]; then
  432. # echo "$TIME_TOTAL $node" >>$tmp_file2
  433. # fi
  434. # fi
  435. # i=$(($i + 1))
  436. # if [ $TIME_TOTAL -lt 100 ]; then
  437. # if [ $RES -ge 3000 ]; then
  438. # break
  439. # fi
  440. # fi
  441. # fi
  442. # done
  443. # NODE_URL=$(cat $tmp_file1 | sort -r -g -t " " -k 1 | head -n 1 | awk '{print $2}')
  444. # if [ -z "$NODE_URL" ]; then
  445. # NODE_URL=$(cat $tmp_file2 | sort -g -t " " -k 1 | head -n 1 | awk '{print $2}')
  446. # if [ -z "$NODE_URL" ]; then
  447. # NODE_URL='https://node.aapanel.com'
  448. # fi
  449. # fi
  450. # rm -f $tmp_file1
  451. # rm -f $tmp_file2
  452. # download_Url=$NODE_URL
  453. # echo "Download node: $download_Url"
  454. # echo '---------------------------------------------'
  455. }
  456. Remove_Package() {
  457. local PackageNmae=$1
  458. if [ "${PM}" == "yum" ]; then
  459. isPackage=$(rpm -q ${PackageNmae} | grep "not installed")
  460. if [ -z "${isPackage}" ]; then
  461. yum remove ${PackageNmae} -y
  462. fi
  463. elif [ "${PM}" == "apt-get" ]; then
  464. isPackage=$(dpkg -l | grep ${PackageNmae})
  465. if [ "${PackageNmae}" ]; then
  466. apt-get remove ${PackageNmae} -y
  467. fi
  468. fi
  469. }
  470. Install_RPM_Pack() {
  471. yumPath=/etc/yum.conf
  472. Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
  473. CentOS_Stream_8=$(cat /etc/redhat-release | grep 'CentOS Stream release 8' | grep -iE 'centos|Red Hat')
  474. if [ "${Centos8Check}" ] || [ "${CentOS_Stream_8}" ];then
  475. Set_Centos8_Repo
  476. fi
  477. Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos|Red Hat')
  478. if [ "${Centos7Check}" ];then
  479. Set_Centos7_Repo
  480. fi
  481. isExc=$(cat $yumPath | grep httpd)
  482. if [ "$isExc" = "" ]; then
  483. echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >>$yumPath
  484. fi
  485. if [ -f "/etc/redhat-release" ] && [ $(cat /etc/os-release|grep PLATFORM_ID|grep -oE "el8") ];then
  486. yum config-manager --set-enabled powertools
  487. yum config-manager --set-enabled PowerTools
  488. fi
  489. if [ -f "/etc/redhat-release" ] && [ $(cat /etc/os-release|grep PLATFORM_ID|grep -oE "el9") ];then
  490. dnf config-manager --set-enabled crb -y
  491. fi
  492. #yumBaseUrl=$(cat /etc/yum.repos.d/CentOS-Base.repo|grep baseurl=http|cut -d '=' -f 2|cut -d '$' -f 1|head -n 1)
  493. #[ "${yumBaseUrl}" ] && checkYumRepo=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${yumBaseUrl})
  494. #if [ "${checkYumRepo}" != "200" ];then
  495. # curl -Ss --connect-timeout 3 -m 60 http://node.aapanel.com/install/yumRepo_select.sh|bash
  496. #fi
  497. #尝试同步时间(从bt.cn)
  498. # echo 'Synchronizing system time...'
  499. # getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time)
  500. # if [ "${getBtTime}" ];then
  501. # date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"
  502. # fi
  503. #if [ -z "${Centos8Check}" ]; then
  504. # yum install ntp -y
  505. # rm -rf /etc/localtime
  506. # ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  507. #尝试同步国际时间(从ntp服务器)
  508. # ntpdate 0.asia.pool.ntp.org
  509. # setenforce 0
  510. #fi
  511. setenforce 0
  512. startTime=$(date +%s)
  513. sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  514. #yum remove -y python-requests python3-requests python-greenlet python3-greenlet
  515. 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 firewalld ipset libpq-devel ca-certificates sudo at mariadb rsyslog autoconf xfsprogs quota"
  516. yum install -y ${yumPacks}
  517. for yumPack in ${yumPacks}; do
  518. rpmPack=$(rpm -q ${yumPack})
  519. packCheck=$(echo ${rpmPack} | grep not)
  520. if [ "${packCheck}" ]; then
  521. yum install ${yumPack} -y
  522. fi
  523. done
  524. if [ -f "/usr/bin/dnf" ]; then
  525. dnf install -y redhat-rpm-config
  526. fi
  527. ALI_OS=$(cat /etc/redhat-release | grep "Alibaba Cloud Linux release 3")
  528. if [ -z "${ALI_OS}" ]; then
  529. yum install epel-release -y
  530. fi
  531. }
  532. Install_Deb_Pack() {
  533. Check_apt_status
  534. ln -sf bash /bin/sh
  535. UBUNTU_22=$(cat /etc/issue|grep "Ubuntu 22")
  536. UBUNTU_24=$(cat /etc/issue|grep "Ubuntu 24")
  537. if [ "${UBUNTU_22}" ] || [ "${UBUNTU_24}" ];then
  538. apt-get remove needrestart -y
  539. fi
  540. apt-get update -y
  541. apt-get install bash -y
  542. if [ -f "/usr/bin/bash" ];then
  543. ln -sf /usr/bin/bash /bin/sh
  544. fi
  545. FNOS_CHECK=$(grep fnOS /etc/issue)
  546. if [ "${FNOS_CHECK}" ];then
  547. apt-get install libc6 -y --allow-change-held-packages
  548. apt-get install libc6-dev -y --allow-change-held-packages
  549. fi
  550. apt-get install ruby -y
  551. apt-get install lsb-release -y
  552. #apt-get install ntp ntpdate -y
  553. #/etc/init.d/ntp stop
  554. #update-rc.d ntp remove
  555. #cat >>~/.profile<<EOF
  556. #TZ='Asia/Shanghai'; export TZ
  557. #EOF
  558. #rm -rf /etc/localtime
  559. #cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  560. #echo 'Synchronizing system time...'
  561. #ntpdate 0.asia.pool.ntp.org
  562. #apt-get upgrade -y
  563. LIBCURL_VER=$(dpkg -l | grep libcurl4 | awk '{print $3}')
  564. if [ "${LIBCURL_VER}" == "7.68.0-1ubuntu2.8" ]; then
  565. apt-get remove libcurl4 -y
  566. apt-get install curl -y
  567. fi
  568. debPacks="wget curl libcurl4-openssl-dev gcc make zip unzip tar openssl libssl-dev gcc libxml2 libxml2-dev libxslt-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 ufw ipset sqlite3 uuid-dev libpq-dev liblzma-dev ca-certificates sudo autoconf at mariadb-client rsyslog xfsprogs quota"
  569. DEBIAN_FRONTEND=noninteractive apt-get install -y $debPacks --allow-downgrades --allow-remove-essential --allow-change-held-packages
  570. for debPack in ${debPacks}; do
  571. packCheck=$(dpkg -l ${debPack})
  572. if [ "$?" -ne "0" ]; then
  573. DEBIAN_FRONTEND=noninteractive apt-get install -y $debPack --allow-downgrades --allow-remove-essential --allow-change-held-packages
  574. fi
  575. done
  576. if [ ! -d '/etc/letsencrypt' ]; then
  577. mkdir -p /etc/letsencryp
  578. mkdir -p /var/spool/cron
  579. if [ ! -f '/var/spool/cron/crontabs/root' ]; then
  580. echo '' >/var/spool/cron/crontabs/root
  581. chmod 600 /var/spool/cron/crontabs/root
  582. fi
  583. fi
  584. }
  585. Ubuntu_20_sources () {
  586. cat > /etc/apt/sources.list << EOF
  587. deb http://archive.ubuntu.com/ubuntu focal main restricted
  588. # deb-src http://archive.ubuntu.com/ubuntu focal main restricted
  589. deb http://ubuntu.mirror.constant.com focal main restricted
  590. # deb-src http://ubuntu.mirror.constant.com focal main restricted
  591. deb http://archive.ubuntu.com/ubuntu focal-updates main restricted
  592. # deb-src http://archive.ubuntu.com/ubuntu focal-updates main restricted
  593. deb http://ubuntu.mirror.constant.com focal-updates main restricted
  594. # deb-src http://ubuntu.mirror.constant.com focal-updates main restricted
  595. deb http://archive.ubuntu.com/ubuntu focal universe
  596. # deb-src http://archive.ubuntu.com/ubuntu focal universe
  597. deb http://archive.ubuntu.com/ubuntu focal-updates universe
  598. # deb-src http://archive.ubuntu.com/ubuntu focal-updates universe
  599. deb http://ubuntu.mirror.constant.com focal universe
  600. # deb-src http://ubuntu.mirror.constant.com focal universe
  601. deb http://ubuntu.mirror.constant.com focal-updates universe
  602. # deb-src http://ubuntu.mirror.constant.com focal-updates universe
  603. deb http://archive.ubuntu.com/ubuntu focal multiverse
  604. # deb-src http://archive.ubuntu.com/ubuntu focal multiverse
  605. deb http://archive.ubuntu.com/ubuntu focal-updates multiverse
  606. # deb-src http://archive.ubuntu.com/ubuntu focal-updates multiverse
  607. deb http://ubuntu.mirror.constant.com focal multiverse
  608. # deb-src http://ubuntu.mirror.constant.com focal multiverse
  609. deb http://ubuntu.mirror.constant.com focal-updates multiverse
  610. # deb-src http://ubuntu.mirror.constant.com focal-updates multiverse
  611. deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
  612. # deb-src http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
  613. deb http://ubuntu.mirror.constant.com focal-backports main restricted universe multiverse
  614. # deb-src http://ubuntu.mirror.constant.com focal-backports main restricted universe multiverse
  615. deb http://archive.ubuntu.com/ubuntu focal-security main restricted
  616. # deb-src http://archive.ubuntu.com/ubuntu focal-security main restricted
  617. deb http://archive.ubuntu.com/ubuntu focal-security universe
  618. # deb-src http://archive.ubuntu.com/ubuntu focal-security universe
  619. deb http://archive.ubuntu.com/ubuntu focal-security multiverse
  620. # deb-src http://archive.ubuntu.com/ubuntu focal-security multiverse
  621. deb http://ubuntu.mirror.constant.com focal-security main restricted
  622. # deb-src http://ubuntu.mirror.constant.com focal-security main restricted
  623. deb http://ubuntu.mirror.constant.com focal-security universe
  624. # deb-src http://ubuntu.mirror.constant.com focal-security universe
  625. deb http://ubuntu.mirror.constant.com focal-security multiverse
  626. # deb-src http://ubuntu.mirror.constant.com focal-security multiverse
  627. EOF
  628. }
  629. Ubuntu_22_sources () {
  630. cat > /etc/apt/sources.list << EOF
  631. deb http://archive.ubuntu.com/ubuntu jammy main restricted
  632. # deb-src http://archive.ubuntu.com/ubuntu jammy main restricted
  633. deb http://ubuntu.mirror.constant.com jammy main restricted
  634. # deb-src http://ubuntu.mirror.constant.com jammy main restricted
  635. deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted
  636. # deb-src http://archive.ubuntu.com/ubuntu jammy-updates main restricted
  637. deb http://ubuntu.mirror.constant.com jammy-updates main restricted
  638. # deb-src http://ubuntu.mirror.constant.com jammy-updates main restricted
  639. deb http://archive.ubuntu.com/ubuntu jammy universe
  640. # deb-src http://archive.ubuntu.com/ubuntu jammy universe
  641. deb http://archive.ubuntu.com/ubuntu jammy-updates universe
  642. # deb-src http://archive.ubuntu.com/ubuntu jammy-updates universe
  643. deb http://ubuntu.mirror.constant.com jammy universe
  644. # deb-src http://ubuntu.mirror.constant.com jammy universe
  645. deb http://ubuntu.mirror.constant.com jammy-updates universe
  646. # deb-src http://ubuntu.mirror.constant.com jammy-updates universe
  647. deb http://archive.ubuntu.com/ubuntu jammy multiverse
  648. # deb-src http://archive.ubuntu.com/ubuntu jammy multiverse
  649. deb http://archive.ubuntu.com/ubuntu jammy-updates multiverse
  650. # deb-src http://archive.ubuntu.com/ubuntu jammy-updates multiverse
  651. deb http://ubuntu.mirror.constant.com jammy multiverse
  652. # deb-src http://ubuntu.mirror.constant.com jammy multiverse
  653. deb http://ubuntu.mirror.constant.com jammy-updates multiverse
  654. # deb-src http://ubuntu.mirror.constant.com jammy-updates multiverse
  655. deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
  656. # deb-src http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
  657. deb http://ubuntu.mirror.constant.com jammy-backports main restricted universe multiverse
  658. # deb-src http://ubuntu.mirror.constant.com jammy-backports main restricted universe multiverse
  659. deb http://archive.ubuntu.com/ubuntu jammy-security main restricted
  660. # deb-src http://archive.ubuntu.com/ubuntu jammy-security main restricted
  661. deb http://archive.ubuntu.com/ubuntu jammy-security universe
  662. # deb-src http://archive.ubuntu.com/ubuntu jammy-security universe
  663. deb http://archive.ubuntu.com/ubuntu jammy-security multiverse
  664. # deb-src http://archive.ubuntu.com/ubuntu jammy-security multiverse
  665. deb http://ubuntu.mirror.constant.com jammy-security main restricted
  666. # deb-src http://ubuntu.mirror.constant.com jammy-security main restricted
  667. deb http://ubuntu.mirror.constant.com jammy-security universe
  668. # deb-src http://ubuntu.mirror.constant.com jammy-security universe
  669. deb http://ubuntu.mirror.constant.com jammy-security multiverse
  670. # deb-src http://ubuntu.mirror.constant.com jammy-security multiverse
  671. EOF
  672. }
  673. Ubuntu_24_sources () {
  674. cat > /etc/apt/sources.list << EOF
  675. deb http://archive.ubuntu.com/ubuntu noble main restricted
  676. # deb-src http://archive.ubuntu.com/ubuntu noble main restricted
  677. deb http://ubuntu.mirror.constant.com noble main restricted
  678. # deb-src http://ubuntu.mirror.constant.com noble main restricted
  679. deb http://archive.ubuntu.com/ubuntu noble-updates main restricted
  680. # deb-src http://archive.ubuntu.com/ubuntu noble-updates main restricted
  681. deb http://ubuntu.mirror.constant.com noble-updates main restricted
  682. # deb-src http://ubuntu.mirror.constant.com noble-updates main restricted
  683. deb http://archive.ubuntu.com/ubuntu noble universe
  684. # deb-src http://archive.ubuntu.com/ubuntu noble universe
  685. deb http://archive.ubuntu.com/ubuntu noble-updates universe
  686. # deb-src http://archive.ubuntu.com/ubuntu noble-updates universe
  687. deb http://ubuntu.mirror.constant.com noble universe
  688. # deb-src http://ubuntu.mirror.constant.com noble universe
  689. deb http://ubuntu.mirror.constant.com noble-updates universe
  690. # deb-src http://ubuntu.mirror.constant.com noble-updates universe
  691. deb http://archive.ubuntu.com/ubuntu noble multiverse
  692. # deb-src http://archive.ubuntu.com/ubuntu noble multiverse
  693. deb http://archive.ubuntu.com/ubuntu noble-updates multiverse
  694. # deb-src http://archive.ubuntu.com/ubuntu noble-updates multiverse
  695. deb http://ubuntu.mirror.constant.com noble multiverse
  696. # deb-src http://ubuntu.mirror.constant.com noble multiverse
  697. deb http://ubuntu.mirror.constant.com noble-updates multiverse
  698. # deb-src http://ubuntu.mirror.constant.com noble-updates multiverse
  699. deb http://archive.ubuntu.com/ubuntu noble-backports main restricted universe multiverse
  700. # deb-src http://archive.ubuntu.com/ubuntu noble-backports main restricted universe multiverse
  701. deb http://ubuntu.mirror.constant.com noble-backports main restricted universe multiverse
  702. # deb-src http://ubuntu.mirror.constant.com noble-backports main restricted universe multiverse
  703. deb http://archive.ubuntu.com/ubuntu noble-security main restricted
  704. # deb-src http://archive.ubuntu.com/ubuntu noble-security main restricted
  705. deb http://archive.ubuntu.com/ubuntu noble-security universe
  706. # deb-src http://archive.ubuntu.com/ubuntu noble-security universe
  707. deb http://archive.ubuntu.com/ubuntu noble-security multiverse
  708. # deb-src http://archive.ubuntu.com/ubuntu noble-security multiverse
  709. deb http://ubuntu.mirror.constant.com noble-security main restricted
  710. # deb-src http://ubuntu.mirror.constant.com noble-security main restricted
  711. deb http://ubuntu.mirror.constant.com noble-security universe
  712. # deb-src http://ubuntu.mirror.constant.com noble-security universe
  713. deb http://ubuntu.mirror.constant.com noble-security multiverse
  714. # deb-src http://ubuntu.mirror.constant.com noble-security multiverse
  715. EOF
  716. }
  717. Debian_11_sources () {
  718. cat > /etc/apt/sources.list << EOF
  719. deb https://deb.debian.org/debian bullseye main contrib non-free
  720. deb-src https://deb.debian.org/debian bullseye main contrib non-free
  721. deb https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
  722. deb-src https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
  723. deb https://deb.debian.org/debian bullseye-updates main contrib non-free
  724. deb-src https://deb.debian.org/debian bullseye-updates main contrib non-free
  725. #deb https://deb.debian.org/debian bullseye-backports main contrib non-free
  726. #deb-src https://deb.debian.org/debian bullseye-backports main contrib non-free
  727. deb https://debian.mirror.constant.com bullseye main contrib non-free
  728. deb-src https://debian.mirror.constant.com bullseye main contrib non-free
  729. EOF
  730. }
  731. Debian_12_sources () {
  732. cat > /etc/apt/sources.list << EOF
  733. deb https://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
  734. deb-src https://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
  735. deb https://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
  736. deb-src https://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
  737. deb https://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
  738. deb-src https://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
  739. #deb https://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware
  740. #deb-src https://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware
  741. deb https://debian.mirror.constant.com bookworm main contrib non-free non-free-firmware
  742. deb-src https://debian.mirror.constant.com bookworm main contrib non-free non-free-firmware
  743. EOF
  744. }
  745. Change_sources () {
  746. if [ -s /etc/os-release ] && [ -s /etc/issue ]; then
  747. . /etc/os-release
  748. echo "detected OS: $ID - $VERSION_ID"
  749. UD_os_version=$(cat /etc/issue | grep Ubuntu | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
  750. OS_v=Ubuntu
  751. if [ "${UD_os_version}" = "" ]; then
  752. OS_v=Debian
  753. UD_os_version=$(cat /etc/issue | grep Debian | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '[0-9]+')
  754. if [ "${UD_os_version}" = "" ]; then
  755. UD_os_version=$(cat /etc/issue | grep Debian | grep -Eo '[0-9]+')
  756. fi
  757. fi
  758. echo "detected OS version: $OS_v $UD_os_version"
  759. if [ $ID == "debian" ] && [ $OS_v == "Debian" ]; then
  760. if [ $VERSION_ID == "11" ] && [ $UD_os_version == "11" ]; then
  761. Debian_11_sources
  762. elif [ $VERSION_ID == "12" ] && [ $UD_os_version == "12" ]; then
  763. Debian_12_sources
  764. else
  765. echo -e "\033[31mSorry: $OS_v $UD_os_version This system does not support changing apt source, please try to change it yourself. \033[0m"
  766. Change_apt_sources="no"
  767. fi
  768. elif [ $ID == "ubuntu" ] && [ $OS_v == "Ubuntu" ]; then
  769. if [ `echo "$VERSION_ID" | cut -b-2 ` == "20" ] && [ $UD_os_version == "20" ]; then
  770. Ubuntu_20_sources
  771. elif [ `echo "$VERSION_ID" | cut -b-2 ` == "22" ] && [ $UD_os_version == "22" ]; then
  772. Ubuntu_22_sources
  773. elif [ `echo "$VERSION_ID" | cut -b-2 ` == "24" ] && [ $UD_os_version == "24" ]; then
  774. Ubuntu_24_sources
  775. else
  776. echo -e "\033[31mSorry: $OS_v $UD_os_version This system does not support changing apt source, please try to change it yourself. \033[0m"
  777. Change_apt_sources="no"
  778. fi
  779. else
  780. echo -e "\033[31mSorry: $OS_v $UD_os_version This system does not support changing apt source, please try to change it yourself. \033[0m"
  781. Change_apt_sources="no"
  782. fi
  783. fi
  784. }
  785. Check_Change_official_sources () {
  786. if [ -s /etc/apt/sources.list ]; then
  787. ubuntu_sources=$(grep "\.ubuntu\.com" /etc/apt/sources.list | grep -v '^#' | grep -v "security\.ubuntu\.com")
  788. debian_sources=$(grep "\.debian\.org" /etc/apt/sources.list | grep -v '^#' | grep -v "security\.debian\.org")
  789. if [ "$ubuntu_sources" = "" ] && [ "$debian_sources" = "" ]; then
  790. while [ "$yes2" != 'yes' ] && [ "$yes2" != 'no' ]; do
  791. read -p "Found that apt source cannot be used. Do need to change it to the official source? [yes/no] " yes2
  792. done
  793. if [ "$yes2" = "yes" ]; then
  794. Backup_sources_time=$(date +%Y_%m_%d_%H_%M_%S)
  795. cp -arpf /etc/apt/sources.list /etc/apt/sources.list_aapanel_${Backup_sources_time}
  796. echo -e "The sources.list file has been backup. The backup file name is:\033[31m /etc/apt/sources.list_aapanel_${Backup_sources_time} \033[0m"
  797. Change_sources
  798. if [ "${Change_apt_sources}" != "no" ]; then
  799. Install_Deb_Pack
  800. fi
  801. fi
  802. fi
  803. fi
  804. }
  805. Check_Install_Sys_Packs() {
  806. echo "Checking necessary dependency system packages"
  807. # Define functions for installation packages
  808. install_package() {
  809. local package=$1
  810. if [ "${PM}" = "yum" ]; then
  811. yum install "$package" -y
  812. elif [ "${PM}" = "apt-get" ]; then
  813. dpkg --configure -a
  814. apt-get update
  815. apt-get install "$package" -y
  816. fi
  817. }
  818. # Define a function to install and verify
  819. install_and_verify() {
  820. local package_name=$1
  821. local command_name=$2
  822. # First try installing directly
  823. if ! Command_Exists "$command_name"; then
  824. install_package "$package_name"
  825. fi
  826. # try change official sources
  827. if [ ! -f "/usr/bin/$command_name" ] && [ ! -f "/bin/$command_name" ] && ! Command_Exists "$command_name"; then
  828. Check_Change_official_sources
  829. fi
  830. # Check again, if it is still missing, an error message will be reported.
  831. if [ ! -f "/usr/bin/$command_name" ] && [ ! -f "/bin/$command_name" ] && ! Command_Exists "$command_name"; then
  832. echo -e "\033[31mERROR: "$command_name" command does not exist, try the following solutions:\033[0m"
  833. echo -e "1. Use command reinstall dependent packages: \033[31m ${PM} reinstall -y $package_name \033[0m"
  834. echo -e "2. Check if system source is available? Try changing available system sources"
  835. echo -e "After solving the above problems, please try to reinstall!"
  836. if [ -s /etc/apt/sources.list ]; then
  837. Vive_source=$(grep -v '^#' /etc/apt/sources.list | grep -Ev "^\s*$|security\.ubuntu\.com|security\.debian\.org" | head -n 1)
  838. Vive_source="apt source: $Vive_source"
  839. # echo "$Vive_source"
  840. fi
  841. Red_Error "Error: $command_name command not found, please install $package_name command. $Vive_source"
  842. fi
  843. }
  844. # Install and check unzip
  845. install_and_verify "unzip" "unzip"
  846. # Install and check tar
  847. install_and_verify "tar" "tar"
  848. # Install and check wget
  849. install_and_verify "wget" "wget"
  850. }
  851. Get_Versions() {
  852. redhat_version_file="/etc/redhat-release"
  853. deb_version_file="/etc/issue"
  854. if [[ $(grep "Amazon Linux" /etc/os-release) ]]; then
  855. os_type="Amazon-"
  856. os_version=$(cat /etc/os-release | grep "Amazon Linux" | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
  857. yum install cronie -y
  858. return
  859. fi
  860. if [[ $(grep OpenCloudOS /etc/os-release) ]]; then
  861. os_type="OpenCloudOS-"
  862. os_version=$(cat /etc/os-release | grep OpenCloudOS | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
  863. if [[ $os_version == "7" ]]; then
  864. os_type="el"
  865. os_version="7"
  866. fi
  867. return
  868. fi
  869. if [[ $(grep "Linux Mint" $deb_version_file) ]]; then
  870. os_version=$(cat $deb_version_file | grep "Linux Mint" | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
  871. if [ "${os_version}" = "" ]; then
  872. os_version=$(cat $deb_version_file | grep "Linux Mint" | grep -Eo '[0-9]+')
  873. fi
  874. # Linux-Mint 使用 ubuntu pyenv
  875. os_type='ubuntu'
  876. if [[ "$os_version" =~ "21" ]]; then
  877. os_version="22"
  878. echo "$os_version"
  879. fi
  880. if [[ "$os_version" =~ "20" ]]; then
  881. os_version="20"
  882. echo "$os_version"
  883. fi
  884. return
  885. fi
  886. if [[ $(grep openEuler /etc/os-release) ]]; then
  887. os_type="openEuler-"
  888. os_version=$(cat /etc/os-release | grep openEuler | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
  889. return
  890. fi
  891. if [[ $(grep AlmaLinux /etc/os-release) ]]; then
  892. os_type="Alma-"
  893. os_version=$(cat /etc/os-release | grep AlmaLinux | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
  894. return
  895. fi
  896. if [[ $(grep Rocky /etc/os-release) ]]; then
  897. os_type="Rocky-"
  898. os_version=$(cat /etc/os-release | grep Rocky | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
  899. return
  900. fi
  901. if [[ $(grep Anolis /etc/os-release) ]] && [[ $(grep VERSION /etc/os-release|grep 8.8) ]];then
  902. if [ -f "/usr/bin/yum" ];then
  903. os_type="anolis"
  904. os_version="8"
  905. return
  906. fi
  907. fi
  908. if [ -s $redhat_version_file ]; then
  909. os_type='el'
  910. if [[ $(grep 'Alibaba Cloud Linux (Aliyun Linux) release 2' $redhat_version_file) ]]; then
  911. os_version="7"
  912. return
  913. fi
  914. is_aliyunos=$(cat $redhat_version_file | grep Aliyun)
  915. if [ "$is_aliyunos" != "" ]; then
  916. return
  917. fi
  918. if [[ $(grep "Red Hat" $redhat_version_file) ]]; then
  919. os_type='el'
  920. os_version=$(cat $redhat_version_file | grep "Red Hat" | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]')
  921. return
  922. fi
  923. if [[ $(grep "Alibaba Cloud Linux release 3 " /etc/redhat-release) ]]; then
  924. os_type="ali-linux-"
  925. os_version="3"
  926. return
  927. fi
  928. if [[ $(grep "Alibaba Cloud" /etc/redhat-release) ]] && [[ $(grep al8 /etc/os-release) ]];then
  929. os_type="ali-linux-"
  930. os_version="al8"
  931. return
  932. fi
  933. if [[ $(grep TencentOS /etc/redhat-release) ]]; then
  934. os_type="TencentOS-"
  935. os_version=$(cat /etc/redhat-release | grep TencentOS | grep -Eo '([0-9]+\.)+[0-9]+')
  936. if [[ $os_version == "2.4" ]]; then
  937. os_type="el"
  938. os_version="7"
  939. elif [[ $os_version == "3.1" ]]; then
  940. os_version="3.1"
  941. fi
  942. return
  943. fi
  944. os_version=$(cat $redhat_version_file | grep CentOS | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]')
  945. if [ "${os_version}" = "5" ]; then
  946. os_version=""
  947. fi
  948. if [ -z "${os_version}" ]; then
  949. os_version=$(cat /etc/redhat-release | grep Stream | grep -oE "8|9")
  950. fi
  951. else
  952. os_type='ubuntu'
  953. os_version=$(cat $deb_version_file | grep Ubuntu | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '^[0-9]+')
  954. if [ "${os_version}" = "" ]; then
  955. os_type='debian'
  956. os_version=$(cat $deb_version_file | grep Debian | grep -Eo '([0-9]+\.)+[0-9]+' | grep -Eo '[0-9]+')
  957. if [ "${os_version}" = "" ]; then
  958. os_version=$(cat $deb_version_file | grep Debian | grep -Eo '[0-9]+')
  959. fi
  960. if [ "${os_version}" = "8" ]; then
  961. os_version=""
  962. fi
  963. if [ "${is64bit}" = '32' ]; then
  964. os_version=""
  965. fi
  966. else
  967. if [ "$os_version" = "14" ]; then
  968. os_version=""
  969. fi
  970. if [ "$os_version" = "12" ]; then
  971. os_version=""
  972. fi
  973. if [ "$os_version" = "19" ]; then
  974. os_version=""
  975. fi
  976. if [ "$os_version" = "21" ]; then
  977. os_version=""
  978. fi
  979. if [ "$os_version" = "20" ]; then
  980. os_version2004=$(cat /etc/issue | grep 20.04)
  981. if [ -z "${os_version2004}" ]; then
  982. os_version=""
  983. fi
  984. fi
  985. fi
  986. fi
  987. }
  988. Install_Openssl111(){
  989. Get_Versions
  990. if [ -f "/www/server/panel/openssl_make.pl" ]; then
  991. # 存在时编译
  992. openssl_make="yes"
  993. rm -f /www/server/panel/openssl_make.pl
  994. fi
  995. CPU_arch=$(uname -m)
  996. if [ "${CPU_arch}" == "aarch64" ];then
  997. CPU_arch="-aarch64"
  998. elif [ "${CPU_arch}" == "x86_64" ];then
  999. # x86_64 默认为空
  1000. CPU_arch=""
  1001. else
  1002. openssl_make="yes"
  1003. fi
  1004. if [[ $os_type = "el" ]] && [[ $os_version == "7" ]] && [[ $openssl_make != "yes" ]]; then
  1005. wget --no-check-certificate -O openssl111.tar.gz ${download_Url}/install/src/openssl111${CPU_arch}.tar.gz -t 5 -T 20
  1006. tmp_size=$(du -b openssl111.tar.gz | awk '{print $1}')
  1007. if [ $tmp_size -lt 5014046 ]; then
  1008. rm -f openssl111.tar.gz
  1009. Red_Error "ERROR: Download openssl111.tar.gz fielded."
  1010. fi
  1011. tar zxvf openssl111.tar.gz -C /usr/local/
  1012. rm -f openssl111.tar.gz
  1013. if [ ! -f "/usr/local/openssl111/bin/openssl" ];then
  1014. Red_Error "/usr/local/openssl111/bin/openssl file does not exist!"
  1015. fi
  1016. export LD_LIBRARY_PATH=/usr/local/openssl111/lib:$LD_LIBRARY_PATH
  1017. echo "/usr/local/openssl111/lib" > /etc/ld.so.conf.d/zopenssl111.conf
  1018. ldconfig
  1019. else
  1020. if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
  1021. yum install -y perl lksctp-tools-devel
  1022. else
  1023. apt install -y perl
  1024. fi
  1025. opensslVersion="1.1.1o"
  1026. wget --no-check-certificate -O openssl-${opensslVersion}.tar.gz ${download_Url}/src/openssl-${opensslVersion}.tar.gz -t 5 -T 20
  1027. tmp_size=$(du -b openssl-${opensslVersion}.tar.gz | awk '{print $1}')
  1028. if [ $tmp_size -lt 9056386 ]; then
  1029. rm -f openssl-${opensslVersion}.tar.gz
  1030. Red_Error "ERROR: Download openssl-${opensslVersion}.tar.gz fielded."
  1031. fi
  1032. tar -zxvf openssl-${opensslVersion}.tar.gz
  1033. if [ ! -d "openssl-${opensslVersion}" ];then
  1034. Red_Error "Decompression failed openssl-${opensslVersion} Directory does not exist!"
  1035. fi
  1036. cd openssl-${opensslVersion}
  1037. ./config --prefix=/usr/local/openssl111 --openssldir=/usr/local/openssl111 enable-md2 enable-rc5 sctp zlib-dynamic shared -fPIC
  1038. make -j$cpu_cpunt
  1039. make install
  1040. if [ ! -f "/usr/local/openssl111/bin/openssl" ];then
  1041. Red_Error "Compilation failed /usr/local/openssl111/bin/openssl file does not exist!"
  1042. fi
  1043. export LD_LIBRARY_PATH=/usr/local/openssl111/lib:$LD_LIBRARY_PATH
  1044. echo "/usr/local/openssl111/lib" > /etc/ld.so.conf.d/zopenssl111.conf
  1045. ldconfig
  1046. cd ..
  1047. rm -rf openssl-${opensslVersion} openssl-${opensslVersion}.tar.gz
  1048. fi
  1049. openssl111Check=$(/usr/local/openssl111/bin/openssl version|grep 1.1.1)
  1050. if [ -z "${openssl111Check}" ];then
  1051. Red_Error "openssl-1.1.1 install failed!"
  1052. fi
  1053. }
  1054. Update_Py_Lib(){
  1055. # Need to use Werkzeug 2.2.3
  1056. mypip="/www/server/panel/pyenv/bin/pip3"
  1057. Werkzeug_path="/www/server/panel/script/Werkzeug-2.2.3-py3-none-any.whl"
  1058. pycountry_path="/www/server/panel/script/pycountry-24.6.1-py3-none-any.whl"
  1059. # pyOpenSSL_path="/www/server/panel/script/pyOpenSSL-23.1.1-py3-none-any.whl"
  1060. change_pip_package_list=$( $mypip list | grep -E "Werkzeug|lxml|pycountry" )
  1061. #change_pip_package_list=$( $mypip list | grep -E "Werkzeug|lxml" )
  1062. Werkzeug_v=$(echo "$change_pip_package_list" | grep Werkzeug | grep 2.2.3)
  1063. if [ "$Werkzeug_v" = "" ];then
  1064. echo "Update Werkzeug"
  1065. $mypip uninstall Werkzeug -y
  1066. $mypip install $Werkzeug_path
  1067. Werkzeug_v_2=$($mypip list |grep Werkzeug | grep 2.2.3)
  1068. if [ "$Werkzeug_v_2" = "" ];then
  1069. $mypip install Werkzeug==2.2.3
  1070. fi
  1071. fi
  1072. pycountry_v=$(echo "$change_pip_package_list" | grep pycountry)
  1073. if [ "$pycountry_v" = "" ];then
  1074. echo "Update pycountry"
  1075. $mypip install $pycountry_path
  1076. rm -f $pycountry_path
  1077. pycountry_v_2=$($mypip list |grep pycountry)
  1078. if [ "$pycountry_v_2" = "" ];then
  1079. $mypip install pycountry
  1080. fi
  1081. fi
  1082. # pyOpenSSL_v=$(echo "$change_pip_package_list" | grep pyOpenSSL | grep 23.1.1)
  1083. # if [ "$pyOpenSSL_v" = "" ];then
  1084. # echo "Update pyOpenSSL"
  1085. # $mypip uninstall pyOpenSSL cryptography -y
  1086. # $mypip install $pyOpenSSL_path cryptography==40.0.2
  1087. # pyOpenSSL_v_2=$($mypip list |grep pyOpenSSL | grep 23.1.1)
  1088. # if [ "$pyOpenSSL_v_2" = "" ];then
  1089. # $mypip install pyOpenSSL==23.1.1 cryptography==40.0.2
  1090. # fi
  1091. # fi
  1092. lxml_v=$(echo "$change_pip_package_list" | grep lxml | grep 5.2.1)
  1093. if [ "$lxml_v" != "" ];then
  1094. echo "Update lxml"
  1095. $mypip uninstall lxml -y
  1096. # bt 16 升级脚本时安装,安装时间久 这里不开,下面进行处理了
  1097. # echo "Please wait a moment to install lxml, it will take a long time."
  1098. # $mypip install lxml==5.0.0
  1099. # lxml_v_2=$($mypip list |grep lxml | grep 5.2.1)
  1100. # if [ "$lxml_v_2" = "" ];then
  1101. # $mypip install lxml==5.0.0
  1102. # fi
  1103. fi
  1104. }
  1105. Check_PIP_Packages(){
  1106. mypip="/www/server/panel/pyenv/bin/pip3"
  1107. show_pip_list_panel="/tmp/show_pip_list_panel.txt"
  1108. trusted_host="--trusted-host mirrors.tencent.com --trusted-host pypi.doubanio.com --trusted-host mirrors.aliyun.com --trusted-host pypi.tuna.tsinghua.edu.cn --trusted-host pypi.org"
  1109. echo "Check pip package, please wait..."
  1110. ${mypip} list | awk '{print $1}' > ${show_pip_list_panel}
  1111. check_pip_packs="/www/server/panel/check-pip-packs.txt"
  1112. if [ ! -s "${check_pip_packs}" ]; then
  1113. check_pip_packs="/tmp/check-pip-packs_3.12.txt"
  1114. wget --no-check-certificate -O ${check_pip_packs} ${download_Url}/install/pyenv/3.12/check-pip-packs_3.12.txt -t 5 -T 20
  1115. fi
  1116. Install_PIP_PACKS_File="/www/server/panel/requirements.txt"
  1117. if [ ! -s "${Install_PIP_PACKS_File}" ]; then
  1118. Install_PIP_PACKS_File="/tmp/pip_en_3.12.txt"
  1119. wget --no-check-certificate -O ${Install_PIP_PACKS_File} ${download_Url}/install/pyenv/3.12/pip_en_3.12.txt -t 5 -T 20
  1120. fi
  1121. PIP_PACKS=$(cat ${check_pip_packs} )
  1122. for ONE_PACK in ${PIP_PACKS};
  1123. do
  1124. Install_PIP_PACKS=`grep "^${ONE_PACK}==" ${Install_PIP_PACKS_File}`
  1125. if [ -z "${Install_PIP_PACKS}" ]; then
  1126. Install_PIP_PACKS=${ONE_PACK}
  1127. fi
  1128. Show_PIP_PACK=`grep "^${ONE_PACK}\$" ${show_pip_list_panel}`
  1129. # echo ${Show_PIP_PACK}
  1130. if [ -z "${Show_PIP_PACK}" ];then
  1131. if [[ "${ONE_PACK}" == "aliyun-python-sdk-kms" || "${ONE_PACK}" == "aliyun-python-sdk-core" || "${ONE_PACK}" == "aliyun-python-sdk-core-v3" || "${ONE_PACK}" == "qiniu" || "${ONE_PACK}" == "cos-python-sdk-v5" ]]; then
  1132. echo "Install packages: ${Install_PIP_PACKS}" >/dev/null 2>&1
  1133. else
  1134. echo "Install packages: ${Install_PIP_PACKS}"
  1135. fi
  1136. if [[ "${ONE_PACK}" == "Flask" ]]; then
  1137. ${mypip} uninstall Flask Werkzeug -y
  1138. ${mypip} install Flask==2.2.5 Werkzeug==2.2.3 ${trusted_host}
  1139. elif [[ "${ONE_PACK}" == "Werkzeug" ]]; then
  1140. ${mypip} install Werkzeug==2.2.3 ${trusted_host}
  1141. elif [[ "${ONE_PACK}" == "aliyun-python-sdk-kms" || "${ONE_PACK}" == "aliyun-python-sdk-core" || "${ONE_PACK}" == "aliyun-python-sdk-core-v3" || "${ONE_PACK}" == "qiniu" || "${ONE_PACK}" == "cos-python-sdk-v5" ]]; then
  1142. echo "${Install_PIP_PACKS} ..." >/dev/null 2>&1
  1143. else
  1144. ${mypip} install ${Install_PIP_PACKS} ${trusted_host}
  1145. fi
  1146. fi
  1147. done
  1148. }
  1149. Install_Python_Lib() {
  1150. # openssl 版本低于1.1.1 需要安装 如CentOS 7
  1151. OPENSSL_VER=$(openssl version|grep -oE '1.0|1.1.0')
  1152. if [ "${OPENSSL_VER}" ]; then
  1153. if [ ! -f "/usr/local/openssl111/bin/openssl" ]; then
  1154. Install_Openssl111
  1155. else
  1156. export LD_LIBRARY_PATH=/usr/local/openssl111/lib:$LD_LIBRARY_PATH
  1157. openssl111Check=$(/usr/local/openssl111/bin/openssl version|grep 1.1.1)
  1158. if [ -z "${openssl111Check}" ];then
  1159. Install_Openssl111
  1160. fi
  1161. if [ ! -f "/etc/ld.so.conf.d/openssl111.conf" ] || [ ! -f "/etc/ld.so.conf.d/zopenssl111.conf" ]; then
  1162. echo "/usr/local/openssl111/lib" > /etc/ld.so.conf.d/zopenssl111.conf
  1163. ldconfig
  1164. fi
  1165. fi
  1166. Use_Openssl111="yes"
  1167. fi
  1168. curl -sSk --connect-timeout 5 -m 60 $download_Url/install/pip_select.sh | bash
  1169. pyenv_path="/www/server/panel"
  1170. if [ -f $pyenv_path/pyenv/bin/python ]; then
  1171. is_ssl=$($python_bin -c "import ssl" 2>&1 | grep cannot)
  1172. $pyenv_path/pyenv/bin/python3.12 -V
  1173. if [ $? -eq 0 ] && [ -z "${is_ssl}" ]; then
  1174. chmod -R 700 $pyenv_path/pyenv/bin
  1175. is_package=$($python_bin -m psutil 2>&1 | grep package)
  1176. if [ "$is_package" = "" ]; then
  1177. wget --no-check-certificate -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/3.12/pip_en_3.12.txt -t 5 -T 20
  1178. $pyenv_path/pyenv/bin/pip install -U pip
  1179. $pyenv_path/pyenv/bin/pip install -U setuptools
  1180. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  1181. fi
  1182. source $pyenv_path/pyenv/bin/activate
  1183. chmod -R 700 $pyenv_path/pyenv/bin
  1184. return
  1185. else
  1186. rm -rf $pyenv_path/pyenv
  1187. fi
  1188. fi
  1189. is_loongarch64=$(uname -a | grep loongarch64)
  1190. if [ "$is_loongarch64" != "" ] && [ -f "/usr/bin/yum" ]; then
  1191. yumPacks="python3-devel python3-pip python3-psutil python3-gevent python3-pyOpenSSL python3-paramiko python3-flask python3-rsa python3-requests python3-six python3-websocket-client"
  1192. yum install -y ${yumPacks}
  1193. for yumPack in ${yumPacks}; do
  1194. rpmPack=$(rpm -q ${yumPack})
  1195. packCheck=$(echo ${rpmPack} | grep not)
  1196. if [ "${packCheck}" ]; then
  1197. yum install ${yumPack} -y
  1198. fi
  1199. done
  1200. pip3 install -U pip
  1201. pip3 install Pillow psutil pyinotify pycryptodome upyun oss2 pymysql qrcode qiniu redis pymongo Cython configparser cos-python-sdk-v5 supervisor gevent-websocket pyopenssl
  1202. pip3 install flask==1.1.4
  1203. pip3 install Pillow -U
  1204. pyenv_bin=/www/server/panel/pyenv/bin
  1205. mkdir -p $pyenv_bin
  1206. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip
  1207. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3
  1208. ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3.7
  1209. if [ -f "/usr/bin/python3.7" ]; then
  1210. ln -sf /usr/bin/python3.7 $pyenv_bin/python
  1211. ln -sf /usr/bin/python3.7 $pyenv_bin/python3
  1212. ln -sf /usr/bin/python3.7 $pyenv_bin/python3.7
  1213. elif [ -f "/usr/bin/python3.6" ]; then
  1214. ln -sf /usr/bin/python3.6 $pyenv_bin/python
  1215. ln -sf /usr/bin/python3.6 $pyenv_bin/python3
  1216. ln -sf /usr/bin/python3.6 $pyenv_bin/python3.7
  1217. fi
  1218. echo >$pyenv_bin/activate
  1219. return
  1220. fi
  1221. py_version="3.12.3"
  1222. python_version="-3.12"
  1223. mkdir -p $pyenv_path
  1224. echo "True" >/www/disk.pl
  1225. if [ ! -w /www/disk.pl ]; then
  1226. Red_Error "ERROR: Install python env fielded." "ERROR: path [www] cannot be written, please check the directory/user/disk permissions!"
  1227. fi
  1228. os_type='el'
  1229. os_version='7'
  1230. is_export_openssl=0
  1231. Get_Versions
  1232. echo "OS: $os_type - $os_version"
  1233. is_aarch64=$(uname -m | grep aarch64)
  1234. if [ "$is_aarch64" != "" ]; then
  1235. is64bit="aarch64"
  1236. fi
  1237. if [ -f "/www/server/panel/pymake.pl" ]; then
  1238. os_version=""
  1239. rm -f /www/server/panel/pymake.pl
  1240. fi
  1241. if [ "${os_version}" != "" ]; then
  1242. pyenv_file="/www/pyenv.tar.gz"
  1243. wget --no-check-certificate -O $pyenv_file $download_Url/install/pyenv/3.12/pyenv-${os_type}${os_version}-x${is64bit}${python_version}.tar.gz -t 5 -T 20
  1244. if [ "$?" != "0" ];then
  1245. get_node_url $download_Url
  1246. wget --no-check-certificate -O $pyenv_file $download_Url/install/pyenv/3.12/pyenv-${os_type}${os_version}-x${is64bit}${python_version}.tar.gz -t 5 -T 20
  1247. fi
  1248. tmp_size=$(du -b $pyenv_file | awk '{print $1}')
  1249. if [ $tmp_size -lt 122271175 ]; then
  1250. rm -f $pyenv_file
  1251. echo "ERROR: Download python env fielded."
  1252. else
  1253. echo "Install python env..."
  1254. tar zxvf $pyenv_file -C $pyenv_path/ >/dev/null
  1255. chmod -R 700 $pyenv_path/pyenv/bin
  1256. if [ ! -f $pyenv_path/pyenv/bin/python ]; then
  1257. rm -f $pyenv_file
  1258. Red_Error "ERROR: Install python env fielded. Please try to reinstall"
  1259. fi
  1260. $pyenv_path/pyenv/bin/python3.12 -V
  1261. if [ $? -eq 0 ]; then
  1262. rm -f $pyenv_file
  1263. ln -sf $pyenv_path/pyenv/bin/pip3.12 /usr/bin/btpip
  1264. ln -sf $pyenv_path/pyenv/bin/python3.12 /usr/bin/btpython
  1265. source $pyenv_path/pyenv/bin/activate
  1266. return
  1267. else
  1268. rm -f $pyenv_file
  1269. rm -rf $pyenv_path/pyenv
  1270. fi
  1271. fi
  1272. fi
  1273. cd /www
  1274. python_src='/www/python_src.tar.xz'
  1275. python_src_path="/www/Python-${py_version}"
  1276. wget --no-check-certificate -O $python_src $download_Url/src/Python-${py_version}.tar.xz -t 5 -T 20
  1277. tmp_size=$(du -b $python_src | awk '{print $1}')
  1278. if [ $tmp_size -lt 10703460 ]; then
  1279. rm -f $python_src
  1280. Red_Error "ERROR: Download python source code fielded. Please try to reinstall OS_${os_type}_${os_version}."
  1281. fi
  1282. tar xvf $python_src
  1283. rm -f $python_src
  1284. cd $python_src_path
  1285. if [[ $Use_Openssl111 = "yes" ]]; then
  1286. # centos7 或者低openssl于1.1.1使用
  1287. export OPENSSL_DIR=/usr/local/openssl111
  1288. ./configure --prefix=$pyenv_path/pyenv \
  1289. LDFLAGS="-L$OPENSSL_DIR/lib" \
  1290. CPPFLAGS="-I$OPENSSL_DIR/include" \
  1291. --with-openssl=$OPENSSL_DIR
  1292. else
  1293. ./configure --prefix=$pyenv_path/pyenv
  1294. fi
  1295. make -j$cpu_cpunt
  1296. make install
  1297. if [ ! -f $pyenv_path/pyenv/bin/python3.12 ]; then
  1298. rm -rf $python_src_path
  1299. Red_Error "ERROR: Make python env fielded. Please try to reinstall"
  1300. fi
  1301. cd ~
  1302. rm -rf $python_src_path
  1303. wget --no-check-certificate -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -t 5 -T 20
  1304. wget --no-check-certificate -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/3.12/pip-3.12.3.txt -t 5 -T 20
  1305. ln -sf $pyenv_path/pyenv/bin/pip3.12 $pyenv_path/pyenv/bin/pip
  1306. ln -sf $pyenv_path/pyenv/bin/python3.12 $pyenv_path/pyenv/bin/python
  1307. ln -sf $pyenv_path/pyenv/bin/pip3.12 /usr/bin/btpip
  1308. ln -sf $pyenv_path/pyenv/bin/python3.12 /usr/bin/btpython
  1309. chmod -R 700 $pyenv_path/pyenv/bin
  1310. $pyenv_path/pyenv/bin/pip install -U pip
  1311. $pyenv_path/pyenv/bin/pip install -U setuptools
  1312. # $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
  1313. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
  1314. source $pyenv_path/pyenv/bin/activate
  1315. btpip install psutil
  1316. btpip install gevent
  1317. is_gevent=$($python_bin -m gevent 2>&1 | grep -oE package)
  1318. is_psutil=$($python_bin -m psutil 2>&1 | grep -oE package)
  1319. if [ "${is_gevent}" != "${is_psutil}" ]; then
  1320. Check_PIP_Packages
  1321. is_gevent=$($python_bin -m gevent 2>&1 | grep -oE package)
  1322. is_psutil=$($python_bin -m psutil 2>&1 | grep -oE package)
  1323. if [ "${is_gevent}" != "${is_psutil}" ]; then
  1324. Red_Error "ERROR: psutil/gevent install failed!"
  1325. fi
  1326. fi
  1327. }
  1328. delete_useless_package() {
  1329. /www/server/panel/pyenv/bin/pip uninstall aliyun-python-sdk-kms -y >/dev/null 2>&1
  1330. /www/server/panel/pyenv/bin/pip uninstall aliyun-python-sdk-core -y >/dev/null 2>&1
  1331. /www/server/panel/pyenv/bin/pip uninstall aliyun-python-sdk-core-v3 -y >/dev/null 2>&1
  1332. /www/server/panel/pyenv/bin/pip uninstall qiniu -y >/dev/null 2>&1
  1333. /www/server/panel/pyenv/bin/pip uninstall cos-python-sdk-v5 -y >/dev/null 2>&1
  1334. }
  1335. Install_Bt() {
  1336. if [ -f ${setup_path}/server/panel/data/port.pl ]; then
  1337. panelPort=$(cat ${setup_path}/server/panel/data/port.pl)
  1338. fi
  1339. if [ "${PANEL_PORT}" ];then
  1340. panelPort=$PANEL_PORT
  1341. fi
  1342. mkdir -p ${setup_path}/server/panel/logs
  1343. mkdir -p ${setup_path}/server/panel/vhost/apache
  1344. mkdir -p ${setup_path}/server/panel/vhost/nginx
  1345. mkdir -p ${setup_path}/server/panel/vhost/rewrite
  1346. mkdir -p ${setup_path}/server/panel/install
  1347. mkdir -p /www/server
  1348. mkdir -p /www/wwwroot
  1349. mkdir -p /www/wwwlogs
  1350. mkdir -p /www/backup/database
  1351. mkdir -p /www/backup/site
  1352. if [ ! -d "/etc/init.d" ];then
  1353. mkdir -p /etc/init.d
  1354. fi
  1355. if [ -f "/etc/init.d/bt" ]; then
  1356. /etc/init.d/bt stop
  1357. sleep 1
  1358. fi
  1359. panel_file="${setup_path}/panel.zip"
  1360. wget --no-check-certificate -O ${panel_file} ${Btapi_Url}/install/src/panel_pro_en.zip -t 5 -T 20
  1361. tmp_size=$(du -b ${panel_file} | awk '{print $1}')
  1362. if [ $tmp_size -lt 10026905 ]; then
  1363. ls -lh ${panel_file}
  1364. rm -f ${panel_file}
  1365. Red_Error "ERROR: Failed to download panel, please try install again!"
  1366. fi
  1367. # wget --no-check-certificate -O /etc/init.d/bt ${download_Url}/install/src/bt7_en.init -t 5 -T 20
  1368. # wget --no-check-certificate -O /www/server/panel/init.sh ${download_Url}/install/src/bt7_en.init -t 5 -T 20
  1369. # wget --no-check-certificate -O /www/server/panel/install/public.sh ${download_Url}/install/public.sh -t 5 -T 20
  1370. if [ -f "${setup_path}/server/panel/data/default.db" ]; then
  1371. if [ -d "/${setup_path}/server/panel/old_data" ]; then
  1372. rm -rf ${setup_path}/server/panel/old_data
  1373. fi
  1374. mkdir -p ${setup_path}/server/panel/old_data
  1375. d_format=$(date +"%Y%m%d_%H%M%S")
  1376. \cp -arf ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/data/default_backup_${d_format}.db
  1377. mv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.db
  1378. mv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.db
  1379. mv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.pl
  1380. mv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.pl
  1381. fi
  1382. unzip -o ${panel_file} -d ${setup_path}/server/ >/dev/null
  1383. if [ -d "${setup_path}/server/panel/old_data" ]; then
  1384. mv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.db
  1385. mv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.db
  1386. mv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.pl
  1387. mv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.pl
  1388. if [ -d "/${setup_path}/server/panel/old_data" ]; then
  1389. rm -rf ${setup_path}/server/panel/old_data
  1390. fi
  1391. fi
  1392. if [ ! -f "${setup_path}/server/panel/tools.py" ] || [ ! -f "${setup_path}/server/panel/BT-Panel" ]; then
  1393. ls -lh ${setup_path}/server/panel/BT-* ${setup_path}/server/panel/tools.py
  1394. Red_Error "ERROR: tools.py BT-Panel file does not exist, please try install again!"
  1395. fi
  1396. pro_file='/www/server/panel/data/panel_pro.pl'
  1397. if [ ! -e $pro_file ]; then
  1398. touch $pro_file
  1399. echo "true" > $pro_file
  1400. fi
  1401. Check_PIP_Packages
  1402. delete_useless_package
  1403. Update_Py_Lib
  1404. rm -f ${panel_file}
  1405. rm -f ${setup_path}/server/panel/class/*.pyc
  1406. rm -f ${setup_path}/server/panel/*.pyc
  1407. \cp -arpf /www/server/panel/init.sh /etc/init.d/bt
  1408. if [[ ! -s "/etc/init.d/bt" ]];then
  1409. rm -f /etc/init.d/bt
  1410. wget --no-check-certificate -O /etc/init.d/bt ${download_Url}/install/src/bt7_en.init -t 5 -T 20
  1411. wget --no-check-certificate -O /www/server/panel/init.sh ${download_Url}/install/src/bt7_en.init -t 5 -T 20
  1412. if [[ ! -s "/etc/init.d/bt" ]];then
  1413. Red_Error "ERROR: /etc/init.d/bt file content is 0kb "
  1414. fi
  1415. fi
  1416. chmod +x /etc/init.d/bt
  1417. chmod -R 600 ${setup_path}/server/panel
  1418. chmod -R 755 ${setup_path}/server/panel/webserver
  1419. chmod -R +x ${setup_path}/server/panel/script
  1420. ln -sf /etc/init.d/bt /usr/bin/bt
  1421. echo "${panelPort}" >${setup_path}/server/panel/data/port.pl
  1422. wget --no-check-certificate -O /www/server/panel/data/softList.conf ${download_Url}/install/conf/softList_en.conf -t 5 -T 20
  1423. rm -f /www/server/panel/class/*.so
  1424. if [ ! -f /www/server/panel/data/userInfo.json ]; then
  1425. echo "{\"id\":1,\"uid\":1,\"server_id\":\"1\",\"last_login_ip\":\"127.0.0.1\",\"username\":\"Administrator\",\"email\":\"admin@aapanel.com\",\"status\":1,\"token\":\"aaa.bbb.ccc\"}" > /www/server/panel/data/userInfo.json
  1426. fi
  1427. }
  1428. Use_self_signed_certificate() {
  1429. echo "Use Self-signed certificate"
  1430. rm -f /www/server/panel/ssl/*
  1431. SSL_path=/www/server/panel/ssl
  1432. # Create private key
  1433. openssl genrsa -out ${SSL_path}/privateKey.pem 2048
  1434. # Create a self-signed root certificate
  1435. openssl req -x509 -new -nodes -key ${SSL_path}/privateKey.pem -sha256 -days 3650 -out ${SSL_path}/certificate.pem \
  1436. -subj "/C=US/ST=State/L=City/O=aapanel.com/OU=aapanel.com/CN=*.aapanel.com" -nodes
  1437. # Use random password
  1438. # SSL_password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 16)
  1439. # Create PFX file
  1440. # openssl pkcs12 -export -out ${SSL_path}/baota_root.pfx -inkey ${SSL_path}/privateKey.pem -in ${SSL_path}/certificate.pem -passout pass:${SSL_password}
  1441. # Create password file
  1442. # echo "${SSL_password}" > ${SSL_path}/root_password.pl
  1443. echo "True" > /www/server/panel/data/ssl.pl
  1444. SET_SSL=true
  1445. if [ ! -s "${SSL_path}/privateKey.pem" ] || [ ! -s "${SSL_path}/certificate.pem" ]; then
  1446. SET_SSL=false
  1447. rm -f /www/server/panel/data/ssl.pl
  1448. echo "Self-signed certificate failed, panel SSl closed"
  1449. fi
  1450. }
  1451. Set_Bt_Panel() {
  1452. Run_User="www"
  1453. wwwUser=$(cat /etc/passwd|cut -d ":" -f 1|grep ^www$)
  1454. if [ "${wwwUser}" != "www" ];then
  1455. groupadd ${Run_User}
  1456. useradd -s /sbin/nologin -g ${Run_User} ${Run_User}
  1457. fi
  1458. chmod -R 700 /www/server/panel/pyenv/bin
  1459. # /www/server/panel/pyenv/bin/pip install cachelib
  1460. /www/server/panel/pyenv/bin/pip install python-telegram-bot==20.3
  1461. password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
  1462. if [ "$PANEL_PASSWORD" ];then
  1463. password=$PANEL_PASSWORD
  1464. fi
  1465. sleep 1
  1466. admin_auth="/www/server/panel/data/admin_path.pl"
  1467. if [ ! -f ${admin_auth} ]; then
  1468. auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
  1469. echo "/${auth_path}" >${admin_auth}
  1470. fi
  1471. if [ "${SAFE_PATH}" ];then
  1472. auth_path=$SAFE_PATH
  1473. echo "/${auth_path}" > ${admin_auth}
  1474. fi
  1475. auth_path=$(cat ${admin_auth})
  1476. # /www/server/panel/pyenv/bin/pip3 install pymongo
  1477. # /www/server/panel/pyenv/bin/pip3 install psycopg2-binary
  1478. # /www/server/panel/pyenv/bin/pip3 install flask -U
  1479. # /www/server/panel/pyenv/bin/pip3 install flask-sock
  1480. # /www/server/panel/pyenv/bin/pip3 install simple-websocket==0.10.0
  1481. check_pyOpenSSL=$(/www/server/panel/pyenv/bin/pip list|grep pyOpenSSL)
  1482. if [ -z "$check_pyOpenSSL" ]; then
  1483. /www/server/panel/pyenv/bin/pip install -I pyOpenSSl
  1484. fi
  1485. cd ${setup_path}/server/panel/
  1486. if [ "$SET_SSL" == true ]; then
  1487. # mkdir /www/server/panel/ssl
  1488. echo "SET ssl, please wait...."
  1489. ssl=$(/www/server/panel/pyenv/bin/python /www/server/panel/tools.py ssl)
  1490. echo ${ssl}
  1491. if [[ "${ssl}" -eq 1 ]];then
  1492. if [ -s "/www/server/panel/ssl/certificate.pem" ];then
  1493. check_certificate=$(openssl x509 -noout -modulus -in /www/server/panel/ssl/certificate.pem | openssl md5)
  1494. check_privateKey=$(openssl rsa -noout -modulus -in /www/server/panel/ssl/privateKey.pem | openssl md5)
  1495. if [ "${check_certificate}" != "${check_privateKey}" ];then
  1496. echo -e "The certificate and privateKey are not consistent, Use the built-in SSL certificate."
  1497. Use_self_signed_certificate
  1498. fi
  1499. else
  1500. Use_self_signed_certificate
  1501. fi
  1502. else
  1503. Use_self_signed_certificate
  1504. fi
  1505. echo "SET_SSL: $SET_SSL"
  1506. fi
  1507. /etc/init.d/bt start
  1508. $python_bin -m py_compile tools.py
  1509. $python_bin tools.py username
  1510. username=$($python_bin tools.py panel ${password})
  1511. if [ "$PANEL_USER" ];then
  1512. username=$PANEL_USER
  1513. fi
  1514. cd ~
  1515. echo "${password}" >${setup_path}/server/panel/default.pl
  1516. chmod 600 ${setup_path}/server/panel/default.pl
  1517. sleep 3
  1518. /etc/init.d/bt restart
  1519. sleep 5
  1520. isStart=$(ps aux | grep 'BT-Panel' | grep -v grep | awk '{print $2}')
  1521. if [ -z "${isStart}" ]; then
  1522. /etc/init.d/bt start
  1523. sleep 5
  1524. isStart=$(ps aux | grep 'BT-Panel' | grep -v grep | awk '{print $2}')
  1525. if [ -z "${isStart}" ]; then
  1526. Check_PIP_Packages
  1527. /etc/init.d/bt start
  1528. sleep 5
  1529. isStart=$(ps aux | grep 'BT-Panel' | grep -v grep | awk '{print $2}')
  1530. fi
  1531. fi
  1532. LOCAL_CURL=$(curl 127.0.0.1:$panelPort/login 2>&1 | grep -i html)
  1533. if [ -z "${isStart}" ] && [ -z "${LOCAL_CURL}" ]; then
  1534. /etc/init.d/bt 22
  1535. cd /www/server/panel/pyenv/bin
  1536. touch t.pl
  1537. ls -al python3.12 python3 python ${setup_path}/server/panel/BT-*
  1538. lsattr python3.12 python3 python
  1539. Red_Error "ERROR: The BT-Panel service startup failed."
  1540. fi
  1541. if [ "$PANEL_USER" ];then
  1542. cd ${setup_path}/server/panel/
  1543. btpython -c 'import tools;tools.set_panel_username("'$PANEL_USER'")'
  1544. cd ~
  1545. fi
  1546. if [ -f "/usr/bin/sqlite3" ] ;then
  1547. #sqlite3 /www/server/panel/data/db/panel.db "UPDATE config SET status = '1' WHERE id = '1';" > /dev/null 2>&1
  1548. sqlite3 /www/server/panel/data/default.db "UPDATE config SET status = '1' WHERE id = '1';" > /dev/null 2>&1
  1549. fi
  1550. touch /www/server/panel/install/i_mysql.pl
  1551. }
  1552. Set_Firewall() {
  1553. sshPort=$(cat /etc/ssh/sshd_config | grep 'Port ' | awk '{print $2}')
  1554. if [ "${PM}" = "apt-get" ]; then
  1555. if [ ! -f "/usr/bin/ufw" ] && [ ! -f "/bin/ufw" ] && ! Command_Exists "ufw"; then
  1556. apt-get install -y ufw
  1557. fi
  1558. if [ -f "/usr/sbin/ufw" ]; then
  1559. ufw allow 20/tcp >/dev/null 2>&1
  1560. ufw allow 21/tcp >/dev/null 2>&1
  1561. ufw allow 22/tcp >/dev/null 2>&1
  1562. ufw allow 80/tcp >/dev/null 2>&1
  1563. ufw allow 443/tcp >/dev/null 2>&1
  1564. ufw allow 888/tcp >/dev/null 2>&1
  1565. ufw allow 39000:40000/tcp >/dev/null 2>&1
  1566. ufw allow ${panelPort}/tcp >/dev/null 2>&1
  1567. ufw allow ${sshPort}/tcp >/dev/null 2>&1
  1568. ufw_status=$(ufw status)
  1569. echo y | ufw enable
  1570. ufw default deny
  1571. ufw reload
  1572. fi
  1573. else
  1574. if [ -f "/etc/init.d/iptables" ]; then
  1575. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
  1576. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
  1577. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
  1578. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
  1579. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
  1580. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT
  1581. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
  1582. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
  1583. #iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
  1584. iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
  1585. iptables -A INPUT -s localhost -d localhost -j ACCEPT
  1586. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  1587. iptables -P INPUT DROP
  1588. service iptables save
  1589. sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
  1590. iptables_status=$(service iptables status | grep 'not running')
  1591. if [ "${iptables_status}" == '' ]; then
  1592. service iptables restart
  1593. fi
  1594. else
  1595. AliyunCheck=$(cat /etc/redhat-release | grep "Aliyun Linux")
  1596. [ "${AliyunCheck}" ] && return
  1597. if [ ! -f "/usr/bin/firewall-cmd" ] && [ ! -f "/bin/firewall-cmd" ] && ! Command_Exists "firewall-cmd"; then
  1598. yum install firewalld -y
  1599. fi
  1600. [ "${Centos8Check}" ] && yum reinstall python3-six -y
  1601. systemctl enable firewalld
  1602. systemctl start firewalld
  1603. firewall-cmd --set-default-zone=public >/dev/null 2>&1
  1604. firewall-cmd --permanent --zone=public --add-port=20/tcp >/dev/null 2>&1
  1605. firewall-cmd --permanent --zone=public --add-port=21/tcp >/dev/null 2>&1
  1606. firewall-cmd --permanent --zone=public --add-port=22/tcp >/dev/null 2>&1
  1607. firewall-cmd --permanent --zone=public --add-port=80/tcp >/dev/null 2>&1
  1608. firewall-cmd --permanent --zone=public --add-port=443/tcp > /dev/null 2>&1
  1609. firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp >/dev/null 2>&1
  1610. firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp >/dev/null 2>&1
  1611. firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp >/dev/null 2>&1
  1612. #firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
  1613. firewall-cmd --reload
  1614. fi
  1615. fi
  1616. }
  1617. Get_Ip_Address() {
  1618. getIpAddress=""
  1619. # getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://brandnew.aapanel.com/api/common/getClientIP)
  1620. getIpAddress=$(curl -sSk --connect-timeout 10 -m 60 https://www.aapanel.com/api/common/getClientIP)
  1621. # if [ -z "${getIpAddress}" ] || [ "${getIpAddress}" = "0.0.0.0" ]; then
  1622. # isHosts=$(cat /etc/hosts|grep 'www.bt.cn')
  1623. # if [ -z "${isHosts}" ];then
  1624. # echo "" >> /etc/hosts
  1625. # echo "103.224.251.67 www.bt.cn" >> /etc/hosts
  1626. # #getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://brandnew.aapanel.com/api/common/getClientIP)
  1627. # getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
  1628. # if [ -z "${getIpAddress}" ];then
  1629. # sed -i "/bt.cn/d" /etc/hosts
  1630. # fi
  1631. # fi
  1632. # fi
  1633. ipv4Check=$($python_bin -c "import re; print(re.match(r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")
  1634. if [ "${ipv4Check}" == "None" ]; then
  1635. ipv6Address=$(echo ${getIpAddress} | tr -d "[]")
  1636. ipv6Check=$($python_bin -c "import re; print(re.match(r'^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))")
  1637. if [ "${ipv6Check}" == "None" ]; then
  1638. getIpAddress="SERVER_IP"
  1639. else
  1640. getIpAddress=$(echo "[$getIpAddress]")
  1641. echo "True" >${setup_path}/server/panel/data/ipv6.pl
  1642. sleep 1
  1643. /etc/init.d/bt restart
  1644. fi
  1645. fi
  1646. if [ "${getIpAddress}" != "SERVER_IP" ]; then
  1647. echo "${getIpAddress}" >${setup_path}/server/panel/data/iplist.txt
  1648. fi
  1649. }
  1650. Setup_Count() {
  1651. # curl -sSk --connect-timeout 10 -m 60 https://www.aapanel.com/api/setupCount/setupPanel?o=$1 >/dev/null 2>&1
  1652. # curl -sS --connect-timeout 10 -m 60 https://console.aapanel.com/Api/SetupCount?type=Linux > /dev/null 2>&1
  1653. if [ "$1" != "" ]; then
  1654. echo $1 >/www/server/panel/data/o.pl
  1655. cd /www/server/panel
  1656. $python_bin tools.py o
  1657. fi
  1658. echo /www >/var/bt_setupPath.conf
  1659. }
  1660. Install_Main() {
  1661. Check_Disk_Space
  1662. startTime=$(date +%s)
  1663. Lock_Clear
  1664. System_Check
  1665. Set_Ssl
  1666. Get_Pack_Manager
  1667. get_node_url
  1668. MEM_TOTAL=$(free -g | grep Mem | awk '{print $2}')
  1669. if [ "${MEM_TOTAL}" -le "1" ]; then
  1670. Auto_Swap
  1671. fi
  1672. if [ "${PM}" = "yum" ]; then
  1673. Install_RPM_Pack
  1674. elif [ "${PM}" = "apt-get" ]; then
  1675. Install_Deb_Pack
  1676. fi
  1677. Check_Install_Sys_Packs
  1678. Install_Python_Lib
  1679. Install_Bt
  1680. Set_Bt_Panel
  1681. Service_Add
  1682. Set_Firewall
  1683. Get_Ip_Address
  1684. Setup_Count ${IDC_CODE}
  1685. }
  1686. echo "
  1687. +----------------------------------------------------------------------
  1688. | aaPanel FOR CentOS/Ubuntu/Debian
  1689. +----------------------------------------------------------------------
  1690. | Copyright © 2015-2099 BT-SOFT(https://www.aapanel.com) All rights reserved.
  1691. +----------------------------------------------------------------------
  1692. | The WebPanel URL will be https://SERVER_IP:$panelPort when installed.
  1693. +----------------------------------------------------------------------
  1694. "
  1695. while [ ${#} -gt 0 ]; do
  1696. case $1 in
  1697. -h|--help)
  1698. echo "Usage: [options]"
  1699. echo "Options:"
  1700. echo " -u, --user Set aaPanel user name"
  1701. echo " -p, --password Set aaPanel password"
  1702. echo " -P, --port Set aaPanel port"
  1703. echo " --safe-path Set aaPanel safe path"
  1704. exit 0
  1705. ;;
  1706. -u|--user)
  1707. PANEL_USER=$2
  1708. shift 1
  1709. ;;
  1710. -p|--password)
  1711. PANEL_PASSWORD=$2
  1712. shift 1
  1713. ;;
  1714. -P|--port)
  1715. PANEL_PORT=$2
  1716. shift 1
  1717. ;;
  1718. --safe-path)
  1719. SAFE_PATH=$2
  1720. shift 1
  1721. ;;
  1722. --ssl-disable)
  1723. SSL_PL="disable"
  1724. ;;
  1725. -y)
  1726. go="y"
  1727. ;;
  1728. *)
  1729. IDC_CODE=$1
  1730. ;;
  1731. esac
  1732. shift 1
  1733. done
  1734. while [ "$go" != 'y' ] && [ "$go" != 'n' ]; do
  1735. read -p "Do you want to install aaPanel to the $setup_path directory now?(y/n): " go
  1736. done
  1737. if [ "$go" == 'n' ]; then
  1738. exit
  1739. fi
  1740. Install_Main
  1741. /etc/init.d/bt restart
  1742. intenal_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)
  1743. echo -e "=================================================================="
  1744. echo -e "\033[32mCongratulations! Installed successfully!\033[0m"
  1745. echo -e "=================================================================="
  1746. if [[ "$SET_SSL" == "true" ]]; then
  1747. HTTP_S="https"
  1748. else
  1749. HTTP_S="http"
  1750. fi
  1751. echo "aaPanel Internet Address: ${HTTP_S}://${getIpAddress}:${panelPort}$auth_path"
  1752. echo "aaPanel Internal Address: ${HTTP_S}://${intenal_ip}:${panelPort}$auth_path"
  1753. echo -e "username: $username"
  1754. echo -e "password: $password"
  1755. echo -e "\033[33mWarning:\033[0m"
  1756. echo -e "\033[33mIf you cannot access the panel, \033[0m"
  1757. echo -e "\033[33mrelease the following port ($panelPort|888|80|443|20|21) in the security group\033[0m"
  1758. echo -e "=================================================================="
  1759. endTime=$(date +%s)
  1760. ((outTime = ($endTime - $startTime) / 60))
  1761. if [ "${outTime}" == "0" ];then
  1762. ((outTime=($endTime-$startTime)))
  1763. echo -e "Time consumed:\033[32m $outTime \033[0mseconds!"
  1764. else
  1765. echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"
  1766. fi
  1767. rm -f install_7.0_en.sh /tmp/pip_en_3.12.txt ${check_pip_packs} ${show_pip_list_panel}