#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH LANG=en_US.UTF-8 INSTALL_LOGFILE="/tmp/btpanel-install.log" # exec > >(tee -a "$INSTALL_LOGFILE") 2>&1 Btapi_Url='http://v920.hostcli.com' Check_Api=$(curl -Ss --connect-timeout 5 -m 2 $Btapi_Url/api/SetupCount) if [ "$Check_Api" != 'ok' ];then Red_Error "此宝塔第三方云端无法连接,因此安装过程已中止!"; fi if [ $(whoami) != "root" ];then echo "请使用root权限执行宝塔安装命令!" exit 1; fi 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}不支持安装宝塔面板,建议更换Ubuntu22/24安装宝塔面板" exit 1 fi HOSTNAME_CHECK=$(cat /etc/hostname) if [ -z "${HOSTNAME_CHECK}" ];then 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 "8 |9 ") if [ "${DEBIAN_9_C}" ];then echo "当前您使用的Debian-8/9,官方已经停止支持、无法进行宝塔面板的安装" echo "请使用Debian-11/12进行安装宝塔面板" 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 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) echo -e ${SYS_VERSION} echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO} echo -e ${SYS_INFO} echo -e "============================================" echo -e "请截图以上报错信息到Telegram群求助 https://tg.HostCLi.com " 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 } 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(){ Get_Versions if [ "${os_type}" == "el" ] && [ "${os_version}" == "7" ];then cd /www/server/panel/class #btpython -c "import panelPlugin; plugin = panelPlugin.panelPlugin(); plugin.check_install_lib('1')" #echo "True" > /tmp/panelTask.pl fi } Get_Pack_Manager(){ PM="apt-get" } Service_Add(){ update-rc.d bt defaults } 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://v920.hostcli.com" # 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://v920.hostcli.com" 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_Centos7_Repo(){ # if [ -z "${download_Url}" ];then # download_Url="http://v920.hostcli.com" # fi # curl -Ss --connect-timeout 3 -m 60 ${download_Url}/install/vault-repo.sh|bash # } 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 [ -z "${download_Url}" ];then download_Url="http://v920.hostcli.com" fi if [ ! -f "/usr/bin/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 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 -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 [ ! -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=(http://v920.hostcli.com http://v920.hostcli.com); CURL_CHECK=$(which curl) if [ "$?" == "0" ];then CN_CHECK=$(curl -sS --connect-timeout 10 -m 10 http://v920.hostcli.com/api/isCN) if [ "${CN_CHECK}" == "True" ];then nodes=(http://v920.hostcli.com/ http://v920.hostcli.com http://v920.hostcli.com/ http://v920.hostcli.com/ http://v920.hostcli.com/ http://v920.hostcli.com/); 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 NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs) 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='http://v920.hostcli.com'; 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_Deb_Pack(){ ln -sf bash /bin/sh UBUNTU_22=$(cat /etc/issue|grep "Ubuntu 22") if [ "${UBUNTU_22}" ];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 apt-get install bash -y if [ -f "/usr/bin/bash" ];then ln -sf /usr/bin/bash /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"; 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 [ ! -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 } 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)$ ]]; then os_type="el" os_version="9" 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(){ curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash 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 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" wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 15 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 15 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 5 wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.16.txt -T 5 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 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 wget -O /etc/init.d/bt ${download_Url}/install/src/bt6.init -T 15 wget -O /www/server/panel/install/public.sh ${Btapi_Url}/install/public.sh -T 15 echo "==============================================" echo "正在下载面板文件,请稍等..................." echo "==============================================" wget -O panel.zip ${Btapi_Url}/install/src/panel6.zip -T 15 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 [ ! -f "/usr/bin/unzip" ]; then if [ "${PM}" = "yum" ]; then yum install unzip -y elif [ "${PM}" = "apt-get" ]; then apt-get update apt-get install unzip -y fi fi unzip -o panel.zip -d ${setup_path}/server/ > /dev/null 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 ls -lh panel.zip Red_Error "ERROR: Failed to download, please try install again!" "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 panel.zip 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 ln -sf /etc/init.d/bt /usr/bin/bt echo "${panelPort}" > ${setup_path}/server/panel/data/port.pl wget -O /etc/init.d/bt ${download_Url}/install/src/bt7.init -T 15 wget -O /www/server/panel/init.sh ${download_Url}/install/src/bt7.init -T 15 wget -O /www/server/panel/data/softList.conf ${download_Url}/install/conf/softList.conf rm -f /www/server/panel/class/*.so if [ ! -f /www/server/panel/data/not_workorder.pl ]; then echo "True" > /www/server/panel/data/not_workorder.pl fi if [ ! -f /www/server/panel/data/userInfo.json ]; then echo "{\"uid\":1,\"username\":\"Administrator\",\"address\":\"127.0.0.1\",\"serverid\":\"1\",\"access_key\":\"test\",\"secret_key\":\"123456\",\"ukey\":\"123456\",\"state\":1}" > /www/server/panel/data/userInfo.json fi if [ ! -f /www/server/panel/data/panel_nps.pl ]; then echo "" > /www/server/panel/data/panel_nps.pl fi if [ ! -f /www/server/panel/data/btwaf_nps.pl ]; then echo "" > /www/server/panel/data/btwaf_nps.pl fi if [ ! -f /www/server/panel/data/tamper_proof_nps.pl ]; then echo "" > /www/server/panel/data/tamper_proof_nps.pl fi if [ ! -f /www/server/panel/data/total_nps.pl ]; then echo "" > /www/server/panel/data/total_nps.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 [ ! -f ${admin_auth} ];then auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8) echo "/${auth_path}" > ${admin_auth} fi if [ "${SAFE_PATH}" ];then auth_path=$SAFE_PATH echo "/${auth_path}" > ${admin_auth} fi chmod -R 700 $pyenv_path/pyenv/bin 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 $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 /etc/init.d/bt stop sleep 5 /etc/init.d/bt start sleep 5 isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}') LOCAL_CURL=$(curl 127.0.0.1:${panelPort}/login 2>&1 |grep -i html) 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 Red_Error "ERROR: The BT-Panel service startup failed." "ERROR: 宝塔启动失败" fi 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}') apt-get install -y ufw if [ -f "/usr/sbin/ufw" ];then 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 ${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 } Get_Ip_Address(){ REMOTE_IP=$(curl ipinfo.io/ip) echo "${REMOTE_IP}" > ${setup_path}/server/panel/data/iplist.txt 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 http://v920.hostcli.com/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 } Install_Main(){ #Set_Ssl startTime=`date +%s` Lock_Clear System_Check Get_Pack_Manager get_node_url Install_Deb_Pack Install_Python_Lib Install_Bt Set_Bt_Panel Service_Add Set_Firewall Get_Ip_Address Setup_Count ${IDC_CODE} Add_lib_Install } echo -e " +---------------------------------------------------------------------- | 宝塔面板 Bt-WebPanel FOR Debian +---------------------------------------------------------------------- " 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 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 > /www/server/panel/data/bind.pl echo -e "==================================================================" echo -e " \033[32m 宝塔纯净版安装完成! Installed successfully \033[0m" echo -e "========================面板账户登录信息==========================" echo -e " \033[32m 外网面板地址: ${HTTP_S}://${REMOTE_IP}:${panelPort}${auth_path}\033[0m" echo -e " \033[32m 内网面板地址: ${HTTP_S}://${LOCAL_IP}:${panelPort}${auth_path}\033[0m" echo -e " \033[32m 账号: $username\033[0m" echo -e " \033[32m 密码: $password\033[0m" echo -e "=========================打开面板前请看===========================" echo -e "【云服务器】请在安全组放行 $panelPort 端口" echo -e " 因默认启用自签证书https加密访问,浏览器将提示不安全" echo -e " 点击【高级】-【继续访问】或【接受风险并继续】访问" echo -e " \033[32m宝塔纯净版顶尖站长群 https://tg.HostCLi.com\033[0m" echo -e "=================================================================="
标签:宝塔,shell,pyenv,etc,fi,path,server,debian,panel From: https://www.cnblogs.com/dzqdzq/p/18524528