Repository: zhucaidan/btpanel-v7.7.0 Branch: main Commit: a19b0135de52 Files: 11 Total size: 62.2 KB Directory structure: gitextract_yy456605/ ├── README.md ├── api/ │ └── panel/ │ └── get_version └── install/ ├── conf/ │ └── softList.conf ├── install_panel.sh ├── pip_select.sh ├── public.sh ├── src/ │ ├── bt6.init │ └── bt7.init ├── update6.sh ├── update6_en.sh └── yumRepo_select.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ # btpanel-v7.7.0 btpanel-v7.7.0-backup 官方原版v7.7.0版本面板备份 **Centos/Ubuntu/Debian安装命令 独立运行环境(py3.7):** ```Bash curl -sSO https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/install_panel.sh && bash install_panel.sh ``` 跳过登录框,以及破解插件等请自行搜索   **如果遇到重启后宝塔乱码 请DD最新版Debian系统然后修改语言区域:** ```Bash localectl set-locale LANG=en_US.UTF-8 nano /etc/default/locale ``` ```Bash LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8" ``` 修改后保存文件,重启VPS即可。 ================================================ FILE: api/panel/get_version ================================================ 7.7.0 ================================================ FILE: install/conf/softList.conf ================================================ [{ "name": "Nginx", "versions": [{ "status": false, "version": "1.20" }, { "status": false, "version": "1.21" }, { "status": false, "version": "1.19" }, { "status": false, "version": "1.18" }, { "status": false, "version": "-Tengine2.2" }, { "status": false, "version": "openresty" }], "type": "Web服务器", "msg": "Nginx是一款轻量级的Web服务器!", "shell": "nginx.sh", "check": "server/nginx/sbin/nginx" }, { "name": "Apache", "versions": [{ "status": false, "version": "2.4" }, { "status": false, "version": "2.2" }], "type": "Web服务器", "msg": "Apache是世界使用排名第一的Web服务器软件。", "shell": "httpd.sh", "check": "server/apache/bin/httpd" }, { "name": "MySQL", "versions": [{ "status": false, "version": "5.1" }, { "status": false, "version": "5.5" }, { "status": false, "version": "5.6" }, { "status": false, "version": "5.7" }, { "status": false, "version": "8.0" }, { "status": false, "version": "AliSQL" }, { "status": false, "version": "mariadb_10.0" }, { "status": false, "version": "mariadb_10.1" }], "type": "数据库", "msg": "推荐安装!", "shell": "mysql.sh", "check": "server/mysql/bin/mysql" }, { "name": "Pure-Ftpd", "versions": [{ "status": false, "version": "1.0.49" }], "type": "FTP服务器", "msg": "PureFTPd是一款专注于程序健壮和软件安全的免费FTP服务器软件", "shell": "pure-ftpd.sh", "check": "server/pure-ftpd/bin/pure-pw" }, { "name": "PHP", "versions": [{ "status": false, "version": "5.2" }, { "status": false, "version": "5.3" }, { "status": false, "version": "5.4" }, { "status": false, "version": "5.5" }, { "status": false, "version": "5.6" }, { "status": false, "version": "7.0" }, { "status": false, "version": "7.1" }, { "status": false, "version": "7.2" }, { "status": false, "version": "7.3" }, { "status": false, "version": "7.4" },{ "status": false, "version": "8.0" }], "type": "语言解释器", "msg": "若非必要,请安装更新的版本!", "shell": "php.sh", "check": "server/php/VERSION/bin/php" }, { "name": "Tomcat", "versions": [{ "status": false, "version": "7" }, { "status": false, "version": "8" }, { "status": false, "version": "9" }], "type": "语言解释器", "msg": "java-ee解释器", "shell": "tomcat.sh", "check": "server/tomcat/bin/catalina.sh" }, { "name": "phpMyAdmin", "versions": [{ "status": false, "version": "4.0" }, { "status": false, "version": "4.4" }, { "status": false, "version": "4.7" }, { "status": false, "version": "4.9" }, { "status": false, "version": "4.8" }, { "status": false, "version": "5.0" }, { "status": false, "version": "5.1" }], "type": "数据库工具", "msg": "Web端MySQL管理工具", "shell": "phpmyadmin.sh", "check": "server/phpmyadmin/version.pl" } ] ================================================ FILE: install/install_panel.sh ================================================ #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH LANG=en_US.UTF-8 if [ $(whoami) != "root" ];then echo "请使用root权限执行宝塔安装命令!" exit 1; fi is64bit=$(getconf LONG_BIT) if [ "${is64bit}" != '64' ];then Red_Error "抱歉, 当前面板版本不支持32位系统, 请使用64位系统或安装宝塔5.9!"; 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}" -lt "16" ];then echo "Ubuntu ${UbuntuCheck}不支持安装宝塔面板,建议更换Ubuntu18/20安装宝塔面板" 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) 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 "请截图以上报错信息发帖至论坛www.bt.cn/bbs求助" } 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 } 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 } 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 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 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 elif [ "${PM}" == "apt-get" ]; then update-rc.d bt defaults 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://dg2.bt.cn http://dg1.bt.cn http://125.90.93.52:5880 http://36.133.1.8:5880 http://123.129.198.197 http://38.34.185.130 http://116.213.43.206:5880 http://128.1.164.196); 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 100 ];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 100 ];then if [ $RES -ge 3000 ];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://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 Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat') isExc=$(cat $yumPath|grep httpd) if [ "$isExc" = "" ];then echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >> $yumPath 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 https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/yumRepo_select.sh|bash #fi #尝试同步时间(从bt.cn) echo 'Synchronizing system time...' getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://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" 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 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 apt-get update -y 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< /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 [ -f $redhat_version_file ];then os_type='el' is_aliyunos=$(cat $redhat_version_file|grep Aliyun) if [ "$is_aliyunos" != "" ];then 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 https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/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 5 $pyenv_path/pyenv/bin/pip install -U pip $pyenv_path/pyenv/bin/pip install -U setuptools $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt fi source $pyenv_path/pyenv/bin/activate return else rm -rf $pyenv_path/pyenv fi fi py_version="3.7.8" 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 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 10 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 5 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.8.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 $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2 $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt source $pyenv_path/pyenv/bin/activate 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(){ panelPort="8888" if [ -f ${setup_path}/server/panel/data/port.pl ];then panelPort=$(cat ${setup_path}/server/panel/data/port.pl) 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 [ -f "/etc/init.d/bt" ]; then /etc/init.d/bt stop sleep 1 fi wget -O /etc/init.d/bt https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/src/bt6.init -T 10 wget -O /www/server/panel/install/public.sh https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/public.sh -T 10 wget -O panel.zip https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/src/panel6.zip -T 10 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 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" ];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 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 https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/src/bt7.init -T 10 wget -O /www/server/panel/init.sh https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/src/bt7.init -T 10 wget -O /www/server/panel/data/softList.conf ${download_Url}/install/conf/softList.conf } Set_Bt_Panel(){ password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8) 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 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}) cd ~ echo "${password}" > ${setup_path}/server/panel/default.pl chmod 600 ${setup_path}/server/panel/default.pl sleep 3 /etc/init.d/bt restart sleep 3 isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}') LOCAL_CURL=$(curl 127.0.0.1:8888/login 2>&1 |grep -i html) if [ -z "${isStart}" ] && [ -z "${LOCAL_CURL}" ];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 } 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 ufw allow 20/tcp ufw allow 21/tcp ufw allow 22/tcp ufw allow 80/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 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 ${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=${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) 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 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 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 } Install_Main(){ startTime=`date +%s` Lock_Clear System_Check Get_Pack_Manager 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 fi Install_Python_Lib Install_Bt Set_Bt_Panel Service_Add Set_Firewall Get_Ip_Address Setup_Count ${IDC_CODE} } 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:8888 when installed. +---------------------------------------------------------------------- " 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 echo > /www/server/panel/data/bind.pl echo -e "==================================================================" echo -e "\033[32mCongratulations! Installed successfully!\033[0m" echo -e "==================================================================" echo "外网面板地址: http://${getIpAddress}:${panelPort}${auth_path}" echo "内网面板地址: http://${LOCAL_IP}:${panelPort}${auth_path}" echo -e "username: $username" echo -e "password: $password" echo -e "\033[33mIf you cannot access the panel,\033[0m" echo -e "\033[33mrelease the following panel port [${panelPort}] in the security group\033[0m" echo -e "\033[33m若无法访问面板,请检查防火墙/安全组是否有放行面板[${panelPort}]端口\033[0m" echo -e "==================================================================" endTime=`date +%s` ((outTime=($endTime-$startTime)/60)) echo -e "Time consumed:\033[32m $outTime \033[0mMinute!" ================================================ FILE: install/pip_select.sh ================================================ #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin pyenv_bin=/www/server/panel/pyenv/bin rep_path=${pyenv_bin}:$PATH if [ -d "$pyenv_bin" ];then PATH=$rep_path fi export PATH LANG=en_US.UTF-8 get_PIP_URL(){ nodes=(https://mirrors.tencent.com/pypi/simple https://pypi.doubanio.com/simple https://mirrors.aliyun.com/pypi/simple https://pypi.tuna.tsinghua.edu.cn/simple https://pypi.org/simple); i=1; for node in ${nodes[@]}; do start=`date +%s.%N` result=`curl -sS --connect-timeout 3 -m 60 $node/0/|grep Links` if [ "$result" != '' ];then end=`date +%s.%N` start_s=`echo $start | cut -d '.' -f 1` start_ns=`echo $start | cut -d '.' -f 2` end_s=`echo $end | cut -d '.' -f 1` end_ns=`echo $end | cut -d '.' -f 2` time_micro=$(( (10#$end_s-10#$start_s)*1000000 + (10#$end_ns/1000 - 10#$start_ns/1000) )) time_ms=$(($time_micro/1000)) values[$i]=$time_ms; urls[$time_ms]=$node i=$(($i+1)) if [ $time_ms -lt 50 ];then break; fi fi done j=5000 for n in ${values[@]}; do if [ $j -gt $n ];then j=$n fi if [ $j -lt 50 ];then break; fi done if [ $j = 5000 ];then PIP_URL='False'; T_HOST='False' else PIP_URL=${urls[$j]} my_tmp=$(echo $PIP_URL|grep 'aliyun') if [ "$my_tmp" != "" ];then T_HOST=mirrors.aliyun.com elif [ $(echo $PIP_URL|grep 'tencent') != "" ];then T_HOST=mirrors.tencent.com elif [ $(echo $PIP_URL|grep 'doubanio') != "" ];then T_HOST=pypi.doubanio.com elif [ $(echo $PIP_URL|grep 'tsinghua') != "" ];then T_HOST=pypi.tuna.tsinghua.edu.cn elif [ $(echo $PIP_URL|grep 'pypi.org') != "" ];then T_HOST=pypi.org fi fi } get_PIP_URL if [ "$PIP_URL" != "False" ];then echo "$PIP_URL" if [ ! -d ~/.pip ];then mkdir -p ~/.pip fi cat > ~/.pip/pip.conf </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 100 ];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 100 ];then if [ $RES -ge 3000 ];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://download.bt.cn'; fi fi rm -f $tmp_file1 rm -f $tmp_file2 } GetCpuStat(){ time1=$(cat /proc/stat |grep 'cpu ') sleep 1 time2=$(cat /proc/stat |grep 'cpu ') cpuTime1=$(echo ${time1}|awk '{print $2+$3+$4+$5+$6+$7+$8}') cpuTime2=$(echo ${time2}|awk '{print $2+$3+$4+$5+$6+$7+$8}') runTime=$((${cpuTime2}-${cpuTime1})) idelTime1=$(echo ${time1}|awk '{print $5}') idelTime2=$(echo ${time2}|awk '{print $5}') idelTime=$((${idelTime2}-${idelTime1})) useTime=$(((${runTime}-${idelTime})*3)) [ ${useTime} -gt ${runTime} ] && cpuBusy="true" if [ "${cpuBusy}" == "true" ]; then cpuCore=$((${cpuInfo}/2)) else cpuCore=$((${cpuInfo}-1)) fi } GetPackManager(){ if [ -f "/usr/bin/yum" ] && [ -f "/etc/yum.conf" ]; then PM="yum" elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then PM="apt-get" fi } bt_check(){ p_path=/www/server/panel/class/panelPlugin.py if [ -f $p_path ];then is_ext=$(cat $p_path|grep btwaf) if [ "$is_ext" != "" ];then send_check fi fi p_path=/www/server/panel/BTPanel/templates/default/index.html if [ -f $p_path ];then is_ext=$(cat $p_path|grep fbi) if [ "$is_ext" != "" ];then send_check fi fi } send_check(){ chattr -i /etc/init.d/bt chmod +x /etc/init.d/bt p_path2=/www/server/panel/class/common.py p_version=$(cat $p_path2|grep "version = "|awk '{print $3}'|tr -cd [0-9.]) curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/panel/notpro?version=$p_version NODE_URL="" exit 0; } init_check(){ CRACK_URL=(oss.yuewux.com); for url in ${CRACK_URL[@]}; do CRACK_INIT=$(cat /etc/init.d/bt |grep ${url}) if [ "${CRACK_INIT}" ];then rm -rf /www/server/panel/class/* chattr +i /www/server/panel/class chattr -R +i /www/server/panel chattr +i /www fi done } GetSysInfo(){ if [ "${PM}" = "yum" ]; then SYS_VERSION=$(cat /etc/redhat-release) elif [ "${PM}" = "apt-get" ]; then SYS_VERSION=$(cat /etc/issue) fi SYS_INFO=$(uname -msr) SYS_BIT=$(getconf LONG_BIT) MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}') CPU_INFO=$(getconf _NPROCESSORS_ONLN) GCC_VER=$(gcc -v 2>&1|grep "gcc version"|awk '{print $3}') CMAKE_VER=$(cmake --version|grep version|awk '{print $3}') echo -e ${SYS_VERSION} echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO} gcc:${GCC_VER} cmake:${CMAKE_VER} echo -e ${SYS_INFO} } cpuInfo=$(getconf _NPROCESSORS_ONLN) if [ "${cpuInfo}" -ge "4" ];then GetCpuStat else cpuCore="1" fi GetPackManager if [ -d "/www/server/phpmyadmin/pma" ];then rm -rf /www/server/phpmyadmin/pma EN_CHECK=$(cat /www/server/panel/config/config.json |grep English) if [ "${EN_CHECK}" ];then curl https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/update6_en.sh|bash else curl https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/update6.sh|bash fi echo > /www/server/panel/data/restart.pl fi if [ ! $NODE_URL ];then EN_CHECK=$(cat /www/server/panel/config/config.json |grep English) if [ -z "${EN_CHECK}" ];then echo '正在选择下载节点...'; else echo "selecting download node..."; fi get_node_url bt_check fi ================================================ FILE: install/src/bt6.init ================================================ #!/bin/bash # chkconfig: 2345 55 25 # description: bt Cloud Service ### BEGIN INIT INFO # Provides: bt # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts bt # Description: starts the bt ### END INIT INFO panel_init(){ panel_path=/www/server/panel pidfile=$panel_path/logs/panel.pid cd $panel_path env_path=$panel_path/pyenv/bin/activate if [ -f $env_path ];then source $env_path pythonV=$panel_path/pyenv/bin/python chmod -R 700 $panel_path/pyenv/bin else pythonV=/usr/bin/python fi reg="^#\!$pythonV\$" is_sed=$(cat $panel_path/BT-Panel|head -n 1|grep -E $reg) if [ "${is_sed}" = "" ];then sed -i "s@^#!.*@#!$pythonV@" $panel_path/BT-Panel fi is_sed=$(cat $panel_path/BT-Task|head -n 1|grep -E $reg) if [ "${is_sed}" = "" ];then sed -i "s@^#!.*@#!$pythonV@" $panel_path/BT-Task fi chmod 700 $panel_path/BT-Panel chmod 700 $panel_path/BT-Task log_file=$panel_path/logs/error.log task_log_file=$panel_path/logs/task.log if [ -f $panel_path/data/ssl.pl ];then log_file=/dev/null fi port=$(cat $panel_path/data/port.pl) } panel_init get_panel_pids(){ isStart=$(ps aux|grep -E '(runserver|BT-Panel)'|grep -v grep|awk '{print $2}'|xargs) pids=$isStart arr=$isStart } get_task_pids(){ isStart=$(ps aux|grep -E '(task.py|BT-Task)'|grep -v grep|awk '{print $2}'|xargs) pids=$isStart arr=$isStart } panel_start() { isStart=`ps aux|grep 'runserver:app'|grep -v grep|awk '{print $2}'` if [ "$isStart" != '' ];then kill -9 $isStart fi get_panel_pids if [ "$isStart" == '' ];then rm -f $pidfile panel_port_check echo -e "Starting Bt-Panel...\c" nohup $panel_path/BT-Panel >> $log_file 2>&1 & isStart="" n=0 while [[ "$isStart" == "" ]]; do echo -e ".\c" sleep 0.5 get_panel_pids let n+=1 if [ $n -gt 8 ];then break; fi done if [ "$isStart" == '' ];then echo -e "\033[31mfailed\033[0m" echo '------------------------------------------------------' tail -n 20 $log_file echo '------------------------------------------------------' echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" fi echo -e " \033[32mdone\033[0m" else echo "Starting Bt-Panel... Bt-Panel (pid $(echo $isStart)) already running" fi get_task_pids if [ "$isStart" == '' ];then echo -e "Starting Bt-Tasks... \c" nohup $panel_path/BT-Task >> $task_log_file 2>&1 & sleep 0.2 get_task_pids if [ "$isStart" == '' ];then echo -e "\033[31mfailed\033[0m" echo '------------------------------------------------------' tail -n 20 $task_log_file echo '------------------------------------------------------' echo -e "\033[31mError: BT-Task service startup failed.\033[0m" return; fi echo -e " \033[32mdone\033[0m" else echo "Starting Bt-Tasks... Bt-Tasks (pid $isStart) already running" fi } panel_port_check() { is_process=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $1}'|sort|uniq|xargs) for pn in ${is_process[@]} do if [ "$pn" = "nginx" ];then /etc/init.d/nginx restart fi if [ "$pn" = "httpd" ];then /etc/init.d/httpd restart fi if [ "$pn" = "mysqld" ];then /etc/init.d/mysqld restart fi if [ "$pn" = "superviso" ];then pkill -9 superviso sleep 0.2 supervisord -c /etc/supervisor/supervisord.conf fi if [ "$pn" = "pure-ftpd" ];then /etc/init.d/pure-ftpd restart fi if [ "$pn" = "memcached" ];then /etc/init.d/memcached restart fi if [ "$pn" = "sudo" ];then if [ -f /etc/init.d/redis ];then /etc/init.d/redis restart fi fi if [ "$pn" = "php-fpm" ];then php_v=(52 53 54 55 56 70 71 72 73 74); for pv in ${php_v[@]}; do if [ -f /etc/init.d/php-fpm-${pv} ];then if [ -f /www/server/php/%{pv}/sbin/php-fpm ];then if [ -f /tmp/php-cgi-${pv}.sock ];then /etc/init.d/php-fpm-${pv} start fi /etc/init.d/php-fpm-${pv} restart fi fi done fi done is_ports=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $2}'|xargs) if [ "$is_ports" != '' ];then kill -9 $is_ports sleep 1 fi } panel_stop() { echo -e "Stopping Bt-Tasks...\c"; get_task_pids arr=($pids) for p in ${arr[@]} do kill -9 $p done echo -e " \033[32mdone\033[0m" echo -e "Stopping Bt-Panel...\c"; get_panel_pids for p in ${arr[@]} do kill -9 $p &>/dev/null done if [ -f $pidfile ];then rm -f $pidfile fi echo -e " \033[32mdone\033[0m" } panel_status() { port=$(cat $panel_path/data/port.pl) get_panel_pids if [ "$isStart" != '' ];then echo -e "\033[32mBt-Panel (pid $(echo $isStart)) already running\033[0m" else echo -e "\033[31mBt-Panel not running\033[0m" fi get_task_pids if [ "$isStart" != '' ];then echo -e "\033[32mBt-Task (pid $isStart) already running\033[0m" else echo -e "\033[31mBt-Task not running\033[0m" fi } panel_reload() { isStart=$(ps aux|grep 'runserver:app'|grep -v grep|awk '{print $2}') if [ "$isStart" != '' ];then kill -9 $isStart sleep 0.5 fi get_panel_pids if [ "$isStart" != '' ];then get_panel_pids for p in ${arr[@]} do kill -9 $p done rm -f $pidfile panel_port_check echo -e "Reload Bt-Panel.\c"; nohup $panel_path/BT-Panel >> $log_file 2>&1 & isStart="" n=0 while [[ "$isStart" == "" ]]; do echo -e ".\c" sleep 0.5 get_panel_pids let n+=1 if [ $n -gt 8 ];then break; fi done if [ "$isStart" == '' ];then echo -e "\033[31mfailed\033[0m" echo '------------------------------------------------------' tail -n 20 $log_file echo '------------------------------------------------------' echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" return; fi echo -e " \033[32mdone\033[0m" else echo -e "\033[31mBt-Panel not running\033[0m" panel_start fi } install_used() { if [ ! -f $panel_path/aliyun.pl ];then return; fi password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 12) username=$($pythonV $panel_path/tools.py panel $password) echo "$password" > $panel_path/default.pl rm -f $panel_path/aliyun.pl } error_logs() { tail -n 100 $log_file } case "$1" in 'start') install_used panel_start ;; 'stop') panel_stop ;; 'restart') panel_stop sleep 1 panel_start ;; 'reload') panel_reload ;; 'status') panel_status ;; 'logs') error_logs ;; 'panel') $pythonV $panel_path/tools.py cli $2 ;; 'default') port=$(cat $panel_path/data/port.pl) password=$(cat $panel_path/default.pl) if [ -f $panel_path/data/domain.conf ];then address=$(cat $panel_path/data/domain.conf) fi if [ -f $panel_path/data/admin_path.pl ];then auth_path=$(cat $panel_path/data/admin_path.pl) fi if [ "$address" = "" ];then address=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress) fi pool=http if [ -f $panel_path/data/ssl.pl ];then pool=https fi echo -e "==================================================================" echo -e "\033[32mBT-Panel default info!\033[0m" echo -e "==================================================================" echo "Bt-Panel-URL: $pool://$address:$port$auth_path" echo -e `$pythonV $panel_path/tools.py username` echo -e "password: $password" echo -e "\033[33mWarning:\033[0m" echo -e "\033[33mIf you cannot access the panel, \033[0m" echo -e "\033[33mrelease the following port (8888|888|80|443|20|21) in the security group\033[0m" echo -e "==================================================================" ;; *) $pythonV $panel_path/tools.py cli $1 ;; esac ================================================ FILE: install/src/bt7.init ================================================ #!/bin/bash # chkconfig: 2345 55 25 # description: bt Cloud Service ### BEGIN INIT INFO # Provides: bt # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts bt # Description: starts the bt ### END INIT INFO panel_init(){ panel_path=/www/server/panel pidfile=$panel_path/logs/panel.pid cd $panel_path env_path=$panel_path/pyenv/bin/activate if [ -f $env_path ];then source $env_path pythonV=$panel_path/pyenv/bin/python chmod -R 700 $panel_path/pyenv/bin else pythonV=/usr/bin/python fi reg="^#\!$pythonV\$" is_sed=$(cat $panel_path/BT-Panel|head -n 1|grep -E $reg) if [ "${is_sed}" = "" ];then sed -i "s@^#!.*@#!$pythonV@" $panel_path/BT-Panel fi is_sed=$(cat $panel_path/BT-Task|head -n 1|grep -E $reg) if [ "${is_sed}" = "" ];then sed -i "s@^#!.*@#!$pythonV@" $panel_path/BT-Task fi chmod 700 $panel_path/BT-Panel chmod 700 $panel_path/BT-Task log_file=$panel_path/logs/error.log task_log_file=$panel_path/logs/task.log if [ -f $panel_path/data/ssl.pl ];then log_file=/dev/null fi port=$(cat $panel_path/data/port.pl) } panel_init get_panel_pids(){ isStart=$(ps aux|grep -E '(runserver|BT-Panel)'|grep -v grep|awk '{print $2}'|xargs) pids=$isStart arr=$isStart } get_task_pids(){ isStart=$(ps aux|grep -E '(task.py|BT-Task)'|grep -v grep|awk '{print $2}'|xargs) pids=$isStart arr=$isStart } panel_start() { isStart=`ps aux|grep 'runserver:app'|grep -v grep|awk '{print $2}'` if [ "$isStart" != '' ];then kill -9 $isStart fi get_panel_pids if [ "$isStart" == '' ];then rm -f $pidfile panel_port_check echo -e "Starting Bt-Panel...\c" nohup $panel_path/BT-Panel >> $log_file 2>&1 & isStart="" n=0 while [[ "$isStart" == "" ]]; do echo -e ".\c" sleep 0.5 get_panel_pids let n+=1 if [ $n -gt 8 ];then break; fi done if [ "$isStart" == '' ];then echo -e "\033[31mfailed\033[0m" echo '------------------------------------------------------' tail -n 20 $log_file echo '------------------------------------------------------' echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" fi echo -e " \033[32mdone\033[0m" else echo "Starting Bt-Panel... Bt-Panel (pid $(echo $isStart)) already running" fi get_task_pids if [ "$isStart" == '' ];then echo -e "Starting Bt-Tasks... \c" nohup $panel_path/BT-Task >> $task_log_file 2>&1 & sleep 0.2 get_task_pids if [ "$isStart" == '' ];then echo -e "\033[31mfailed\033[0m" echo '------------------------------------------------------' tail -n 20 $task_log_file echo '------------------------------------------------------' echo -e "\033[31mError: BT-Task service startup failed.\033[0m" return; fi echo -e " \033[32mdone\033[0m" else echo "Starting Bt-Tasks... Bt-Tasks (pid $isStart) already running" fi } panel_port_check() { is_process=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $1}'|sort|uniq|xargs) for pn in ${is_process[@]} do if [ "$pn" = "nginx" ];then /etc/init.d/nginx restart fi if [ "$pn" = "httpd" ];then /etc/init.d/httpd restart fi if [ "$pn" = "mysqld" ];then /etc/init.d/mysqld restart fi if [ "$pn" = "superviso" ];then pkill -9 superviso sleep 0.2 supervisord -c /etc/supervisor/supervisord.conf fi if [ "$pn" = "pure-ftpd" ];then /etc/init.d/pure-ftpd restart fi if [ "$pn" = "memcached" ];then /etc/init.d/memcached restart fi if [ "$pn" = "sudo" ];then if [ -f /etc/init.d/redis ];then /etc/init.d/redis restart fi fi if [ "$pn" = "php-fpm" ];then php_v=(52 53 54 55 56 70 71 72 73 74); for pv in ${php_v[@]}; do if [ -f /etc/init.d/php-fpm-${pv} ];then if [ -f /www/server/php/%{pv}/sbin/php-fpm ];then if [ -f /tmp/php-cgi-${pv}.sock ];then /etc/init.d/php-fpm-${pv} start fi /etc/init.d/php-fpm-${pv} restart fi fi done fi done is_ports=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $2}'|xargs) if [ "$is_ports" != '' ];then kill -9 $is_ports sleep 1 fi } panel_stop() { echo -e "Stopping Bt-Tasks...\c"; get_task_pids arr=($pids) for p in ${arr[@]} do kill -9 $p done echo -e " \033[32mdone\033[0m" echo -e "Stopping Bt-Panel...\c"; get_panel_pids for p in ${arr[@]} do kill -9 $p &>/dev/null done if [ -f $pidfile ];then rm -f $pidfile fi echo -e " \033[32mdone\033[0m" } panel_status() { port=$(cat $panel_path/data/port.pl) get_panel_pids if [ "$isStart" != '' ];then echo -e "\033[32mBt-Panel (pid $(echo $isStart)) already running\033[0m" else echo -e "\033[31mBt-Panel not running\033[0m" fi get_task_pids if [ "$isStart" != '' ];then echo -e "\033[32mBt-Task (pid $isStart) already running\033[0m" else echo -e "\033[31mBt-Task not running\033[0m" fi } panel_reload() { isStart=$(ps aux|grep 'runserver:app'|grep -v grep|awk '{print $2}') if [ "$isStart" != '' ];then kill -9 $isStart sleep 0.5 fi get_panel_pids if [ "$isStart" != '' ];then get_panel_pids for p in ${arr[@]} do kill -9 $p done rm -f $pidfile panel_port_check echo -e "Reload Bt-Panel.\c"; nohup $panel_path/BT-Panel >> $log_file 2>&1 & isStart="" n=0 while [[ "$isStart" == "" ]]; do echo -e ".\c" sleep 0.5 get_panel_pids let n+=1 if [ $n -gt 8 ];then break; fi done if [ "$isStart" == '' ];then echo -e "\033[31mfailed\033[0m" echo '------------------------------------------------------' tail -n 20 $log_file echo '------------------------------------------------------' echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" return; fi echo -e " \033[32mdone\033[0m" else echo -e "\033[31mBt-Panel not running\033[0m" panel_start fi } install_used() { if [ ! -f $panel_path/aliyun.pl ];then return; fi password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 12) username=$($pythonV $panel_path/tools.py panel $password) safe_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8) echo "$safe_path" > $panel_path/admin_path.pl echo "$password" > $panel_path/default.pl rm -f $panel_path/aliyun.pl } error_logs() { tail -n 100 $log_file } case "$1" in 'start') install_used panel_start ;; 'stop') panel_stop ;; 'restart') panel_stop sleep 1 panel_start ;; 'reload') panel_reload ;; 'status') panel_status ;; 'logs') error_logs ;; 'panel') $pythonV $panel_path/tools.py cli $2 ;; 'default') 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) port=$(cat $panel_path/data/port.pl) password=$(cat $panel_path/default.pl) if [ -f $panel_path/data/domain.conf ];then address=$(cat $panel_path/data/domain.conf) fi if [ -f $panel_path/data/admin_path.pl ];then auth_path=$(cat $panel_path/data/admin_path.pl) fi if [ "$address" = "" ];then address=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress) fi pool=http if [ -f $panel_path/data/ssl.pl ];then pool=https fi echo -e "==================================================================" echo -e "\033[32mBT-Panel default info!\033[0m" echo -e "==================================================================" echo "外网面板地址: $pool://$address:$port$auth_path" echo "内网面板地址: http://${LOCAL_IP}:$port$auth_path" echo -e "\033[33m*以下仅为初始默认账户密码,若无法登录请执行bt命令重置账户/密码登录\033[0m" echo -e `$pythonV $panel_path/tools.py username` echo -e "password: $password" echo -e "\033[33mIf you cannot access the panel,\033[0m" echo -e "\033[33mrelease the following panel port [${port}] in the security group\033[0m" echo -e "\033[33m若无法访问面板,请检查防火墙/安全组是否有放行面板[${port}]端口\033[0m" echo -e "==================================================================" ;; *) $pythonV $panel_path/tools.py cli $1 ;; esac ================================================ FILE: install/update6.sh ================================================ #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH LANG=en_US.UTF-8 if [ ! -d /www/server/panel/BTPanel ];then echo "=============================================" echo "错误, 5.x不可以使用此命令升级!" echo "5.9平滑升级到6.0的命令:curl http://download.bt.cn/install/update_to_6.sh|bash" exit 0; fi public_file=/www/server/panel/install/public.sh publicFileMd5=$(md5sum ${public_file} 2>/dev/null|awk '{print $1}') md5check="918CC0E14AC92F9D51BFD5CE6A076C36" if [ "${publicFileMd5}" != "${md5check}" ]; then wget -O Tpublic.sh https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/public.sh -T 20; publicFileMd5=$(md5sum Tpublic.sh 2>/dev/null|awk '{print $1}') if [ "${publicFileMd5}" == "${md5check}" ]; then \cp -rpa Tpublic.sh $public_file fi rm -f Tpublic.sh fi . $public_file Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat') if [ "${Centos8Check}" ];then if [ ! -f "/usr/bin/python" ] && [ -f "/usr/bin/python3" ] && [ ! -d "/www/server/panel/pyenv" ]; then ln -sf /usr/bin/python3 /usr/bin/python fi fi mypip="pip" env_path=/www/server/panel/pyenv/bin/activate if [ -f $env_path ];then mypip="/www/server/panel/pyenv/bin/pip" fi download_Url=$NODE_URL setup_path=/www version=$(curl -Ss --connect-timeout 5 -m 2 https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/api/panel/get_version) if [ "$version" = '' ];then version='7.7.0' fi armCheck=$(uname -m|grep arm) if [ "${armCheck}" ];then version='7.7.0' fi wget -T 5 -O /tmp/panel.zip https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/src/LinuxPanel-7.7.0.zip dsize=$(du -b /tmp/panel.zip|awk '{print $1}') if [ $dsize -lt 10240 ];then echo "获取更新包失败,请稍后更新或联系宝塔运维" exit; fi unzip -o /tmp/panel.zip -d $setup_path/server/ > /dev/null rm -f /tmp/panel.zip cd $setup_path/server/panel/ check_bt=`cat /etc/init.d/bt` if [ "${check_bt}" = "" ];then rm -f /etc/init.d/bt wget -O /etc/init.d/bt https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/src/bt6.init -T 20 chmod +x /etc/init.d/bt fi rm -f /www/server/panel/*.pyc rm -f /www/server/panel/class/*.pyc #pip install flask_sqlalchemy #pip install itsdangerous==0.24 pip_list=$($mypip list) request_v=$(echo "$pip_list"|grep requests) if [ "$request_v" = "" ];then $mypip install requests fi openssl_v=$(echo "$pip_list"|grep pyOpenSSL) if [ "$openssl_v" = "" ];then $mypip install pyOpenSSL fi #cffi_v=$(echo "$pip_list"|grep cffi|grep 1.12.) #if [ "$cffi_v" = "" ];then # $mypip install cffi==1.12.3 #fi pymysql=$(echo "$pip_list"|grep pymysql) if [ "$pymysql" = "" ];then $mypip install pymysql fi pymysql=$(echo "$pip_list"|grep pycryptodome) if [ "$pymysql" = "" ];then $mypip install pycryptodome fi #psutil=$(echo "$pip_list"|grep psutil|awk '{print $2}'|grep '5.7.') #if [ "$psutil" = "" ];then # $mypip install -U psutil #fi if [ -d /www/server/panel/class/BTPanel ];then rm -rf /www/server/panel/class/BTPanel fi chattr -i /etc/init.d/bt chmod +x /etc/init.d/bt echo "=====================================" rm -f /dev/shm/bt_sql_tips.pl kill $(ps aux|grep -E "task.pyc|main.py"|grep -v grep|awk '{print $2}') /etc/init.d/bt start echo 'True' > /www/server/panel/data/restart.pl pkill -9 gunicorn & echo "已成功升级到[$version]${Ver}"; ================================================ FILE: install/update6_en.sh ================================================ #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH LANG=en_US.UTF-8 if [ ! -d /www/server/panel/BTPanel ];then echo "=============================================" echo "Error, 5.x Can't use this command to upgrade!" #echo "5.9 Smooth upgrade to 6.0 command:curl http://download.bt.cn/install/update_to_6.sh|bash" exit 0; fi public_file=/www/server/panel/install/public.sh publicFileMd5=$(md5sum ${public_file} 2>/dev/null|awk '{print $1}') md5check="918CC0E14AC92F9D51BFD5CE6A076C36" if [ "${publicFileMd5}" != "${md5check}" ]; then wget -O Tpublic.sh https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/public.sh -T 20; publicFileMd5=$(md5sum Tpublic.sh 2>/dev/null|awk '{print $1}') if [ "${publicFileMd5}" == "${md5check}" ]; then \cp -rpa Tpublic.sh $public_file fi rm -f Tpublic.sh fi . $public_file Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat') if [ "${Centos8Check}" ];then if [ ! -f "/usr/bin/python" ] && [ -f "/usr/bin/python3" ] && [ ! -d "/www/server/panel/pyenv" ]; then ln -sf /usr/bin/python3 /usr/bin/python fi fi mypip="pip" env_path=/www/server/panel/pyenv/bin/activate if [ -f $env_path ];then mypip="/www/server/panel/pyenv/bin/pip" fi download_Url=$NODE_URL setup_path=/www version=$(curl -Ss --connect-timeout 5 -m 2 https://brandnew.aapanel.com/api/panel/getLatestOfficialVersion) if [ "$version" = '' ];then version='6.8.16' fi wget -T 5 -O /tmp/panel.zip https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/src/LinuxPanel-7.7.0.zip dsize=$(du -b /tmp/panel.zip|awk '{print $1}') if [ $dsize -lt 10240 ];then echo "Failed to get update package, please update or contact aaPanel Operation" exit; fi unzip -o /tmp/panel.zip -d $setup_path/server/ > /dev/null rm -f /tmp/panel.zip cd $setup_path/server/panel/ check_bt=`cat /etc/init.d/bt` if [ "${check_bt}" = "" ];then rm -f /etc/init.d/bt wget -O /etc/init.d/bt https://raw.githubusercontent.com/zhucaidan/btpanel-v7.7.0/main/install/src/bt6.init -T 20 chmod +x /etc/init.d/bt fi rm -f /www/server/panel/*.pyc rm -f /www/server/panel/class/*.pyc #pip install flask_sqlalchemy #pip install itsdangerous==0.24 pip_list=$($mypip list) request_v=$(echo "$pip_list"|grep requests) if [ "$request_v" = "" ];then $mypip install requests fi openssl_v=$(echo "$pip_list"|grep pyOpenSSL) if [ "$openssl_v" = "" ];then $mypip install pyOpenSSL fi cffi_v=$(echo "$pip_list"|grep cffi|grep 1.12.) if [ "$cffi_v" = "" ];then $mypip install cffi==1.12.3 fi pymysql=$(echo "$pip_list"|grep pymysql) if [ "$pymysql" = "" ];then $mypip install pymysql fi psutil=$(echo "$pip_list"|grep psutil|awk '{print $2}'|grep '5.7.') if [ "$psutil" = "" ];then $mypip install -U psutil fi $mypip install telegram $mypip install paramiko -I Run_User="www" groupadd ${Run_User} useradd -s /sbin/nologin -g ${Run_User} ${Run_User} chattr -i /etc/init.d/bt chmod +x /etc/init.d/bt echo "=====================================" rm -f /dev/shm/bt_sql_tips.pl kill $(ps aux|grep -E "task.pyc|main.py"|grep -v grep|awk '{print $2}') #/etc/init.d/bt restart #echo 'True' > /www/server/panel/data/restart.pl echo "Successfully upgraded to[$version]${Ver}"; ================================================ FILE: install/yumRepo_select.sh ================================================ #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH get_Yum_Repo(){ nodes=(http://mirrors.cloud.tencent.com/repo/centos7_base.repo http://mirrors.aliyun.com/repo/Centos-7.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/index.html) i=1 for node in ${nodes[@]}; do start=$(date +%s.%N) result=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${node}) if [ "$result" == "200" ];then end=`date +%s.%N` start_s=`echo $start | cut -d '.' -f 1` start_ns=`echo $start | cut -d '.' -f 2` end_s=`echo $end | cut -d '.' -f 1` end_ns=`echo $end | cut -d '.' -f 2` time_micro=$(( (10#$end_s-10#$start_s)*1000000 + (10#$end_ns/1000 - 10#$start_ns/1000) )) time_ms=$(($time_micro/1000)) values[$i]=$time_ms; urls[$time_ms]=$node i=$(($i+1)) if [ $time_ms -lt 50 ];then break; fi fi done j=5000 for n in ${values[@]}; do if [ $j -gt $n ];then j=$n fi if [ $j -lt 50 ];then break; fi done if [ $j = 5000 ];then yumRepo='False'; T_HOST='False' else mv -f /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.Bak yumRepo=${urls[$j]} my_tmp=$(echo $yumRepo|grep 'tencent') if [ "$my_tmp" ];then wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo elif [ $(echo $yumRepo|grep 'aliyun') ]; then wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo elif [ $(echo $yumRepo|grep '163') ];then wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo elif [ $(echo $yumRepo|grep 'tsinghua') ];then wget -O /etc/yum.repos.d/CentOS-Base.repo http://download.bt.cn/mirrors/repo/Centos7-Base-thu.repo fi yum makecache fi } centos_version=$(cat /etc/redhat-release | grep ' 7.' | grep -i centos) if [ "${centos_version}" ];then get_Yum_Repo fi