File size: 80,890 Bytes
020c337 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 | #!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
LANG=en_US.UTF-8
MAC_OS_CHECK=$(uname -a|grep Darwin)
if [ "${MAC_OS_CHECK}" ];then
echo "当前系统为macOS,无法安装宝塔面板,请使用Linux系统(服务器版本如Debian/Centos)安装宝塔面板"
echo "或使用Docker安装宝塔面板"
exit 1
fi
INSTALL_LOGFILE="/tmp/btpanel-install.log"
if [ -f "$INSTALL_LOGFILE" ];then
rm -f $INSTALL_LOGFILE
fi
exec > >(tee -a "$INSTALL_LOGFILE") 2>&1
CURL_CHECK=$(which curl)
if [ "$?" == "0" ];then
curl -sS --connect-timeout 10 -m 10 https://www.bt.cn/api/wpanel/SetupCount > /dev/null 2>&1
else
wget -O /dev/null -o /dev/null -T 5 https://www.bt.cn/api/wpanel/SetupCount
fi
backup_Url="https://download-cdn1.bt.cn"
signal_type=""
exit_msg() {
case $signal_type in
SIGINT)
EXIT_MSG="捕获到Ctrl+C信号退出"
;;
SIGTERM)
EXIT_MSG="捕获到进程被杀死"
;;
SIGHUP)
EXIT_MSG="捕获到终端连接异常"
;;
*)
EXIT_MSG="未知信号"
;;
esac
local TIME=$(date "+%Y-%m-%d %H:%M:%S")
if [ -s "/etc/redhat-release" ];then
SYS_VERSION=$(cat /etc/redhat-release)
elif [ -s "/etc/issue" ]; then
SYS_VERSION=$(cat /etc/issue)
fi
SYS_INFO=$(uname -a)
SYS_BIT=$(getconf LONG_BIT)
MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
CPU_INFO=$(getconf _NPROCESSORS_ONLN)
curl -sS --connect-timeout 3 -m 3 --request POST \
--url "http://api.bt.cn/bt_error/index.php" \
--data "UID=89045" \
--data "PANEL_VERSION=9.3.9"\
--data "REQUEST_DATE=${TIME}" \
--data "OS_VERSION=${SYS_VERSION}" \
--data "REMOTE_ADDR=192.168.168.1641" \
--data "REQUEST_URI=panel" \
--data "USER_AGENT=${SYS_INFO}" \
--data "ERROR_INFO=${EXIT_MSG}" \
--data "PACK_TIME=${TIME}" \
--data "TYPE=3" > /dev/null
exit 1
}
trap 'signal_type=SIGINT; exit_msg' SIGINT
trap 'signal_type=SIGTERM; exit_msg' SIGTERM
trap 'signal_type=SIGHUP; exit_msg' SIGHUP
if [ $(whoami) != "root" ];then
if [ -f "/usr/bin/curl" ];then
DOWN_EXEC="curl -sSO"
else
DOWN_EXEC="wget -O install_panel.sh"
fi
echo "====================================================="
echo "检查到当前非root权限进行面板安装"
IS_UBUNTU=$(cat /etc/issue|grep Ubuntu)
IS_DEBIAN=$(cat /etc/issue|grep Debian)
if [ "${IS_UBUNTU}" ];then
echo "请使用下面命令重新执行安装面板"
echo "sudo $DOWN_EXEC https://download.bt.cn/install/install_panel.sh;sudo bash install_panel.sh"
elif [ "${IS_DEBIAN}" ];then
echo "请执行su root命令切换为root账户后"
echo "执行下面命令重新安装宝塔面板"
echo "$DOWN_EXEC https://download.bt.cn/install/install_panel.sh;bash install_panel.sh"
else
if [ -f "/usr/bin/sudo" ];then
echo "请使用下面命令使用root权限重新执行安装"
echo "sudo $DOWN_EXEC https://download.bt.cn/install/install_panel.sh;sudo bash install_panel.sh"
else
echo "请执行su root命令切换为root账户后"
echo "执行下面命令重新安装宝塔面板"
echo "$DOWN_EXEC https://download.bt.cn/install/install_panel.sh;bash install_panel.sh"
fi
fi
echo "-----------------------------------------------------"
exit 1
fi
MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
if [ "${MEM_TOTAL}" ] ;then
if [ "${MEM_TOTAL}" -lt "450" ];then
echo "====================================================="
free -m
echo "当前服务器内存为:${MEM_TOTAL}MB"
echo "检测到当前服务器内存小于450MB,无法安装宝塔面板"
echo "建议更换内存大于等于512MB的服务器安装宝塔面板"
echo "====================================================="
exit 1
fi
fi
Fix_Apt_Lock(){
[ ! -f "/usr/bin/apt-get" ] && return 0
echo "检查 apt/dpkg 锁状态..."
# # 1. 停止自动更新服务
# if systemctl is-active --quiet unattended-upgrades 2>/dev/null; then
# echo "停止 unattended-upgrades 服务..."
# systemctl stop unattended-upgrades 2>/dev/null
# systemctl disable unattended-upgrades 2>/dev/null
# sleep 2
# fi
# 2. 等待其他 apt/dpkg 进程(最多等待60秒)
local wait=0
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 || \
fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1 || \
fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || \
fuser /var/cache/apt/archives/lock >/dev/null 2>&1; do
if [ ${wait} -eq 0 ]; then
echo "检测到 apt/dpkg 正在使用中,等待完成..."
ps aux | grep -E 'apt-get|apt |dpkg|unattended' | grep -v grep | awk '{print " PID "$2": "$11}' || true
fi
[ ${wait} -ge 60 ] && break
sleep 3
wait=$((wait + 3))
done
# 3. 如果还有锁,强制清理
if fuser /var/lib/dpkg/lock >/dev/null 2>&1 || \
fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1 || \
fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || \
fuser /var/cache/apt/archives/lock >/dev/null 2>&1; then
echo "强制清理 apt/dpkg 锁..."
# 强制终止进程
pkill -9 unattended-upgr 2>/dev/null
pkill -9 apt-get 2>/dev/null
pkill -9 apt 2>/dev/null
pkill -9 dpkg 2>/dev/null
sleep 1
# 删除所有锁文件
rm -f /var/lib/dpkg/lock-frontend
rm -f /var/lib/dpkg/lock
rm -f /var/lib/apt/lists/lock
rm -f /var/cache/apt/archives/lock
# 修复 dpkg 状态
echo "修复 dpkg 状态..."
dpkg --configure -a 2>/dev/null || true
apt-get install -f -y 2>/dev/null || true
fi
echo "apt/dpkg 锁检查完成"
return 0
}
is64bit=$(getconf LONG_BIT)
if [ "${is64bit}" != '64' ];then
echo "抱歉, 当前面板版本不支持32位系统, 请使用64位系统或安装宝塔5.9!";
exit 1
fi
Centos6Check=$(cat /etc/redhat-release | grep ' 6.' | grep -iE 'centos|Red Hat')
if [ "${Centos6Check}" ];then
echo "Centos6不支持安装宝塔面板,请更换Centos7/8安装宝塔面板"
exit 1
fi
UbuntuCheck=$(cat /etc/issue|grep Ubuntu|awk '{print $2}'|cut -f 1 -d '.')
if [ "${UbuntuCheck}" ] && [ "${UbuntuCheck}" -lt "16" ];then
echo "Ubuntu ${UbuntuCheck}不支持安装宝塔面板,建议更换Ubuntu18/20安装宝塔面板"
exit 1
fi
HOSTNAME_CHECK=$(cat /etc/hostname)
if [ -z "${HOSTNAME_CHECK}" ];then
echo "localhost" > /etc/hostname
# echo "当前主机名hostname为空无法安装宝塔面板,请咨询服务器运营商设置好hostname后再重新安装"
# exit 1
fi
UBUNTU_NO_LTS=$(cat /etc/issue|grep Ubuntu|grep -E "19|21|23|25")
if [ "${UBUNTU_NO_LTS}" ];then
echo "当前您使用的非Ubuntu-lts版本,无法进行宝塔面板的安装"
echo "请使用Ubuntu-20/20/22/24进行安装宝塔面板"
exit 1
fi
DEBIAN_9_C=$(cat /etc/issue|grep Debian|grep -E "7 |8 |9 ")
if [ "${DEBIAN_9_C}" ];then
echo "当前您使用的Debian-7/8/9,官方已经停止支持、无法进行宝塔面板的安装"
echo "建议使用Debian-11/12/13进行安装宝塔面板"
exit 1
fi
cd ~
setup_path="/www"
python_bin=$setup_path/server/panel/pyenv/bin/python
cpu_cpunt=$(cat /proc/cpuinfo|grep processor|wc -l)
panelPort=$(expr $RANDOM % 55535 + 10000)
# if [ "$1" ];then
# IDC_CODE=$1
# fi
#2026-03-14新增下载共用函数
Download_File(){
# 参数1:主下载域名(如http://download.bt.cn)
# 参数2:备用下载域名(如http://download.bt.com)
# 参数3:文件路径(如/src/file.tar.gz)
# 参数4:保存路径(如/tmp/file.tar.gz)
# 示例调用:Download_File "http://download.bt.cn" "http://download.bt.com" "/src/file.tar.gz" "/tmp/file.tar.gz"
# 智能下载函数,支持curl和wget,自动重试,验证文件大小,确保下载成功
local primary_domain=$1
local backup_domain=$2
local file_path=$3
local save_path=$4
local max_retry=2
local connect_timeout=15
local timeout=20
local min_speed=60000
local retry_count=0
local download_success=0
local current_url=""
echo "正在下载: $(basename ${save_path})"
while [ ${retry_count} -lt ${max_retry} ]; do
if [ -f "${save_path}" ]; then
rm -f "${save_path}"
fi
if [ ${retry_count} -eq 0 ]; then
current_url="${primary_domain}${file_path}"
#echo "使用主下载节点: ${primary_domain}"
else
current_url="${backup_domain}${file_path}"
#echo "切换到备用下载节点: ${backup_domain}"
fi
if command -v curl >/dev/null 2>&1; then
curl -fL --connect-timeout ${connect_timeout} --speed-limit ${min_speed} --speed-time 10 -o "${save_path}" "${current_url}"
if [ $? -eq 0 ] && [ -f "${save_path}" ]; then
file_size=$(du -b "${save_path}" 2>/dev/null | awk '{print $1}')
if [ "${file_size}" -gt 100 ]; then
download_success=1
break
fi
fi
elif command -v wget >/dev/null 2>&1; then
wget --connect-timeout=${connect_timeout} --read-timeout=10 --tries=1 --progress=bar:force -O "${save_path}" "${current_url}" 2>&1
if [ $? -eq 0 ] && [ -f "${save_path}" ]; then
file_size=$(du -b "${save_path}" 2>/dev/null | awk '{print $1}')
if [ "${file_size}" -gt 100 ]; then
download_success=1
break
fi
fi
else
echo "错误: 未找到curl或wget下载工具"
return 1
fi
retry_count=$((retry_count + 1))
if [ ${retry_count} -lt ${max_retry} ]; then
echo "下载失败,${retry_count}/${max_retry} 次重试中..."
sleep 2
fi
done
if [ ${download_success} -eq 0 ]; then
echo "错误: 下载失败,已重试 ${max_retry} 次"
#echo "主节点: ${primary_domain}${file_path}"
#echo "备用节点: ${backup_domain}${file_path}"
return 1
fi
if [ ${retry_count} -gt 0 ] && [ ${download_success} -eq 1 ]; then
download_Url=${backup_domain}
fi
#echo "下载成功: $(basename ${save_path})"
return 0
}
Ready_Check(){
WWW_DISK_SPACE=$(df |grep /www|awk '{print $4}')
ROOT_DISK_SPACE=$(df |grep /$|awk '{print $4}')
if [ "${ROOT_DISK_SPACE}" -le 412000 ];then
df -h
echo -e "系统盘剩余空间不足400M 无法继续安装宝塔面板!"
echo -e "请尝试清理磁盘空间后再重新进行安装"
exit 1
fi
if [ "${WWW_DISK_SPACE}" ] && [ "${WWW_DISK_SPACE}" -le 412000 ] ;then
echo -e "/www盘剩余空间不足400M 无法继续安装宝塔面板!"
echo -e "请尝试清理磁盘空间后再重新进行安装"
exit 1
fi
# ROOT_DISK_INODE=$(df -i|grep /$|awk '{print $2}')
# if [ "${ROOT_DISK_INODE}" != "0" ];then
# ROOT_DISK_INODE_FREE=$(df -i|grep /$|awk '{print $4}')
# if [ "${ROOT_DISK_INODE_FREE}" -le 1000 ];then
# echo -e "系统盘剩余inodes空间不足1000,无法继续安装!"
# echo -e "请尝试清理磁盘空间后再重新进行安装"
# exit 1
# fi
# fi
# WWW_DISK_INODE==$(df -i|grep /www|awk '{print $2}')
# if [ "${WWW_DISK_INODE}" ] && [ "${WWW_DISK_INODE}" != "0" ] ;then
# WWW_DISK_INODE_FREE=$(df -i|grep /www|awk '{print $4}')
# if [ "${WWW_DISK_INODE_FREE}" ] && [ "${WWW_DISK_INODE_FREE}" -le 1000 ] ;then
# echo -e "/www盘剩余inodes空间不足1000, 无法继续安装!"
# echo -e "请尝试清理磁盘空间后再重新进行安装"
# exit 1
# fi
# fi
}
GetSysInfo(){
if [ -s "/etc/redhat-release" ];then
SYS_VERSION=$(cat /etc/redhat-release)
elif [ -s "/etc/issue" ]; then
SYS_VERSION=$(cat /etc/issue)
fi
SYS_INFO=$(uname -a)
SYS_BIT=$(getconf LONG_BIT)
MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
CPU_INFO=$(getconf _NPROCESSORS_ONLN)
# if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ];then
# cat /etc/apt/sources.list.d/ubuntu.sources
# apt-get update -y
# apt-get install unzip -y
# fi
echo -e ${SYS_VERSION}
echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
echo -e ${SYS_INFO}
echo -e "============================================"
echo -e "请截图以上报错信息发帖至论坛www.bt.cn/bbs求助"
# echo -e "或添加QQ群:706478424 寻求帮助"
echo -e "或浏览器访问:https://www.bt.cn/static/astro/images/wechat/wechat-all.png"
echo -e "扫码联系企业微信技术求助"
echo -e "============================================"
if [ -f "/etc/redhat-release" ];then
Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos')
echo -e "============================================"
echo -e "Centos7/8官方已经停止支持"
echo -e "如是新安装系统服务器建议更换至Debian-12/Ubuntu-22/Centos-9系统安装宝塔面板"
echo -e "============================================"
fi
if [ -f "/usr/sbin/setstatus" ] || [ -f "/usr/sbin/setstatus" ];then
echo -e "=================================================="
echo -e " 检测到为麒麟系统,可能默认开启安全功能导致安装失败"
echo -e " 请执行以下命令关闭安全加固后,再重新安装宝塔面板看是否正常"
echo -e " 命令:sudo setstatus softmode -p"
echo -e "=================================================="
fi
#2026-3-14新增常用命令检测
CORE_TOOLS="wget tar xz unzip"
NO_EXIST_TOOL=""
for tool in $CORE_TOOLS; do
if ! command -v "$tool" >/dev/null 2>&1; then
if [ "${PM}" = "apt-get" ] && [ "$tool" = "xz" ]; then
NO_EXIST_TOOL="$NO_EXIST_TOOL xz-utils"
else
NO_EXIST_TOOL="$NO_EXIST_TOOL $tool"
fi
fi
done
if [ -n "$NO_EXIST_TOOL" ]; then
if [ "${PM}" = "yum" ]; then
yum install -y $NO_EXIST_TOOL
elif [ "${PM}" = "apt-get" ]; then
apt-get update -y
apt-get install -y $NO_EXIST_TOOL
fi
fi
if [ -n "$NO_EXIST_TOOL" ]; then
NO_EXIST_TOOL="${NO_EXIST_TOOL# }"
echo "========================================================"
echo " 检测到缺少必要的系统工具: $NO_EXIST_TOOL"
echo " 宝塔面板安装过程中会尝试修复系统源并安装这些工具,"
echo " 但本次安装未能成功,可能是由于系统源或网络问题导致。"
echo " 建议您先自行排查或使用 AI 协助解决问题后,再重新安装宝塔面板。"
echo " 请注意:执行下面命令时产生的报错信息是排查问题的关键信息,"
echo " 请根据报错信息进行处理后再尝试安装。"
echo " 您可以使用以下命令手动安装缺少的工具:"
if [ -f "/usr/bin/yum" ]; then
echo " 安装命令: yum install $NO_EXIST_TOOL -y"
elif [ -f "/usr/bin/apt-get" ]; then
echo " 安装命令: apt-get install $NO_EXIST_TOOL -y"
else
echo " 系统未识别,请手动安装上述工具"
fi
echo "========================================================"
fi
# SYS_SSL_LIBS=$(pkg-config --list-all | grep -q libssl)
# if [ -z "$SYS_SSL_LIBS" ] && [ -z "$NO_EXIST_TOOL" ];then
# echo "检测到缺少系统ssl相关依赖,可执行下面命令安装依赖后再重新安装宝塔看是否正常"
# echo "执行前请确保系统源正常"
# if [ -f "/usr/bin/yum" ];then
# echo "安装依赖命令: yum install openssl-devel -y"
# elif [ -f "/usr/bin/apt-get" ];then
# echo "安装依赖命令: apt-get install libssl-dev -y"
# fi
# rm -rf /www/server/panel/pyenv
# echo -e "=================================================="
# fi
if [ -f "/tmp/btpanel-install.log" ] && [ ! -f "/tmp/btpanel_err.pl" ];then
local TIME=$(date "+%Y-%m-%d %H:%M:%S")
INSTALL_USER=$(whoami)
echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO} >> ${INSTALL_LOGFILE}
echo -e ${SYS_VERSION} ${SYS_INFO} >> ${INSTALL_LOGFILE}
echo -e $INSTALL_USER >> ${INSTALL_LOGFILE}
OS_INFO=$(cat /etc/os-release |grep ID)
echo $OS_INFO >> $INSTALL_LOGFILE
PANEL_PORT_CHECK=$(lsof -i :${panelPort})
echo ${PANEL_PORT_CHECK} >> $INSTALL_LOGFILE
echo $LOCAL_CURL >> $INSTALL_LOGFILE
ERR_MSG=$(tail -n 70 $INSTALL_LOGFILE)
is_aarch64=$(uname -a|grep aarch64)
if [ "${is_aarch64}" ];then
PANEL_V="9.5.0"
else
PANEL_V="9.4.9"
fi
curl -sS --connect-timeout 3 -m 3 --request POST \
--url "http://api.bt.cn/bt_error/index.php" \
--data "UID=89045" \
--data "PANEL_VERSION=${PANEL_V}"\
--data "REQUEST_DATE=${TIME}" \
--data "OS_VERSION=${SYS_VERSION}" \
--data "REMOTE_ADDR=192.168.168.1641" \
--data "REQUEST_URI=panel" \
--data "USER_AGENT=${SYS_INFO}" \
--data "ERROR_INFO=${ERR_MSG}" \
--data "PACK_TIME=${TIME}" \
--data "TYPE=3" > /dev/null
fi
echo "True" > /tmp/btpanel_err.pl
# if [ -f "/usr/bin/qrencode" ];then
# echo -e "或微信扫码联系企业微信技术求助"
# echo -e "============================================"
# qrencode -t ANSIUTF8 "https://work.weixin.qq.com/kfid/kfc9072f0e29a53bd52"
# echo -e "============================================"
# else
# echo -e "或手机访问以下链接、扫码联系企业微信技术求助"
# echo -e "============================================"
# echo -e "联系链接:https://work.weixin.qq.com/kfid/kfc9072f0e29a53bd52"
# echo -e "============================================"
# fi
}
Red_Error(){
echo '=================================================';
printf '\033[1;31;40m%b\033[0m\n' "$@";
GetSysInfo
exit 1;
}
Lock_Clear(){
if [ -f "/etc/bt_crack.pl" ];then
chattr -R -ia /www
chattr -ia /etc/init.d/bt
\cp -rpa /www/backup/panel/vhost/* /www/server/panel/vhost/
mv /www/server/panel/BTPanel/__init__.bak /www/server/panel/BTPanel/__init__.py
rm -f /etc/bt_crack.pl
fi
}
Install_Check(){
if [ "${INSTALL_FORCE}" ];then
return
fi
echo -e "----------------------------------------------------"
echo -e "检查已有其他Web/mysql环境,安装宝塔可能影响现有站点及数据"
echo -e "Web/mysql service is alreday installed,Can't install panel"
echo -e "----------------------------------------------------"
echo -e "已知风险/Enter yes to force installation"
read -p "输入yes强制安装: " yes;
if [ "$yes" != "yes" ];then
echo -e "------------"
echo "取消安装"
exit;
fi
INSTALL_FORCE="true"
}
System_Check(){
MYSQLD_CHECK=$(ps -ef |grep mysqld|grep -v grep|grep -v /www/server/mysql)
PHP_CHECK=$(ps -ef|grep php-fpm|grep master|grep -v /www/server/php)
NGINX_CHECK=$(ps -ef|grep nginx|grep master|grep -v /www/server/nginx)
HTTPD_CHECK=$(ps -ef |grep -E 'httpd|apache'|grep -v /www/server/apache|grep -v grep)
if [ "${PHP_CHECK}" ] || [ "${MYSQLD_CHECK}" ] || [ "${NGINX_CHECK}" ] || [ "${HTTPD_CHECK}" ];then
Install_Check
fi
}
Set_Ssl(){
SET_SSL=true
if [ "${SSL_PL}" ];then
SET_SSL=""
fi
}
Add_lib_Install(){
if [ -f "/etc/os-release" ];then
. /etc/os-release
OS_V=${VERSION_ID%%.*}
if [ "${ID}" == "debian" ] && [[ "${OS_V}" =~ ^(11|12|13)$ ]];then
OS_NAME=${ID}
elif [ "${ID}" == "ubuntu" ] && [[ "${OS_V}" =~ ^(22|24)$ ]];then
OS_NAME=${ID}
elif [ "${ID}" == "centos" ] && [[ "${OS_V}" =~ ^(7)$ ]];then
OS_NAME="el"
elif [ "${ID}" == "opencloudos" ] && [[ "${OS_V}" =~ ^(9)$ ]];then
OS_NAME=${ID}
elif [ "${ID}" == "tencentos" ] && [[ "${OS_V}" =~ ^(4)$ ]];then
OS_NAME=${ID}
elif [ "${ID}" == "hce" ] && [[ "${OS_V}" =~ ^(2)$ ]];then
OS_NAME=${ID}
elif { [ "${ID}" == "almalinux" ] || [ "${ID}" == "centos" ] || [ "${ID}" == "rocky" ]; } && [[ "${OS_V}" =~ ^(9)$ ]]; then
OS_NAME="el"
fi
fi
X86_CHECK=$(uname -m|grep x86_64)
if [ "${OS_NAME}" ] && [ "${X86_CHECK}" ];then
if [ "${PM}" = "yum" ]; then
mtype="1"
elif [ "${PM}" = "apt-get" ]; then
mtype="4"
fi
cd /www/server/panel/class
btpython -c "import panelPlugin; plugin = panelPlugin.panelPlugin(); plugin.check_install_lib('${mtype}')"
echo "True" > /tmp/panelTask.pl
echo "True" > /www/server/panel/install/ins_lib.pl
fi
}
Get_Pack_Manager(){
if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
PM="yum"
elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
PM="apt-get"
fi
}
Check_And_Fix_Debian_Ubuntu_Source(){
#2026-3-12日更新
# 作用:检查Debian/Ubuntu系统源配置,自动替换过旧的版本代号为当前系统版本的正确代号,保持较新版本代号不变,避免引入不兼容的软件包
# 场景:用户系统升级后,sources.list中仍然保留了旧版本的代号,导致安装过程中无法找到正确的软件包,安装失败
[ ! -f "/usr/bin/apt-get" ] && return 0
[ ! -f "/etc/os-release" ] && return 0
. /etc/os-release
# 只处理Debian和Ubuntu
if [ "${ID}" != "debian" ] && [ "${ID}" != "ubuntu" ]; then
return 0
fi
echo "=================================================="
echo "检查${ID}系统源配置..."
# 定义版本代号映射(按版本顺序)
local correct_codename=""
local version_order=""
local version_index=0
if [ "${ID}" = "debian" ]; then
case "${VERSION_ID%%.*}" in
10) correct_codename="buster"; version_index=10 ;;
11) correct_codename="bullseye"; version_index=11 ;;
12) correct_codename="bookworm"; version_index=12 ;;
13) correct_codename="trixie"; version_index=13 ;;
esac
# 定义版本顺序映射 (codename:version_number)
declare -A debian_versions=(
# ["jessie"]=8
# ["stretch"]=9
["buster"]=10
["bullseye"]=11
["bookworm"]=12
["trixie"]=13
)
elif [ "${ID}" = "ubuntu" ]; then
case "${VERSION_ID}" in
18.04) correct_codename="bionic"; version_index=1804 ;;
20.04) correct_codename="focal"; version_index=2004 ;;
22.04) correct_codename="jammy"; version_index=2204 ;;
24.04) correct_codename="noble"; version_index=2404 ;;
esac
# 定义版本顺序映射
declare -A ubuntu_versions=(
# ["trusty"]=1404
# ["xenial"]=1604
["bionic"]=1804
["focal"]=2004
["jammy"]=2204
["noble"]=2404
)
fi
if [ -z "${correct_codename}" ]; then
echo "未识别的${ID}版本: ${VERSION_ID}"
return 0
fi
echo "当前系统: ${ID} ${VERSION_ID} -> 正确: ${correct_codename}"
# 检查sources.list
sources_file="/etc/apt/sources.list"
if [ ! -f "${sources_file}" ]; then
echo "源文件 ${sources_file} 不存在,跳过检查"
return 0
fi
# 收集需要替换的旧代号
need_fix=0
old_codenames=""
if [ "${ID}" = "debian" ]; then
for codename in "${!debian_versions[@]}"; do
local codename_version=${debian_versions[$codename]}
# 只处理比当前版本旧的代号
if [ ${codename_version} -lt ${version_index} ]; then
if grep -q "[[:space:]]${codename}[[:space:]]" "${sources_file}" 2>/dev/null; then
echo "发现旧版本代号: ${codename} (版本${codename_version} < 当前${version_index})"
old_codenames="${old_codenames} ${codename}"
need_fix=1
fi
elif [ ${codename_version} -gt ${version_index} ] && [ ${codename_version} -lt 99 ]; then
if grep -q "[[:space:]]${codename}[[:space:]]" "${sources_file}" 2>/dev/null; then
echo "检测到较新版本代号: ${codename} (版本${codename_version} > 当前${version_index}),跳过替换"
fi
fi
done
elif [ "${ID}" = "ubuntu" ]; then
for codename in "${!ubuntu_versions[@]}"; do
local codename_version=${ubuntu_versions[$codename]}
# 只处理比当前版本旧的代号
if [ ${codename_version} -lt ${version_index} ]; then
if grep -q "[[:space:]]${codename}[[:space:]]" "${sources_file}" 2>/dev/null; then
echo "发现旧版本代号: ${codename} (版本${codename_version} < 当前${version_index})"
old_codenames="${old_codenames} ${codename}"
need_fix=1
fi
elif [ ${codename_version} -gt ${version_index} ]; then
if grep -q "[[:space:]]${codename}[[:space:]]" "${sources_file}" 2>/dev/null; then
echo "检测到较新版本代号: ${codename} (版本${codename_version} > 当前${version_index}),跳过替换"
fi
fi
done
fi
if [ ${need_fix} -eq 0 ]; then
#echo "系统源配置正确,无需修复"
return 0
fi
# 备份并修复
echo "=================================================="
echo "检测到系统源配置使用了旧的版本服务器代号!"
echo "当前系统: ${ID} ${VERSION_ID} 应使用服务器代号: ${correct_codename}"
echo "正在自动修复旧版本服务器代号..."
echo "=================================================="
# 备份原文件
backup_file="${sources_file}.bak.$(date +%Y%m%d_%H%M%S)"
\cp -p "${sources_file}" "${backup_file}"
echo "已备份到: ${backup_file}"
# 只替换旧版本的代号
for wrong_codename in ${old_codenames}; do
sed -ri "/^[[:space:]]*(deb|deb-src) / s/${wrong_codename}/${correct_codename}/g" "${sources_file}"
echo "已替换: ${wrong_codename} -> ${correct_codename}"
done
echo "源配置已修复,更新软件包列表..."
apt-get update -y 2>&1 | head -n 20
if [ $? -eq 0 ]; then
echo "源更新成功!"
else
echo "警告: apt-get update 执行失败,可能需要手动检查"
echo "如需回滚,备份文件在: ${backup_file}"
fi
return 0
}
Set_Repo_Url(){
if [ "${PM}"="apt-get" ];then
if [ -f "/etc/os-release" ];then
. /etc/os-release
OS_V=${VERSION_ID%%.*}
if [ "${ID}" == "debian" ] && [ "${OS_V}" = "10" ];then
apt-get update -y
if [ "$?" != "0" ];then
echo "deb https://mirrors.aliyun.com/debian-archive/debian/ buster main contrib non-free" > /etc/apt/sources.list
echo "deb-src https://mirrors.aliyun.com/debian-archive/debian/ buster main contrib non-free" >> /etc/apt/sources.list
echo "deb https://mirrors.aliyun.com/debian-archive/debian-security/ buster/updates main contrib non-free" >> /etc/apt/sources.list
echo "deb-src https://mirrors.aliyun.com/debian-archive/debian-security/ buster/updates main contrib non-free" >> /etc/apt/sources.list
apt-get update -y
fi
return
fi
fi
ALI_CLOUD_CHECK=$(grep Alibaba /etc/motd)
Tencent_Cloud=$(cat /etc/hostname |grep -E VM-[0-9]+-[0-9]+)
VELINUX_CHECK=$(grep veLinux /etc/os-release)
if [ "${ALI_CLOUD_CHECK}" ] || [ "${Tencent_Cloud}" ] || [ "${VELINUX_CHECK}" ];then
return
fi
CN_CHECK=$(curl -sS --connect-timeout 10 -m 10 https://api.bt.cn/api/isCN)
if [ "${CN_CHECK}" == "True" ];then
SOURCE_URL_CHECK=$(grep -E 'security.ubuntu.com|archive.ubuntu.com|security.debian.org|deb.debian.org' /etc/apt/sources.list)
if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ];then
SOURCE_URL_CHECK=$(grep -E 'security.ubuntu.com|archive.ubuntu.com|security.debian.org|deb.debian.org' /etc/apt/sources.list.d/ubuntu.sources)
fi
fi
#GET_SOURCES_URL=$(cat /etc/apt/sources.list|grep ^deb|head -n 1|awk -F[/:] '{print $4}')
GET_SOURCES_URL=$(cat /etc/apt/sources.list|grep ^deb|head -n 1|sed -E 's|^[^ ]+ https?://([^/]+).*|\1|')
if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ];then
GET_SOURCES_URL=$(cat /etc/apt/sources.list.d/ubuntu.sources|grep ^URIs:|head -n 1|sed -E 's|^[^ ]+ https?://([^/]+).*|\1|')
fi
NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${GET_SOURCES_URL} -o /dev/null)
NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $1}')
TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $2 * 1000}'|cut -d '.' -f 1)
if { [ "${NODE_STATUS}" != "200" ] && [ "${NODE_STATUS}" != "301" ]; } || [ "${TIME_TOTAL}" -ge "500" ] || [ "${SOURCE_URL_CHECK}" ]; then
\cp -rpa /etc/apt/sources.list /etc/apt/sources.list.btbackup
apt_lists=(mirrors.cloud.tencent.com mirrors.163.com repo.huaweicloud.com mirrors.tuna.tsinghua.edu.cn mirrors.aliyun.com mirrors.ustc.edu.cn )
apt_lists=(mirrors.cloud.tencent.com repo.huaweicloud.com mirrors.aliyun.com mirrors.ustc.edu.cn mirrors.163.com)
for list in ${apt_lists[@]};
do
NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${list} -o /dev/null)
NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $1}')
TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $2 * 1000}'|cut -d '.' -f 1)
if [ "${NODE_STATUS}" == "200" ] || [ "${NODE_STATUS}" == "301" ];then
if [ "${TIME_TOTAL}" -le "150" ];then
if [ -f "/etc/apt/sources.list" ];then
sed -i "s/${GET_SOURCES_URL}/${list}/g" /etc/apt/sources.list
sed -i "s/cn.security.ubuntu.com/${list}/g" /etc/apt/sources.list
sed -i "s/cn.archive.ubuntu.com/${list}/g" /etc/apt/sources.list
sed -i "s/security.ubuntu.com/${list}/g" /etc/apt/sources.list
sed -i "s/archive.ubuntu.com/${list}/g" /etc/apt/sources.list
sed -i "s/security.debian.org/${list}/g" /etc/apt/sources.list
sed -i "s/deb.debian.org/${list}/g" /etc/apt/sources.list
fi
if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ];then
\cp -rpa /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak
sed -i "s/${GET_SOURCES_URL}/${list}/g" /etc/apt/sources.list.d/ubuntu.sources
sed -i "s/cn.security.ubuntu.com/${list}/g" /etc/apt/sources.list.d/ubuntu.sources
sed -i "s/cn.archive.ubuntu.com/${list}/g" /etc/apt/sources.list.d/ubuntu.sources
sed -i "s/security.ubuntu.com/${list}/g" /etc/apt/sources.list.d/ubuntu.sources
sed -i "s/archive.ubuntu.com/${list}/g" /etc/apt/sources.list.d/ubuntu.sources
sed -i "s/security.debian.org/${list}/g" /etc/apt/sources.list.d/ubuntu.sources
sed -i "s/deb.debian.org/${list}/g" /etc/apt/sources.list.d/ubuntu.sources
sleep 3
apt-get update -y
if [ $? != "0" ];then
\cp -rpa /etc/apt/sources.list.d/ubuntu.sources.bak /etc/apt/sources.list.d/ubuntu.sources
apt-get update -y
fi
fi
break;
fi
fi
done
fi
fi
}
Auto_Swap()
{
swap=$(free |grep Swap|awk '{print $2}')
if [ "${swap}" -gt 1 ];then
echo "Swap total sizse: $swap";
return;
fi
if [ ! -d /www ];then
mkdir /www
fi
echo "正在设置虚拟内存,请稍等..........";
echo '---------------------------------------------';
swapFile="/www/swap"
dd if=/dev/zero of=$swapFile bs=1M count=1025
mkswap -f $swapFile
swapon $swapFile
echo "$swapFile swap swap defaults 0 0" >> /etc/fstab
swap=`free |grep Swap|awk '{print $2}'`
if [ $swap -gt 1 ];then
KERNEL_MAJOR_VERSION=$(uname -r | cut -d '-' -f1 | awk -F. '{print $1}')
KERNEL_MINOR_VERSION=$(uname -r | cut -d '-' -f1 | awk -F. '{print $2}')
if [ -f "/etc/sysctl.conf" ]; then
sed -i "/vm.swappiness/d" /etc/sysctl.conf
fi
if [ "$KERNEL_MAJOR_VERSION" -lt 3 ]; then
sysctl -w vm.swappiness=1
echo "vm.swappiness=1" >> /etc/sysctl.conf
elif [ "$KERNEL_MAJOR_VERSION" = "3" ] && [ "$KERNEL_MINOR_VERSION" -lt 5 ]; then
sysctl -w vm.swappiness=1
echo "vm.swappiness=1" >> /etc/sysctl.conf
else
sysctl -w vm.swappiness=0
echo "vm.swappiness=0" >> /etc/sysctl.conf
fi
echo "Swap total sizse: $swap";
return;
fi
sed -i "/\/www\/swap/d" /etc/fstab
rm -f $swapFile
}
Service_Add(){
if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
chkconfig --add bt
chkconfig --level 2345 bt on
Centos9Check=$(cat /etc/redhat-release |grep ' 9')
if [ "${Centos9Check}" ];then
wget -O /usr/lib/systemd/system/btpanel.service ${download_Url}/init/systemd/btpanel.service
systemctl enable btpanel
fi
elif [ "${PM}" == "apt-get" ]; then
update-rc.d bt defaults
fi
}
Set_Centos7_Repo(){
# CN_YUM_URL=$(grep -E "aliyun|163|tencent|tsinghua" /etc/yum.repos.d/CentOS-Base.repo)
# if [ -z "${CN_YUM_URL}" ];then
# if [ -z "${download_Url}" ];then
# download_Url="http://download.bt.cn"
# fi
# curl -Ss --connect-timeout 3 -m 60 ${download_Url}/install/vault-repo.sh|bash
# return
# fi
MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "[^#]mirror.centos.org")
if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
fi
TSU_MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Base.repo |grep "tuna.tsinghua.edu.cn")
if [ "${TSU_MIRROR_CHECK}" ];then
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=https://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|baseurl=https://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|baseurl=http://mirrors.tuna.tsinghua.edu.cn|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
fi
ALI_CLOUD_CHECK=$(grep Alibaba /etc/motd)
Tencent_Cloud=$(cat /etc/hostname |grep -E VM-[0-9]+-[0-9]+)
if [ "${ALI_CLOUD_CHECK}" ] || [ "${Tencent_Cloud}" ];then
return
fi
yum install unzip -y
if [ "$?" != "0" ] ;then
TAR_CHECK=$(which tar)
if [ "$?" == "0" ] ;then
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
if [ -z "${download_Url}" ];then
download_Url="http://download.bt.cn"
fi
curl -Ss --connect-timeout 5 -m 60 -O ${download_Url}/src/el7repo.tar.gz
rm -f /etc/yum.repos.d/*.repo
tar -xvzf el7repo.tar.gz -C /etc/yum.repos.d/
fi
fi
yum install unzip -y
if [ "$?" != "0" ] ;then
sed -i "s/vault.epel.cloud/mirrors.cloud.tencent.com/g" /etc/yum.repos.d/*.repo
fi
}
Set_Centos8_Repo(){
HUAWEI_CHECK=$(cat /etc/motd |grep "Huawei Cloud")
if [ "${HUAWEI_CHECK}" ] && [ "${is64bit}" == "64" ];then
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
rm -f /etc/yum.repos.d/epel.repo
rm -f /etc/yum.repos.d/epel-*
fi
ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
if [ "${ALIYUN_CHECK}" ] && [ "${is64bit}" == "64" ] && [ ! -f "/etc/yum.repos.d/Centos-vault-8.5.2111.repo" ];then
rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
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
sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo
fi
MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Linux-AppStream.repo |grep "[^#]mirror.centos.org")
if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
fi
yum install unzip tar -y
if [ "$?" != "0" ] ;then
if [ -d "/etc/yum.repos.d" ];then
mkdir -p /etc/yum.repos.d
fi
if [ -z "${download_Url}" ];then
download_Url="http://download.bt.cn"
fi
if [ ! -f "/usr/bin/tar" ] || [ ! -f "/usr/sbin/tar" ];then
curl -Ss --connect-timeout 5 -m 60 -O ${download_Url}/src/tar-1.30-5.el8.x86_64.rpm
yum install tar-1.30-5.el8.x86_64.rpm -y
if [ "$?" != "0" ] ;then
rpm -ivh --nodeps --force tar-1.30-5.el8.x86_64.rpm
fi
fi
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
curl -Ss --connect-timeout 5 -m 60 -O ${download_Url}/src/el8repo.tar.gz
rm -f /etc/yum.repos.d/*.repo
tar -xvzf el8repo.tar.gz -C /etc/yum.repos.d/
fi
yum install unzip tar -y
if [ "$?" != "0" ] ;then
sed -i "s/vault.epel.cloud/mirrors.cloud.tencent.com/g" /etc/yum.repos.d/*.repo
fi
}
get_node_url(){
if [ "${PM}" = "yum" ]; then
yum install wget -y
if [ ! -f "/usr/sbin/wget" ] && [ ! -f "/usr/bin/wget" ];then
yum reinstall wget -y
fi
fi
if [ ! -f /bin/curl ];then
if [ "${PM}" = "yum" ]; then
yum install curl -y
elif [ "${PM}" = "apt-get" ]; then
apt-get install curl -y
fi
fi
if [ -f "/www/node.pl" ];then
download_Url=$(cat /www/node.pl)
echo "Download node: $download_Url";
echo '---------------------------------------------';
return
fi
echo '---------------------------------------------';
echo "Selected download node...";
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-cdn1.bt.cn);
CURL_CHECK=$(which curl)
if [ "$?" == "0" ];then
CN_CHECK=$(curl -sS --connect-timeout 10 -m 10 https://api.bt.cn/api/isCN)
if [ "${CN_CHECK}" == "True" ];then
nodes=(https://dg2.bt.cn https://download.bt.cn https://ctcc1-node.bt.cn https://cmcc1-node.bt.cn https://download-cdn1.bt.cn http://download-cdn1.bt.cn https://ctcc2-node.bt.cn https://hk1-node.bt.cn);
else
PING6_CHECK=$(ping6 -c 2 -W 2 download.bt.cn &> /dev/null && echo "yes" || echo "no")
if [ "${PING6_CHECK}" == "yes" ];then
nodes=(https://dg2.bt.cn https://download.bt.cn https://cf1-node.aapanel.com https://download-cdn1.bt.cn);
else
#nodes=(https://cf1-node.aapanel.com https://download.bt.cn https://na1-node.bt.cn https://jp1-node.bt.cn https://dg2.bt.cn);
nodes=(https://cf1-node.aapanel.com https://cf1-node.aapanel.com https://jp1-node.bt.cn https://download.bt.cn https://dg2.bt.cn https://download-cdn1.bt.cn);
fi
fi
fi
if [ "$1" ];then
nodes=($(echo ${nodes[*]}|sed "s#${1}##"))
fi
tmp_file1=/dev/shm/net_test1.pl
tmp_file2=/dev/shm/net_test2.pl
[ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
[ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
touch $tmp_file1
touch $tmp_file2
for node in ${nodes[@]};
do
if [ "${node}" == "https://cf1-node.aapanel.com" ];then
NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/1net_test|xargs)
else
NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
fi
RES=$(echo ${NODE_CHECK}|awk '{print $1}')
NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $2}')
TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $3 * 1000 - 500 }'|cut -d '.' -f 1)
if [ "${NODE_STATUS}" == "200" ];then
if [ $TIME_TOTAL -lt 300 ];then
if [ $RES -ge 1500 ];then
echo "$RES $node" >> $tmp_file1
fi
else
if [ $RES -ge 1500 ];then
echo "$TIME_TOTAL $node" >> $tmp_file2
fi
fi
i=$(($i+1))
if [ $TIME_TOTAL -lt 300 ];then
if [ $RES -ge 2390 ];then
break;
fi
fi
fi
done
NODE_URL=$(cat $tmp_file1|sort -r -g -t " " -k 1|head -n 1|awk '{print $2}')
if [ -z "$NODE_URL" ];then
NODE_URL=$(cat $tmp_file2|sort -g -t " " -k 1|head -n 1|awk '{print $2}')
if [ -z "$NODE_URL" ];then
NODE_URL='https://download.bt.cn';
fi
fi
rm -f $tmp_file1
rm -f $tmp_file2
download_Url=$NODE_URL
echo "Download node: $download_Url";
echo '---------------------------------------------';
}
Remove_Package(){
local PackageNmae=$1
if [ "${PM}" == "yum" ];then
isPackage=$(rpm -q ${PackageNmae}|grep "not installed")
if [ -z "${isPackage}" ];then
yum remove ${PackageNmae} -y
fi
elif [ "${PM}" == "apt-get" ];then
isPackage=$(dpkg -l|grep ${PackageNmae})
if [ "${PackageNmae}" ];then
apt-get remove ${PackageNmae} -y
fi
fi
}
Install_RPM_Pack(){
yumPath=/etc/yum.conf
CentosStream8Check=$(cat /etc/redhat-release |grep Stream|grep 8)
if [ "${CentosStream8Check}" ];then
MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Stream-AppStream.repo|grep "[^#]mirror.centos.org")
if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then
\cp -rpa /etc/yum.repos.d/ /etc/yumBak
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo
fi
fi
Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
if [ "${Centos8Check}" ];then
Set_Centos8_Repo
fi
Centos7Check=$(cat /etc/redhat-release | grep ' 7.' | grep -iE 'centos|Red Hat')
if [ "${Centos7Check}" ];then
Set_Centos7_Repo
fi
isExc=$(cat $yumPath|grep httpd)
if [ "$isExc" = "" ];then
echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >> $yumPath
fi
if [ -f "/etc/redhat-release" ] && [ $(cat /etc/os-release|grep PLATFORM_ID|grep -oE "el8") ];then
yum config-manager --set-enabled powertools
yum config-manager --set-enabled PowerTools
fi
if [ -f "/etc/redhat-release" ] && [ $(cat /etc/os-release|grep PLATFORM_ID|grep -oE "el9") ];then
dnf config-manager --set-enabled crb -y
fi
#SYS_TYPE=$(uname -a|grep x86_64)
#yumBaseUrl=$(cat /etc/yum.repos.d/CentOS-Base.repo|grep baseurl=http|cut -d '=' -f 2|cut -d '$' -f 1|head -n 1)
#[ "${yumBaseUrl}" ] && checkYumRepo=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${yumBaseUrl})
#if [ "${checkYumRepo}" != "200" ] && [ "${SYS_TYPE}" ];then
# curl -Ss --connect-timeout 3 -m 60 http://download.bt.cn/install/yumRepo_select.sh|bash
#fi
#尝试同步时间(从bt.cn)
echo 'Synchronizing system time...'
getBtTime=$(curl -sS --connect-timeout 3 -m 60 https://www.bt.cn/api/index/get_time)
if [ "${getBtTime}" ];then
date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"
fi
if [ -z "${Centos8Check}" ]; then
yum install ntp -y
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#尝试同步国际时间(从ntp服务器)
ntpdate 0.asia.pool.ntp.org
setenforce 0
fi
startTime=`date +%s`
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#yum remove -y python-requests python3-requests python-greenlet python3-greenlet
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 rsyslog net-tools firewalld"
yum install -y ${yumPacks}
for yumPack in ${yumPacks}
do
rpmPack=$(rpm -q ${yumPack})
packCheck=$(echo ${rpmPack}|grep not)
if [ "${packCheck}" ]; then
yum install ${yumPack} -y
fi
done
if [ -f "/usr/bin/dnf" ]; then
dnf install -y redhat-rpm-config
fi
# if [ ! -f "/usr/bin/mysql" ] && [ -f "/usr/sbin/mysql" ];then
# yum install
# fi
ALI_OS=$(cat /etc/redhat-release |grep "Alibaba Cloud Linux release 3")
if [ -z "${ALI_OS}" ];then
yum install epel-release -y
fi
}
Install_Deb_Pack(){
ln -sf bash /bin/sh
UBUNTU_22=$(cat /etc/issue|grep "Ubuntu 22")
UBUNTU_24=$(cat /etc/issue|grep "Ubuntu 24")
if [ "${UBUNTU_22}" ] || [ "${UBUNTU_24}" ];then
apt-get remove needrestart -y
fi
ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ")
if [ "${ALIYUN_CHECK}" ] && [ "${UBUNTU_22}" ];then
apt-get remove libicu70 -y
fi
apt-get update -y
FNOS_CHECK=$(cat /etc/issue|grep fnOS)
if [ "${FNOS_CHECK}" ];then
apt-get install libc6 --allow-change-held-packages -y
apt-get install libc6-dev --allow-change-held-packages -y
fi
apt-get install bash -y
if [ -f "/usr/bin/bash" ];then
ln -sf /usr/bin/bash /bin/sh
ln -sf /usr/bin/bash /usr/bin/sh
fi
apt-get install ruby -y
apt-get install lsb-release -y
#apt-get install ntp ntpdate -y
#/etc/init.d/ntp stop
#update-rc.d ntp remove
#cat >>~/.profile<<EOF
#TZ='Asia/Shanghai'; export TZ
#EOF
#rm -rf /etc/localtime
#cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#echo 'Synchronizing system time...'
#ntpdate 0.asia.pool.ntp.org
#apt-get upgrade -y
LIBCURL_VER=$(dpkg -l|grep libcurl4|awk '{print $3}')
if [ "${LIBCURL_VER}" == "7.68.0-1ubuntu2.8" ];then
apt-get remove libcurl4 -y
apt-get install curl -y
fi
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 rsyslog net-tools ufw";
apt-get install -y $debPacks --force-yes
for debPack in ${debPacks}
do
packCheck=$(dpkg -l|grep ${debPack})
if [ "$?" -ne "0" ] ;then
apt-get install -y $debPack
fi
done
if [ ! -f "/usr/bin/mysql" ] && [ -f "/usr/sbin/mysql" ];then
apt-get install mysql-client -y
fi
if [ ! -d '/etc/letsencrypt' ];then
mkdir -p /etc/letsencryp
mkdir -p /var/spool/cron
if [ ! -f '/var/spool/cron/crontabs/root' ];then
echo '' > /var/spool/cron/crontabs/root
chmod 600 /var/spool/cron/crontabs/root
fi
fi
}
Install_Other_Pack(){
if [ -f "/sbin/apk" ];then
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories
apk update
apk upgrade
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
LOCK_PIP="True"
fi
}
Get_Versions(){
redhat_version_file="/etc/redhat-release"
deb_version_file="/etc/issue"
if [[ $(grep Anolis /etc/os-release) ]] && [[ $(grep VERSION /etc/os-release|grep 8.8) ]];then
if [ -f "/usr/bin/yum" ];then
os_type="anolis"
os_version="8"
return
fi
fi
if [ -f "/etc/os-release" ];then
. /etc/os-release
OS_V=${VERSION_ID%%.*}
if [ "${ID}" == "opencloudos" ] && [[ "${OS_V}" =~ ^(9)$ ]];then
os_type="opencloudos"
os_version="9"
pyenv_tt="true"
elif { [ "${ID}" == "almalinux" ] || [ "${ID}" == "centos" ] || [ "${ID}" == "rocky" ]; } && [[ "${OS_V}" =~ ^(9|10)$ ]]; then
os_type="el"
os_version="9"
pyenv_tt="true"
elif [ "${ID}" == "alinux" ] && [[ "${OS_V}" =~ ^(4)$ ]];then
os_type="alinux"
os_version="4"
pyenv_tt="true"
fi
if [ "${pyenv_tt}" ];then
return
fi
fi
if [ -f $redhat_version_file ];then
os_type='el'
is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
if [ "$is_aliyunos" != "" ];then
return
fi
if [[ $(grep "Alibaba Cloud" /etc/redhat-release) ]] && [[ $(grep al8 /etc/os-release) ]];then
os_type="ali-linux-"
os_version="al8"
return
fi
if [[ $(grep "TencentOS Server" /etc/redhat-release|grep 3.1) ]];then
os_type="TencentOS-"
os_version="3.1"
return
fi
os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
if [ "${os_version}" = "5" ];then
os_version=""
fi
if [ -z "${os_version}" ];then
os_version=$(cat /etc/redhat-release |grep Stream|grep -oE 8)
fi
else
os_type='ubuntu'
os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
if [ "${os_version}" = "" ];then
os_type='debian'
os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
if [ "${os_version}" = "" ];then
os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
fi
if [ "${os_version}" = "8" ];then
os_version=""
fi
if [ "${is64bit}" = '32' ];then
os_version=""
fi
else
if [ "$os_version" = "14" ];then
os_version=""
fi
if [ "$os_version" = "12" ];then
os_version=""
fi
if [ "$os_version" = "19" ];then
os_version=""
fi
if [ "$os_version" = "21" ];then
os_version=""
fi
if [ "$os_version" = "20" ];then
os_version2004=$(cat /etc/issue|grep 20.04)
if [ -z "${os_version2004}" ];then
os_version=""
fi
fi
fi
fi
}
Install_Python_Lib(){
if [ -f "/www/server/panel/pyenv/bin/python3.7" ];then
python_file_date=$(date -r /www/server/panel/pyenv/bin/python3.7 +"%Y")
if [ "${python_file_date}" -lt "2021" ];then
rm -rf /www/server/panel/pyenv
fi
fi
curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
if [ "${LOCK_PIP}" ];then
if [ ! -d ~/.pip ];then
mkdir -p ~/.pip
fi
cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://mirrors.tencent.com/pypi/simple
[install]
trusted-host = mirrors.tencent.com
EOF
fi
pyenv_path="/www/server/panel"
if [ -f $pyenv_path/pyenv/bin/python ];then
is_ssl=$($python_bin -c "import ssl" 2>&1|grep cannot)
$pyenv_path/pyenv/bin/python3.7 -V
if [ $? -eq 0 ] && [ -z "${is_ssl}" ];then
chmod -R 700 $pyenv_path/pyenv/bin
is_package=$($python_bin -m psutil 2>&1|grep package)
if [ "$is_package" = "" ];then
wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 15
$pyenv_path/pyenv/bin/pip install -U pip
$pyenv_path/pyenv/bin/pip install -U setuptools==65.5.0
$pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
fi
source $pyenv_path/pyenv/bin/activate
chmod -R 700 $pyenv_path/pyenv/bin
return
else
rm -rf $pyenv_path/pyenv
fi
fi
is_loongarch64=$(uname -a|grep loongarch64)
if [ "$is_loongarch64" != "" ] && [ -f "/usr/bin/yum" ];then
yumPacks="python3-devel python3-pip python3-psutil python3-gevent python3-pyOpenSSL python3-paramiko python3-flask python3-rsa python3-requests python3-six python3-websocket-client"
yum install -y ${yumPacks}
for yumPack in ${yumPacks}
do
rpmPack=$(rpm -q ${yumPack})
packCheck=$(echo ${rpmPack}|grep not)
if [ "${packCheck}" ]; then
yum install ${yumPack} -y
fi
done
pip3 install -U pip
pip3 install Pillow psutil pyinotify pycryptodome upyun oss2 pymysql qrcode qiniu redis pymongo Cython configparser cos-python-sdk-v5 supervisor gevent-websocket pyopenssl
pip3 install flask==1.1.4
pip3 install Pillow -U
pyenv_bin=/www/server/panel/pyenv/bin
mkdir -p $pyenv_bin
ln -sf /usr/local/bin/pip3 $pyenv_bin/pip
ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3
ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3.7
if [ -f "/usr/bin/python3.7" ];then
ln -sf /usr/bin/python3.7 $pyenv_bin/python
ln -sf /usr/bin/python3.7 $pyenv_bin/python3
ln -sf /usr/bin/python3.7 $pyenv_bin/python3.7
elif [ -f "/usr/bin/python3.6" ]; then
ln -sf /usr/bin/python3.6 $pyenv_bin/python
ln -sf /usr/bin/python3.6 $pyenv_bin/python3
ln -sf /usr/bin/python3.6 $pyenv_bin/python3.7
fi
echo > $pyenv_bin/activate
return
fi
py_version="3.7.16"
mkdir -p $pyenv_path
echo "True" > /www/disk.pl
if [ ! -w /www/disk.pl ];then
Red_Error "ERROR: Install python env fielded." "ERROR: /www目录无法写入,请检查目录/用户/磁盘权限!"
fi
os_type='el'
os_version='7'
is_export_openssl=0
Get_Versions
echo "OS: $os_type - $os_version"
is_aarch64=$(uname -a|grep aarch64)
if [ "$is_aarch64" != "" ];then
is64bit="aarch64"
fi
if [ -f "/www/server/panel/pymake.pl" ];then
os_version=""
rm -f /www/server/panel/pymake.pl
fi
echo "==============================================="
echo "正在下载面板运行环境,请稍等..............."
echo "==============================================="
if [ "${os_version}" != "" ];then
pyenv_file="/www/pyenv.tar.gz"
#Download_File ${download_Url} ${backup_Url} "/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz" $pyenv_file
wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 20
if [ "$?" != "0" ];then
get_node_url $download_Url
wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 20
fi
tmp_size=$(du -b $pyenv_file|awk '{print $1}')
if [ $tmp_size -lt 703460 ];then
rm -f $pyenv_file
echo "ERROR: Download python env fielded."
else
echo "Install python env..."
tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null
chmod -R 700 $pyenv_path/pyenv/bin
if [ ! -f $pyenv_path/pyenv/bin/python ];then
rm -f $pyenv_file
Red_Error "ERROR: Install python env fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
fi
$pyenv_path/pyenv/bin/python3.7 -V
if [ $? -eq 0 ];then
rm -f $pyenv_file
ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
source $pyenv_path/pyenv/bin/activate
return
else
rm -f $pyenv_file
rm -rf $pyenv_path/pyenv
fi
fi
fi
cd /www
python_src='/www/python_src.tar.xz'
python_src_path="/www/Python-${py_version}"
wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 15
tmp_size=$(du -b $python_src|awk '{print $1}')
if [ $tmp_size -lt 10703460 ];then
rm -f $python_src
Red_Error "ERROR: Download python source code fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!"
fi
tar xvf $python_src
rm -f $python_src
cd $python_src_path
./configure --prefix=$pyenv_path/pyenv
make -j$cpu_cpunt
make install
if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
rm -rf $python_src_path
Red_Error "ERROR: Make python env fielded." "ERROR: 编译宝塔运行环境失败!"
fi
cd ~
rm -rf $python_src_path
wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 20
wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.16.txt -T 20
ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
chmod -R 700 $pyenv_path/pyenv/bin
$pyenv_path/pyenv/bin/pip install -U pip
$pyenv_path/pyenv/bin/pip install -U setuptools==65.5.0
$pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
$pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
wget -O pip-packs.txt $download_Url/install/pyenv/pip-packs.txt
echo "正在后台安装pip依赖请稍等.........."
PIP_PACKS=$(cat pip-packs.txt)
for P_PACK in ${PIP_PACKS};
do
btpip show ${P_PACK} > /dev/null 2>&1
if [ "$?" == "1" ];then
btpip install ${P_PACK}
fi
done
rm -f pip-packs.txt
source $pyenv_path/pyenv/bin/activate
btpip install psutil
btpip install gevent
is_gevent=$($python_bin -m gevent 2>&1|grep -oE package)
is_psutil=$($python_bin -m psutil 2>&1|grep -oE package)
if [ "${is_gevent}" != "${is_psutil}" ];then
Red_Error "ERROR: psutil/gevent install failed!"
fi
}
Install_Bt(){
if [ -f ${setup_path}/server/panel/data/port.pl ];then
panelPort=$(cat ${setup_path}/server/panel/data/port.pl)
fi
if [ "${PANEL_PORT}" ];then
panelPort=$PANEL_PORT
fi
mkdir -p ${setup_path}/server/panel/logs
mkdir -p ${setup_path}/server/panel/vhost/apache
mkdir -p ${setup_path}/server/panel/vhost/nginx
mkdir -p ${setup_path}/server/panel/vhost/rewrite
mkdir -p ${setup_path}/server/panel/install
mkdir -p /www/server
mkdir -p /www/wwwroot
mkdir -p /www/wwwlogs
mkdir -p /www/backup/database
mkdir -p /www/backup/site
if [ ! -d "/etc/init.d" ];then
mkdir -p /etc/init.d
fi
if [ -f "/etc/init.d/bt" ]; then
/etc/init.d/bt stop
sleep 1
fi
# 使用本地初始化脚本
cp /www/server/panel/install/src/bt6.init /etc/init.d/bt
cp /www/server/panel/install/src/bt7.init /etc/init.d/bt
cp /www/server/panel/install/public.sh /www/server/panel/install/public.sh
echo "=============================================="
echo "使用本地宝塔面板源码进行安装............"
echo "=============================================="
# 检查本地源码是否存在(Docker构建时已复制)
if [ ! -d "${setup_path}/server/panel" ]; then
Red_Error "ERROR: Local panel source not found!" "ERROR: 本地宝塔源码不存在,请确保已复制到 ${setup_path}/server/panel"
fi
# 备份现有数据(如果有)
if [ -f "${setup_path}/server/panel/data/default.db" ];then
if [ -d "/${setup_path}/server/panel/old_data" ];then
rm -rf ${setup_path}/server/panel/old_data
fi
mkdir -p ${setup_path}/server/panel/old_data
d_format=$(date +"%Y%m%d_%H%M%S")
\cp -arf ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/data/default_backup_${d_format}.db
mv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.db
mv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.db
mv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.pl
mv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.pl
if [ -d "${setup_path}/server/panel/data/db" ];then
\cp -r ${setup_path}/server/panel/data/db ${setup_path}/server/panel/old_data/
fi
fi
# 恢复数据(如果有备份)
if [ -d "${setup_path}/server/panel/old_data" ];then
mv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.db
mv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.db
mv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.pl
mv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.pl
if [ -d "${setup_path}/server/panel/old_data/db" ];then
\cp -r ${setup_path}/server/panel/old_data/db ${setup_path}/server/panel/data/
fi
if [ -d "/${setup_path}/server/panel/old_data" ];then
rm -rf ${setup_path}/server/panel/old_data
fi
fi
# 检查关键文件是否存在
if [ ! -f ${setup_path}/server/panel/tools.py ] || [ ! -f ${setup_path}/server/panel/BT-Panel ];then
Red_Error "ERROR: Local panel source is incomplete!" "ERROR: 本地宝塔源码不完整,缺少关键文件!"
fi
SYS_LOG_CHECK=$(grep ^weekly /etc/logrotate.conf)
if [ "${SYS_LOG_CHECK}" ];then
sed -i 's/rotate [0-9]*/rotate 8/g' /etc/logrotate.conf
fi
rm -f ${setup_path}/server/panel/class/*.pyc
rm -f ${setup_path}/server/panel/*.pyc
chmod +x /etc/init.d/bt
chmod -R 600 ${setup_path}/server/panel
chmod -R +x ${setup_path}/server/panel/script
chmod -R 700 $pyenv_path/pyenv/bin
ln -sf /etc/init.d/bt /usr/bin/bt
chmod +x /www/server/panel/script/btcli.py
ln -sf /www/server/panel/script/btcli.py /usr/bin/btcli
echo "${panelPort}" > ${setup_path}/server/panel/data/port.pl
# 使用本地初始化脚本和配置文件
cp /www/server/panel/install/src/bt7.init /etc/init.d/bt
cp /www/server/panel/install/src/bt7.init /www/server/panel/init.sh
if [ -f "/www/server/panel/config/default_soft_list.conf" ];then
\cp -rpa /www/server/panel/config/default_soft_list.conf /www/server/panel/data/softList.conf
else
cp /www/server/panel/install/conf/softList.conf /www/server/panel/data/softList.conf
fi
rm -rf /www/server/panel/plugin/webssh/
if [ ! -f "${setup_path}/server/panel/data/installCount.pl" ];then
echo "1 $(date)" > ${setup_path}/server/panel/data/installCount.pl
elif [ -f "${setup_path}/server/panel/data/installCount.pl" ];then
INSTALL_COUNT=$(cat ${setup_path}/server/panel/data/installCount.pl|awk '{last=$1} END {print last}')
echo "$((INSTALL_COUNT+1)) $(date)" >> ${setup_path}/server/panel/data/installCount.pl
fi
}
Set_Bt_Panel(){
Run_User="www"
wwwUser=$(cat /etc/passwd|cut -d ":" -f 1|grep ^www$)
if [ "${wwwUser}" != "www" ];then
groupadd ${Run_User}
useradd -s /sbin/nologin -g ${Run_User} ${Run_User}
fi
password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
if [ "$PANEL_PASSWORD" ];then
password=$PANEL_PASSWORD
fi
sleep 1
admin_auth="/www/server/panel/data/admin_path.pl"
if [ "${SAFE_PATH}" ];then
auth_path=$SAFE_PATH
echo "/${auth_path}" > ${admin_auth}
elif [ ! -f ${admin_auth} ];then
auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
echo "/${auth_path}" > ${admin_auth}
fi
btpip install asn1crypto==1.5.1 cbor2==5.4.6
if [ ! -f "/www/server/panel/pyenv/n.pl" ];then
btpip install docxtpl==0.16.7
/www/server/panel/pyenv/bin/pip3 install pymongo
/www/server/panel/pyenv/bin/pip3 install psycopg2-binary
/www/server/panel/pyenv/bin/pip3 install flask -U
/www/server/panel/pyenv/bin/pip3 install flask-sock
/www/server/panel/pyenv/bin/pip3 install -I gevent
btpip install simple-websocket==0.10.0
btpip install natsort
btpip uninstall enum34 -y
btpip install geoip2==4.7.0
btpip install brotli
btpip install PyMySQL
fi
auth_path=$(cat ${admin_auth})
cd ${setup_path}/server/panel/
/etc/init.d/bt start
if [ "${BT_TIMEZONE}" ];then
timezone_zone=$(echo "$BT_TIMEZONE" | cut -d'/' -f1)
timezone_area=$(echo "$BT_TIMEZONE" | cut -d'/' -f2)
if [ -n "$timezone_zone" ] && [ -n "$timezone_area" ];then
target_path="/usr/share/zoneinfo/${timezone_zone}/${timezone_area}"
if [ -f "$target_path" ] || [ -L "$target_path" ];then
ln -sf "$target_path" /etc/localtime
echo "${timezone_zone}/${timezone_area}" > /etc/timezone 2>/dev/null
btpython -c "import time; time.tzset()"
panel_sqlite="/www/server/panel/data/default.db"
if [ -f "$panel_sqlite" ];then
btpython - <<EOF
import sqlite3
import json
conn = sqlite3.connect('$panel_sqlite', timeout=1)
cursor = conn.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='config'")
if cursor.fetchone():
cursor.execute("SELECT v FROM config WHERE k='time'")
row = cursor.fetchone()
if row:
cursor.execute("UPDATE config SET v=? WHERE k='time'", (json.dumps({"zone":"$timezone_zone","area":"$timezone_area"}),))
else:
cursor.execute("INSERT INTO config (k,v) VALUES ('time', ?)", (json.dumps({"zone":"$timezone_zone","area":"$timezone_area"}),))
conn.commit()
conn.close()
EOF
fi
echo "[BT-PANEL] 时区已设置为: $BT_TIMEZONE"
else
echo "[BT-PANEL] 时区文件不存在: $target_path,使用系统默认"
fi
fi
fi
$python_bin -m py_compile tools.py
$python_bin tools.py username
username=$($python_bin tools.py panel ${password})
if [ "$PANEL_USER" ];then
username=$PANEL_USER
fi
cd ~
echo "${password}" > ${setup_path}/server/panel/default.pl
chmod 600 ${setup_path}/server/panel/default.pl
sleep 3
if [ "$SET_SSL" == true ]; then
if [ ! -f "/www/server/panel/pyenv/n.pl" ];then
btpip install -I pyOpenSSl 2>/dev/null
fi
# echo "========================================"
# echo "正在开启面板SSL,请稍等............ "
# echo "========================================"
SSL_STATUS=$(btpython /www/server/panel/tools.py ssl)
if [ "${SSL_STATUS}" == "0" ] ;then
echo -n " -4 " > /www/server/panel/data/v4.pl
btpython /www/server/panel/tools.py ssl
fi
# echo "证书开启成功!"
# echo "========================================"
fi
# btpip install Flask-SQLAlchemy==2.5.1 SQLAlchemy==1.3.24
/etc/init.d/bt stop
sleep 5
if [ ! -f "/www/server/panel/data/port.pl" ];then
echo "8888" > /www/server/panel/data/port.pl
fi
/etc/init.d/bt start
sleep 5
isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}')
if [ -f "/www/server/panel/data/ssl.pl" ];then
LOCAL_CURL=$(curl -k https://127.0.0.1:${panelPort}/login 2>&1 |grep -i html)
else
LOCAL_CURL=$(curl 127.0.0.1:${panelPort}/login 2>&1 |grep -i html)
fi
if [ -z "${isStart}" ] && [ -z "${LOCAL_CURL}" ];then
/etc/init.d/bt restart
sleep 5
isStart=$(ps -ef|grep /www/server/panel/BT-Panel|grep -v grep)
if [ -z "${isStart}" ];then
#/etc/init.d/bt 22
cd /www/server/panel/pyenv/bin
touch t.pl
ls -al python3.7 python
lsattr python3.7 python
if [ -f "/www/server/panel/pyenv/bin/python3.7" ];then
/www/server/panel/pyenv/bin/python3.7 -c "print('test')"
/www/server/panel/pyenv/bin/python3.7 -V
ls -la /www/server/panel/pyenv/lib/python3.7/encodings*|grep utf|grep 8
fi
# btpython /www/server/panel/BT-Panel
Red_Error "ERROR: The BT-Panel service startup failed." "ERROR: 宝塔启动失败"
fi
fi
# wget -O oneav_bt.sh https://download.bt.cn/install/plugin/oneav/install.sh > /dev/null 2>&1
# bash oneav_bt.sh install > /www/server/panel/install//btinstall.log 2>&1
# rm -f oneav_bt.sh
if [ "$PANEL_USER" ];then
cd ${setup_path}/server/panel/
btpython -c 'import tools;tools.set_panel_username("'$PANEL_USER'")'
cd ~
fi
if [ -f "/usr/bin/sqlite3" ] ;then
sqlite3 /www/server/panel/data/db/panel.db "UPDATE config SET status = '1' WHERE id = '1';" > /dev/null 2>&1
fi
}
Set_Firewall(){
sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')
if [ "${PM}" = "apt-get" ]; then
#apt-get install -y ufw
if [ -f "/usr/sbin/ufw" ];then
if [ "${PANEL_PORT}" ];then
ufw allow ${PANEL_PORT}/tcp
fi
ufw allow 20/tcp
ufw allow 21/tcp
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 888/tcp
ufw allow 8888/tcp
ufw allow ${panelPort}/tcp
ufw allow ${sshPort}/tcp
ufw allow 39000:40000/tcp
ufw_status=`ufw status`
echo y|ufw enable
ufw default deny
ufw reload
fi
else
if [ -f "/etc/init.d/iptables" ];then
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
#iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
iptables -A INPUT -s localhost -d localhost -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -P INPUT DROP
service iptables save
sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
iptables_status=$(service iptables status | grep 'not running')
if [ "${iptables_status}" == '' ];then
service iptables restart
fi
else
AliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux")
[ "${AliyunCheck}" ] && return
#yum install firewalld -y
[ "${Centos8Check}" ] && yum reinstall python3-six -y
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --set-default-zone=public > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=20/tcp > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=21/tcp > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=80/tcp > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=443/tcp > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=8888/tcp > /dev/null 2>&1
if [ "${PANEL_PORT}" ];then
firewall-cmd --permanent --zone=public --add-port=${PANEL_PORT}/tcp > /dev/null 2>&10
fi
firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1
firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp > /dev/null 2>&1
#firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
firewall-cmd --reload
fi
fi
}
Get_Ip_Address(){
getIpAddress=""
#getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
ipv4_address=""
ipv6_address=""
ipv4_address=$(curl -4 -sS --connect-timeout 4 -m 5 https://api.bt.cn/Api/getIpAddress 2>&1)
if [ -z "${ipv4_address}" ];then
ipv4_address=$(curl -4 -sS --connect-timeout 4 -m 5 https://www.bt.cn/Api/getIpAddress 2>&1)
if [ -z "${ipv4_address}" ];then
ipv4_address=$(curl -4 -sS --connect-timeout 4 -m 5 https://www.aapanel.com/api/common/getClientIP 2>&1)
fi
fi
IPV4_REGEX="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
if ! [[ $ipv4_address =~ $IPV4_REGEX ]]; then
ipv4_address=""
fi
ipv6_address=$(curl -6 -sS --connect-timeout 4 -m 5 https://www.bt.cn/Api/getIpAddress 2>&1)
IPV6_REGEX="^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$"
if ! [[ $ipv6_address =~ $IPV6_REGEX ]]; then
ipv6_address=""
else
if [[ ! $ipv6_address =~ ^\[ ]]; then
ipv6_address="[$ipv6_address]"
fi
fi
if [ "${ipv4_address}" ];then
getIpAddress=$ipv4_address
elif [ "${ipv6_address}" ];then
getIpAddress=$ipv6_address
fi
if [ -z "${getIpAddress}" ] || [ "${getIpAddress}" = "0.0.0.0" ]; then
isHosts=$(cat /etc/hosts|grep 'www.bt.cn')
if [ -z "${isHosts}" ];then
echo "" >> /etc/hosts
echo "116.213.43.206 www.bt.cn" >> /etc/hosts
getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
if [ -z "${getIpAddress}" ];then
sed -i "/bt.cn/d" /etc/hosts
fi
fi
fi
CN_CHECK=$(curl -sS --connect-timeout 10 -m 10 https://api.bt.cn/api/isCN)
if [ "${CN_CHECK}" == "True" ];then
echo "True" > /www/server/panel/data/domestic_ip.pl
else
echo "True" > /www/server/panel/data/foreign_ip.pl
fi
ipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")
if [ "${ipv4Check}" == "None" ];then
ipv6Address=$(echo ${getIpAddress}|tr -d "[]")
ipv6Check=$($python_bin -c "import re; print(re.match('^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))")
if [ "${ipv6Check}" == "None" ]; then
getIpAddress="SERVER_IP"
else
echo "True" > ${setup_path}/server/panel/data/ipv6.pl
sleep 1
/etc/init.d/bt restart
getIpAddress=$(echo "[$getIpAddress]")
fi
fi
if [ "${getIpAddress}" != "SERVER_IP" ];then
echo "${getIpAddress}" > ${setup_path}/server/panel/data/iplist.txt
fi
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)
}
Setup_Count(){
curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/SetupCount?type=Linux\&o=$1 > /dev/null 2>&1
if [ "$1" != "" ];then
echo $1 > /www/server/panel/data/o.pl
cd /www/server/panel
$python_bin tools.py o
fi
echo /www > /var/bt_setupPath.conf
}
Start_Count(){
curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/SetupCountPre?type=Linux\&o=$1 > /dev/null 2>&1
echo /www > /var/bt_setupPath.conf
echo "check_certificate = off" >> /etc/wgetrc
}
Start_Ip_Cert_Async(){
IP_SSL_PID=""
if [ -z "${ipv4_address}" ];then
return
fi
if [ "$SET_SSL" == "true" ];then
if [ -f "/www/server/panel/script/auto_apply_ip_ssl.py" ];then
acme_connect_url="https://acme-v02.api.letsencrypt.org"
acme_http_code=$(curl -sS --connect-timeout 2 -m 60 -o /dev/null -w "%{http_code}" "$acme_connect_url")
if [ "$acme_http_code" == "200" ];then
echo "正在后台开启受信任宝塔面板ip证书..."
(
timeout 60 $pyenv_path/pyenv/bin/python3.7 /www/server/panel/script/auto_apply_ip_ssl.py -ips ${ipv4_address} -path /www/server/panel/ssl > /tmp/auto_apply_ip_ssl.log 2>&1
echo $? > /tmp/ip_ssl_exit_code.pl
) &
IP_SSL_PID=$!
fi
fi
fi
}
Check_Ip_Cert_Async(){
if [ "$SET_SSL" != "true" ];then
return
fi
if [ -z "$IP_SSL_PID" ]; then
if [ "$acme_http_code" != "200" ];then
echo "受信ip证书申请失败,exit code=$acme_http_code"
echo "转为使用默认自签证书,后续可手动在面板设置中重新使用Let's encrypt申请ip证书"
return
fi
echo "受信宝塔面板ip证书开启成功"
/etc/init.d/bt restart
return
fi
echo "正在检查受信宝塔面板ip证书开启状态..."
wait $IP_SSL_PID
if [ -f "/tmp/ip_ssl_exit_code.pl" ]; then
rc=$(cat /tmp/ip_ssl_exit_code.pl)
rm -f /tmp/ip_ssl_exit_code.pl
else
rc=1
fi
if [ $rc -eq 0 ]; then
echo "受信宝塔面板ip证书开启成功"
/etc/init.d/bt restart
elif [ $rc -eq 124 ]; then
echo "受信ip证书申请超时(60秒)"
echo "转为使用默认自签证书,后续可手动在面板设置中重新使用Let's encrypt申请ip证书"
else
echo "受信ip证书申请失败,exit code=$rc"
echo "转为使用默认自签证书,后续可手动在面板设置中重新使用Let's encrypt申请ip证书"
fi
}
Install_Main(){
Ready_Check
Start_Count ${IDC_CODE}
Set_Ssl
startTime=`date +%s`
Lock_Clear
System_Check
Get_Pack_Manager
Set_Repo_Url
Check_And_Fix_Debian_Ubuntu_Source
get_node_url
MEM_TOTAL=$(free -g|grep Mem|awk '{print $2}')
if [ "${MEM_TOTAL}" -le "1" ];then
Auto_Swap
fi
if [ "${PM}" = "yum" ]; then
Install_RPM_Pack
elif [ "${PM}" = "apt-get" ]; then
Install_Deb_Pack
else
Install_Other_Pack
fi
Set_Firewall
Install_Python_Lib
Install_Bt
Get_Ip_Address
Start_Ip_Cert_Async
Set_Bt_Panel
Service_Add
Check_Ip_Cert_Async
Setup_Count ${IDC_CODE}
#Add_lib_Install
}
echo "
+----------------------------------------------------------------------
| Bt-WebPanel FOR CentOS/Ubuntu/Debian
+----------------------------------------------------------------------
| Copyright © 2015-2099 BT-SOFT(http://www.bt.cn) All rights reserved.
+----------------------------------------------------------------------
| The WebPanel URL will be http://SERVER_IP:${panelPort} when installed.
+----------------------------------------------------------------------
| 为了您的正常使用,请确保使用全新或纯净的系统安装宝塔面板,不支持已部署项目/环境的系统安装
+----------------------------------------------------------------------
"
while [ ${#} -gt 0 ]; do
case $1 in
-u|--user)
PANEL_USER=$2
shift 1
;;
-p|--password)
PANEL_PASSWORD=$2
shift 1
;;
-P|--port)
PANEL_PORT=$2
shift 1
;;
--safe-path)
SAFE_PATH=$2
shift 1
;;
--ssl-disable)
SSL_PL="disable"
;;
-y)
go="y"
;;
*)
IDC_CODE=$1
;;
esac
shift 1
done
while [ "$go" != 'y' ] && [ "$go" != 'n' ]
do
read -p "Do you want to install Bt-Panel to the $setup_path directory now?(y/n): " go;
done
if [ "$go" == 'n' ];then
exit;
fi
if [ -f "/www/server/panel/BT-Panel" ];then
AAPANEL_CHECK=$(grep www.aapanel.com /www/server/panel/BT-Panel)
if [ "${AAPANEL_CHECK}" ];then
echo -e "----------------------------------------------------"
echo -e "检查已安装有aapanel,无法进行覆盖安装宝塔面板"
echo -e "如继续执行安装将移去aapanel面板数据(备份至/www/server/aapanel路径) 全新安装宝塔面板"
echo -e "aapanel is alreday installed,Can't install panel"
echo -e "is install Baota panel, aapanel data will be removed (backed up to /www/server/aapanel)"
echo -e "Beginning new Baota panel installation."
echo -e "----------------------------------------------------"
echo -e "已知风险/Enter yes to force installation"
read -p "输入yes开始安装: " yes;
if [ "$yes" != "yes" ];then
echo -e "------------"
echo "取消安装"
exit;
fi
bt stop
sleep 1
mv /www/server/panel /www/server/aapanel
fi
fi
ARCH_LINUX=$(cat /etc/os-release |grep "Arch Linux")
if [ "${ARCH_LINUX}" ] && [ -f "/usr/bin/pacman" ];then
pacman -Sy
pacman -S curl wget unzip firewalld openssl pkg-config make gcc cmake libxml2 libxslt libvpx gd libsodium oniguruma sqlite libzip autoconf inetutils sudo --noconfirm
fi
CURL_CHECK=$(which curl)
if [ "$?" == "0" ] && [ ! -f "/tmp/btpanel_err.pl" ];then
getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
INSTALL_DATE=$(date +%Y%m%d)
curl -sS --connect-timeout 3 -m 3 --request POST --url "https://www.bt.cn/Api/installationCount" --data "date=${INSTALL_DATE}" --data "status=0" --data "ip=${getIpAddress}" > /dev/null
fi
Install_Main
PANEL_SSL=$(cat /www/server/panel/data/ssl.pl 2> /dev/null)
if [ "${PANEL_SSL}" == "True" ];then
HTTP_S="https"
else
HTTP_S="http"
fi
echo "安装基础网站流量统计程序..."
wget -O site_new_total.sh ${download_Url}/site_total/install.sh &> /dev/null
bash site_new_total.sh &> /dev/null
rm -f site_new_total.sh
echo "安装基础网站流量统计程序完成"
echo > /www/server/panel/data/bind.pl
echo -e "=================================================================="
echo -e "\033[32mCongratulations! Installed successfully!\033[0m"
#echo -e "=============注意:首次打开面板浏览器如果提示不安全,可以尝试下面的解决方案================="
#echo -e ""
#echo -e " 请选择以下其中一种方式解决不安全提醒"
#echo -e " 1、下载证书,地址:https://dg2.bt.cn/ssl/baota_root.pfx,双击安装,密码【www.bt.cn】"
#echo -e " 2、点击【高级】-【继续访问】或【接受风险并继续】访问"
#echo -e " 教程:https://www.bt.cn/bbs/thread-117246-1-1.html"
#echo -e " mac用户请下载使用此证书:https://dg2.bt.cn/ssl/mac.crt"
echo -e ""
echo -e "========================面板账户登录信息=========================="
echo -e ""
echo -e " 【云服务器】请在安全组放行 $panelPort 端口"
if [ -z "${ipv4_address}" ] && [ -z "${ipv6_address}" ];then
echo -e " 外网面板地址: ${HTTP_S}://SERVER_IP:${panelPort}${auth_path}"
fi
if [ "${ipv4_address}" ];then
echo -e " 外网ipv4面板地址: ${HTTP_S}://${ipv4_address}:${panelPort}${auth_path}"
fi
if [ "${ipv6_address}" ];then
echo -e " 外网ipv6面板地址: ${HTTP_S}://${ipv6_address}:${panelPort}${auth_path}"
fi
echo -e " 内网面板地址: ${HTTP_S}://${LOCAL_IP}:${panelPort}${auth_path}"
echo -e " username: $username"
echo -e " password: $password"
echo -e ""
echo -e " 浏览器访问以下链接,添加宝塔客服"
echo -e " https://www.bt.cn/new/wechat_customer"
echo -e "=================================================================="
endTime=`date +%s`
((outTime=($endTime-$startTime)/60))
if [ "${outTime}" -le "5" ];then
echo ${download_Url} > /www/server/panel/install/d_node.pl
fi
if [ "${outTime}" == "0" ];then
((outTime=($endTime-$startTime)))
echo -e "Time consumed:\033[32m $outTime \033[0mseconds!"
else
echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"
fi
if [ "${INSTALL_DATE}" ];then
curl -sS --connect-timeout 7 -m 7 --retry 2 --request POST --url "https://www.bt.cn/Api/installationCount" --data "date=${INSTALL_DATE}" --data "status=1" --data "ip=${getIpAddress}" > /dev/null
fi
# if [ "${INSTALL_DATE}" ];then
# curl -sS --connect-timeout 7 -m 7 --retry 2 --request POST --url "https://www.bt.cn/Api/installationCount" --data "date=${INSTALL_DATE}" --data "status=1" --data "ip=${getIpAddress}" > /dev/null
# if [ $? -eq 0 ];then
# curl -sS --connect-timeout 7 -m 7 --retry 2 --request POST --url "https://www-node3.bt.cn/Api/installationCount" --data "date=${INSTALL_DATE}" --data "status=1" --data "ip=${getIpAddress}" > /dev/null
# fi
# fi
|