├── install_6.0.sh ├── install-ubuntu_6.0.sh ├── tools └── check.sh ├── README.md ├── init └── systemd │ └── btpanel.service ├── install ├── pip_select.sh ├── public.sh ├── pyenv │ └── activate.panel ├── selfhost.sh ├── conf │ └── softList.conf ├── update6.sh └── src │ ├── bt6.init │ └── bt7.init └── install_panel.sh /install_6.0.sh: -------------------------------------------------------------------------------- 1 | install_panel.sh -------------------------------------------------------------------------------- /install-ubuntu_6.0.sh: -------------------------------------------------------------------------------- 1 | install_panel.sh -------------------------------------------------------------------------------- /tools/check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 3 | export PATH 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pagoda Panel 2 | 3 | ```bash 4 | curl -sSL -o install_panel.sh https://github.com/PagodaPanel/install/raw/master/install_panel.sh 5 | 6 | # Normally 7 | bash install_panel.sh 8 | 9 | # Self-host server ( https://github.com/flucont/btcloud ) 10 | BT_SELFHOST='http://YOUR-SERVER' bash install_panel.sh 11 | 12 | # No AutoSwap 13 | NOSWAP=1 bash install_panel.sh 14 | ``` -------------------------------------------------------------------------------- /init/systemd/btpanel.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=BT-Panel - simple and safe web control panel 3 | Documentation=https://www.bt.cn/new/btcode.html 4 | After=network-online.target remote-fs.target nss-lookup.target 5 | Wants=network-online.target 6 | 7 | [Service] 8 | Type=forking 9 | ExecStart=/etc/init.d/bt start 10 | ExecReload=/etc/init.d/bt reload 11 | ExecStop=/etc/init.d/bt stop 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | 16 | -------------------------------------------------------------------------------- /install/pip_select.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 3 | pyenv_bin=/www/server/panel/pyenv/bin 4 | rep_path=${pyenv_bin}:$PATH 5 | if [ -d "$pyenv_bin" ];then 6 | PATH=$rep_path 7 | fi 8 | export PATH 9 | LANG=en_US.UTF-8 10 | get_PIP_URL(){ 11 | 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); 12 | i=1; 13 | for node in ${nodes[@]}; 14 | do 15 | start=`date +%s.%N` 16 | result=`curl -sS --connect-timeout 3 -m 60 $node/0/|grep Links` 17 | if [ "$result" != '' ];then 18 | end=`date +%s.%N` 19 | start_s=`echo $start | cut -d '.' -f 1` 20 | start_ns=`echo $start | cut -d '.' -f 2` 21 | end_s=`echo $end | cut -d '.' -f 1` 22 | end_ns=`echo $end | cut -d '.' -f 2` 23 | time_micro=$(( (10#$end_s-10#$start_s)*1000000 + (10#$end_ns/1000 - 10#$start_ns/1000) )) 24 | time_ms=$(($time_micro/1000)) 25 | values[$i]=$time_ms; 26 | urls[$time_ms]=$node 27 | i=$(($i+1)) 28 | if [ $time_ms -lt 50 ];then 29 | break; 30 | fi 31 | fi 32 | done 33 | j=5000 34 | for n in ${values[@]}; 35 | do 36 | if [ $j -gt $n ];then 37 | j=$n 38 | fi 39 | if [ $j -lt 50 ];then 40 | break; 41 | fi 42 | done 43 | if [ $j = 5000 ];then 44 | PIP_URL='False'; 45 | T_HOST='False' 46 | else 47 | PIP_URL=${urls[$j]} 48 | my_tmp=$(echo $PIP_URL|grep 'aliyun') 49 | if [ "$my_tmp" != "" ];then 50 | T_HOST=mirrors.aliyun.com 51 | elif [ $(echo $PIP_URL|grep 'tencent') != "" ];then 52 | T_HOST=mirrors.tencent.com 53 | elif [ $(echo $PIP_URL|grep 'doubanio') != "" ];then 54 | T_HOST=pypi.doubanio.com 55 | elif [ $(echo $PIP_URL|grep 'tsinghua') != "" ];then 56 | T_HOST=pypi.tuna.tsinghua.edu.cn 57 | elif [ $(echo $PIP_URL|grep 'pypi.org') != "" ];then 58 | T_HOST=pypi.org 59 | fi 60 | fi 61 | } 62 | 63 | get_PIP_URL 64 | if [ "$PIP_URL" != "False" ];then 65 | echo "$PIP_URL" 66 | if [ ! -d ~/.pip ];then 67 | mkdir -p ~/.pip 68 | fi 69 | cat > ~/.pip/pip.conf <&1|grep "gcc version"|awk '{print $3}') 63 | CMAKE_VER=$(cmake --version|grep version|awk '{print $3}') 64 | 65 | echo -e ${SYS_VERSION} 66 | echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO} gcc:${GCC_VER} cmake:${CMAKE_VER} 67 | echo -e ${SYS_INFO} 68 | } 69 | cpuInfo=$(getconf _NPROCESSORS_ONLN) 70 | if [ "${cpuInfo}" -ge "4" ];then 71 | GetCpuStat 72 | else 73 | cpuCore="1" 74 | fi 75 | GetPackManager 76 | 77 | if [ -d "/www/server/phpmyadmin/pma" ];then 78 | rm -rf /www/server/phpmyadmin/pma 79 | echo "Please update your panel!" 80 | fi 81 | 82 | if [ ! $NODE_URL ];then 83 | EN_CHECK=$(cat /www/server/panel/config/config.json |grep English) 84 | if [ -z "${EN_CHECK}" ];then 85 | echo '正在选择下载节点...'; 86 | else 87 | echo "selecting download node..."; 88 | fi 89 | get_node_url 90 | fi 91 | -------------------------------------------------------------------------------- /install/pyenv/activate.panel: -------------------------------------------------------------------------------- 1 | # This file must be used with "source bin/activate" *from bash* 2 | # you cannot run it directly 3 | 4 | 5 | if [ "${BASH_SOURCE-}" = "$0" ]; then 6 | echo "You must source this script: \$ source $0" >&2 7 | exit 33 8 | fi 9 | 10 | deactivate () { 11 | unset -f pydoc >/dev/null 2>&1 12 | 13 | # reset old environment variables 14 | # ! [ -z ${VAR+_} ] returns true if VAR is declared at all 15 | if ! [ -z "${_OLD_VIRTUAL_PATH:+_}" ] ; then 16 | PATH="$_OLD_VIRTUAL_PATH" 17 | export PATH 18 | unset _OLD_VIRTUAL_PATH 19 | fi 20 | if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then 21 | PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME" 22 | export PYTHONHOME 23 | unset _OLD_VIRTUAL_PYTHONHOME 24 | fi 25 | 26 | # This should detect bash and zsh, which have a hash command that must 27 | # be called to get it to forget past commands. Without forgetting 28 | # past commands the $PATH changes we made may not be respected 29 | if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then 30 | hash -r 2>/dev/null 31 | fi 32 | 33 | if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then 34 | PS1="$_OLD_VIRTUAL_PS1" 35 | export PS1 36 | unset _OLD_VIRTUAL_PS1 37 | fi 38 | 39 | unset VIRTUAL_ENV 40 | if [ ! "${1-}" = "nondestructive" ] ; then 41 | # Self destruct! 42 | unset -f deactivate 43 | fi 44 | } 45 | 46 | # unset irrelevant variables 47 | deactivate nondestructive 48 | 49 | VIRTUAL_ENV="/www/server/panel/pyenv" 50 | export VIRTUAL_ENV 51 | 52 | _OLD_VIRTUAL_PATH="$PATH" 53 | PATH="$VIRTUAL_ENV/bin:$PATH" 54 | export PATH 55 | 56 | # unset PYTHONHOME if set 57 | if ! [ -z "${PYTHONHOME+_}" ] ; then 58 | _OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME" 59 | unset PYTHONHOME 60 | fi 61 | 62 | if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then 63 | _OLD_VIRTUAL_PS1="${PS1-}" 64 | if [ "x" != x ] ; then 65 | PS1="${PS1-}" 66 | else 67 | PS1="(`basename \"$VIRTUAL_ENV\"`) ${PS1-}" 68 | fi 69 | export PS1 70 | fi 71 | 72 | # Make sure to unalias pydoc if it's already there 73 | alias pydoc 2>/dev/null >/dev/null && unalias pydoc || true 74 | 75 | pydoc () { 76 | python -m pydoc "$@" 77 | } 78 | 79 | # This should detect bash and zsh, which have a hash command that must 80 | # be called to get it to forget past commands. Without forgetting 81 | # past commands the $PATH changes we made may not be respected 82 | if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then 83 | hash -r 2>/dev/null 84 | fi 85 | -------------------------------------------------------------------------------- /install/selfhost.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BTDIR='/www/server/panel' 4 | ZIPFILE='' 5 | SERVER='http://YOUR-BTCLOUD-SERVER' # https://github.com/flucont/btcloud 6 | 7 | while [ $# -gt 0 ]; do 8 | case $1 in 9 | -d|--dir) 10 | BTDIR=${2%/} 11 | shift 12 | ;; 13 | -s|--server) 14 | SERVER=$2 15 | shift 16 | ;; 17 | -z|--zipfile) 18 | ZIPFILE=$2 19 | shift 20 | ;; 21 | *) 22 | echo "Unknown option: \"$1\"" 23 | exit 24 | esac 25 | shift 26 | done 27 | 28 | if [ -z "$BTDIR" ] ;then 29 | echo "Program dir error!" 30 | exit 31 | fi 32 | 33 | Replace(){ 34 | echo "Server: $SERVER" 35 | echo "Program dir: $BTDIR" 36 | 37 | rm -rf ${BTDIR}/class/*.so 38 | mv -f ${BTDIR}/class/PluginLoader-bak.py ${BTDIR}/class/PluginLoader.py 39 | sed -i "s|http://www.example.com|${SERVER}|g" ${BTDIR}/class/PluginLoader.py 40 | 41 | grep -rl --include=\*.py 'https://api.bt.cn' ${BTDIR}/class | xargs -I @ sed -i "s|https://api.bt.cn|${SERVER}|g" @ 42 | 43 | grep -rl --include=\*.py --exclude=clearModel.py 'https://www.bt.cn/api' ${BTDIR}/class | xargs -I @ sed -i "s|https://www.bt.cn/api|${SERVER}/api|g" @ 44 | grep -rl 'https://www.bt.cn/api' ${BTDIR}/script | xargs -I @ sed -i "s|https://www.bt.cn/api|${SERVER}/api|g" @ 45 | 46 | sed -i "s|httpUrl = public.get_url()|httpUrl = public.GetConfigValue('home')|g" ${BTDIR}/class/ajax.py 47 | sed -i "s|public.get_url()|public.GetConfigValue('home')|g" ${BTDIR}/class/jobs.py 48 | sed -i "s|public.get_url()|public.GetConfigValue('home')|g" ${BTDIR}/class/system.py 49 | 50 | sed -i "s|^def GetConfigValue(key):|&\n if key == 'home': return '${SERVER}'|g" ${BTDIR}/class/public.py 51 | sed -i "s|http://www.example.com|${SERVER}|g" ${BTDIR}/class/panelPlugin.py 52 | sed -i "s|#temp_file = temp_file.replace|temp_file = temp_file.replace|g" ${BTDIR}/class/panelPlugin.py 53 | 54 | # Uncomment it to use btcloud update script 55 | #grep -rl 'update6.sh' ${BTDIR} | xargs -I @ sed -i "s|https://cdn.jsdelivr.net/gh/PagodaPanel/install/install/update6.sh|${SERVER}/install/update6.sh|g" @ 56 | } 57 | 58 | if [ -z "$ZIPFILE" ] ;then 59 | Replace 60 | else 61 | ZIPFILE=$(realpath $ZIPFILE) 62 | echo "Zip FIle: $ZIPFILE" 63 | mkdir -p /tmp/pagodafile 64 | unzip -q -o $ZIPFILE -d /tmp/pagodafile 65 | BTDIR='/tmp/pagodafile/panel' 66 | Replace 67 | mv -f $ZIPFILE $ZIPFILE.bak 68 | cd /tmp/pagodafile && zip -q -r $ZIPFILE panel && cd - 69 | rm -rf /tmp/pagodafile 70 | fi 71 | 72 | echo Done! -------------------------------------------------------------------------------- /install/conf/softList.conf: -------------------------------------------------------------------------------- 1 | [{ 2 | "name": "Nginx", 3 | "versions": [{ 4 | "status": false, 5 | "version": "1.20" 6 | }, { 7 | "status": false, 8 | "version": "1.21" 9 | }, { 10 | "status": false, 11 | "version": "1.19" 12 | }, { 13 | "status": false, 14 | "version": "1.18" 15 | }, { 16 | "status": false, 17 | "version": "-Tengine2.2" 18 | }, { 19 | "status": false, 20 | "version": "openresty" 21 | }], 22 | "type": "Web服务器", 23 | "msg": "Nginx是一款轻量级的Web服务器!", 24 | "shell": "nginx.sh", 25 | "check": "server/nginx/sbin/nginx" 26 | }, 27 | { 28 | "name": "Apache", 29 | "versions": [{ 30 | "status": false, 31 | "version": "2.4" 32 | }, { 33 | "status": false, 34 | "version": "2.2" 35 | }], 36 | "type": "Web服务器", 37 | "msg": "Apache是世界使用排名第一的Web服务器软件。", 38 | "shell": "httpd.sh", 39 | "check": "server/apache/bin/httpd" 40 | }, 41 | { 42 | "name": "MySQL", 43 | "versions": [{ 44 | "status": false, 45 | "version": "5.1" 46 | }, { 47 | "status": false, 48 | "version": "5.5" 49 | }, { 50 | "status": false, 51 | "version": "5.6" 52 | }, { 53 | "status": false, 54 | "version": "5.7" 55 | }, { 56 | "status": false, 57 | "version": "8.0" 58 | }, { 59 | "status": false, 60 | "version": "AliSQL" 61 | }, { 62 | "status": false, 63 | "version": "mariadb_10.0" 64 | }, { 65 | "status": false, 66 | "version": "mariadb_10.1" 67 | }], 68 | "type": "数据库", 69 | "msg": "推荐安装!", 70 | "shell": "mysql.sh", 71 | "check": "server/mysql/bin/mysql" 72 | }, 73 | { 74 | "name": "Pure-Ftpd", 75 | "versions": [{ 76 | "status": false, 77 | "version": "1.0.49" 78 | }], 79 | "type": "FTP服务器", 80 | "msg": "PureFTPd是一款专注于程序健壮和软件安全的免费FTP服务器软件", 81 | "shell": "pure-ftpd.sh", 82 | "check": "server/pure-ftpd/bin/pure-pw" 83 | }, 84 | { 85 | "name": "PHP", 86 | "versions": [{ 87 | "status": false, 88 | "version": "5.2" 89 | }, { 90 | "status": false, 91 | "version": "5.3" 92 | }, { 93 | "status": false, 94 | "version": "5.4" 95 | }, { 96 | "status": false, 97 | "version": "5.5" 98 | }, { 99 | "status": false, 100 | "version": "5.6" 101 | }, { 102 | "status": false, 103 | "version": "7.0" 104 | }, { 105 | "status": false, 106 | "version": "7.1" 107 | }, { 108 | "status": false, 109 | "version": "7.2" 110 | }, { 111 | "status": false, 112 | "version": "7.3" 113 | }, { 114 | "status": false, 115 | "version": "7.4" 116 | },{ 117 | "status": false, 118 | "version": "8.0" 119 | }], 120 | "type": "语言解释器", 121 | "msg": "若非必要,请安装更新的版本!", 122 | "shell": "php.sh", 123 | "check": "server/php/VERSION/bin/php" 124 | }, 125 | { 126 | "name": "Tomcat", 127 | "versions": [{ 128 | "status": false, 129 | "version": "7" 130 | }, { 131 | "status": false, 132 | "version": "8" 133 | }, { 134 | "status": false, 135 | "version": "9" 136 | }], 137 | "type": "语言解释器", 138 | "msg": "java-ee解释器", 139 | "shell": "tomcat.sh", 140 | "check": "server/tomcat/bin/catalina.sh" 141 | }, 142 | { 143 | "name": "phpMyAdmin", 144 | "versions": [{ 145 | "status": false, 146 | "version": "4.0" 147 | }, { 148 | "status": false, 149 | "version": "4.4" 150 | }, { 151 | "status": false, 152 | "version": "4.7" 153 | }, { 154 | "status": false, 155 | "version": "4.9" 156 | }, { 157 | "status": false, 158 | "version": "4.8" 159 | }, { 160 | "status": false, 161 | "version": "5.0" 162 | }, { 163 | "status": false, 164 | "version": "5.1" 165 | }], 166 | "type": "数据库工具", 167 | "msg": "Web端MySQL管理工具", 168 | "shell": "phpmyadmin.sh", 169 | "check": "server/phpmyadmin/version.pl" 170 | } 171 | ] -------------------------------------------------------------------------------- /install/update6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 3 | export PATH 4 | LANG=en_US.UTF-8 5 | 6 | if [ ! -d /www/server/panel/BTPanel ];then 7 | echo "=============================================" 8 | echo "错误, 5.x不可以使用此命令升级!" 9 | echo "5.9平滑升级到6.0的命令:curl http://download.bt.cn/install/update_to_6.sh|bash" 10 | exit 0; 11 | fi 12 | 13 | download_Url='https://github.com/PagodaPanel/LinuxPanel/releases' 14 | bt_Url='https://raw.githubusercontent.com/PagodaPanel/install/master' 15 | 16 | cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"") 17 | if [[ "$cn" != "" ]];then 18 | download_Url='https://ghproxy.com/github.com/PagodaPanel/LinuxPanel/releases' 19 | bt_Url='https://fastly.jsdelivr.net/gh/PagodaPanel/install@latest' 20 | fi 21 | 22 | Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat') 23 | if [ "${Centos8Check}" ];then 24 | if [ ! -f "/usr/bin/python" ] && [ -f "/usr/bin/python3" ] && [ ! -d "/www/server/panel/pyenv" ]; then 25 | ln -sf /usr/bin/python3 /usr/bin/python 26 | fi 27 | fi 28 | 29 | mypip="pip" 30 | env_path=/www/server/panel/pyenv/bin/activate 31 | if [ -f $env_path ];then 32 | mypip="/www/server/panel/pyenv/bin/pip" 33 | fi 34 | 35 | setup_path=/www 36 | #version=$(curl -Ss --connect-timeout 5 -m 2 https://www.bt.cn/api/panel/get_version) 37 | version=$(grep -o "g.version = '.*'" /www/server/panel/class/common.py | cut -d "'" -f 2) 38 | 39 | if [ ! -z "$1" ]; then 40 | version="$1" 41 | fi 42 | 43 | armCheck=$(uname -m|grep arm) 44 | if [ "${armCheck}" ];then 45 | echo "Not support!" && exit 46 | fi 47 | 48 | if [ "$version" = 'latest' ];then 49 | wget -T 5 -O /tmp/panel.zip $download_Url/latest/download/update.zip 50 | else 51 | wget -T 5 -O /tmp/panel.zip $download_Url/download/v${version}/update.zip 52 | fi 53 | 54 | dsize=$(du -b /tmp/panel.zip|awk '{print $1}') 55 | if [ $dsize -lt 10240 ];then 56 | echo "获取更新包失败,请稍后更新" 57 | exit; 58 | fi 59 | unzip -o /tmp/panel.zip -d $setup_path/server/ > /dev/null 60 | rm -f /tmp/panel.zip 61 | cd $setup_path/server/panel/ 62 | check_bt=`cat /etc/init.d/bt` 63 | if [ "${check_bt}" = "" ];then 64 | rm -f /etc/init.d/bt 65 | wget -O /etc/init.d/bt $bt_Url/install/src/bt7.init -T 20 66 | chmod +x /etc/init.d/bt 67 | fi 68 | rm -f /www/server/panel/*.pyc 69 | rm -f /www/server/panel/class/*.pyc 70 | #pip install flask_sqlalchemy 71 | #pip install itsdangerous==0.24 72 | 73 | [[ -e $setup_path/server/panel/data/selfhost.pl ]] && BT_SELFHOST=$(cat $setup_path/server/panel/data/selfhost.pl | tr -d '[:space:]') 74 | if [ ! -z "$BT_SELFHOST" ]; then 75 | wget -O /tmp/selfhost.sh $bt_Url/install/selfhost.sh 76 | bash /tmp/selfhost.sh -s "$BT_SELFHOST" -d $setup_path/server/panel 77 | fi 78 | 79 | pip_list=$($mypip list) 80 | request_v=$(echo "$pip_list"|grep requests) 81 | if [ "$request_v" = "" ];then 82 | $mypip install requests 83 | fi 84 | openssl_v=$(echo "$pip_list"|grep pyOpenSSL) 85 | if [ "$openssl_v" = "" ];then 86 | $mypip install pyOpenSSL 87 | fi 88 | 89 | #cffi_v=$(echo "$pip_list"|grep cffi|grep 1.12.) 90 | #if [ "$cffi_v" = "" ];then 91 | # $mypip install cffi==1.12.3 92 | #fi 93 | 94 | pymysql=$(echo "$pip_list"|grep pymysql) 95 | if [ "$pymysql" = "" ];then 96 | $mypip install pymysql 97 | fi 98 | 99 | pymysql=$(echo "$pip_list"|grep pycryptodome) 100 | if [ "$pymysql" = "" ];then 101 | $mypip install pycryptodome 102 | fi 103 | 104 | #psutil=$(echo "$pip_list"|grep psutil|awk '{print $2}'|grep '5.7.') 105 | #if [ "$psutil" = "" ];then 106 | # $mypip install -U psutil 107 | #fi 108 | 109 | if [ -d /www/server/panel/class/BTPanel ];then 110 | rm -rf /www/server/panel/class/BTPanel 111 | fi 112 | 113 | chattr -i /etc/init.d/bt 114 | chmod +x /etc/init.d/bt 115 | echo "=====================================" 116 | rm -f /dev/shm/bt_sql_tips.pl 117 | oldproc=$(ps aux|grep -E "task.pyc|main.py"|grep -v grep|awk '{print $2}') 118 | if [ ! -z "$oldproc" ]; then 119 | kill $oldproc 120 | fi 121 | /etc/init.d/bt restart 122 | echo 'True' > /www/server/panel/data/restart.pl 123 | pkill -9 gunicorn & 124 | echo "已成功升级到[$version]${Ver}"; 125 | -------------------------------------------------------------------------------- /install/src/bt6.init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # chkconfig: 2345 55 25 3 | # description: bt Cloud Service 4 | 5 | ### BEGIN INIT INFO 6 | # Provides: bt 7 | # Required-Start: $all 8 | # Required-Stop: $all 9 | # Default-Start: 2 3 4 5 10 | # Default-Stop: 0 1 6 11 | # Short-Description: starts bt 12 | # Description: starts the bt 13 | ### END INIT INFO 14 | panel_init(){ 15 | panel_path=/www/server/panel 16 | pidfile=$panel_path/logs/panel.pid 17 | cd $panel_path 18 | env_path=$panel_path/pyenv/bin/activate 19 | if [ -f $env_path ];then 20 | source $env_path 21 | pythonV=$panel_path/pyenv/bin/python 22 | chmod -R 700 $panel_path/pyenv/bin 23 | else 24 | pythonV=/usr/bin/python 25 | fi 26 | reg="^#\!$pythonV\$" 27 | is_sed=$(cat $panel_path/BT-Panel|head -n 1|grep -E $reg) 28 | if [ "${is_sed}" = "" ];then 29 | sed -i "s@^#!.*@#!$pythonV@" $panel_path/BT-Panel 30 | fi 31 | is_sed=$(cat $panel_path/BT-Task|head -n 1|grep -E $reg) 32 | if [ "${is_sed}" = "" ];then 33 | sed -i "s@^#!.*@#!$pythonV@" $panel_path/BT-Task 34 | fi 35 | chmod 700 $panel_path/BT-Panel 36 | chmod 700 $panel_path/BT-Task 37 | log_file=$panel_path/logs/error.log 38 | task_log_file=$panel_path/logs/task.log 39 | if [ -f $panel_path/data/ssl.pl ];then 40 | log_file=/dev/null 41 | fi 42 | 43 | port=$(cat $panel_path/data/port.pl) 44 | } 45 | panel_init 46 | 47 | get_panel_pids(){ 48 | isStart=$(ps aux|grep -E '(runserver|BT-Panel)'|grep -v grep|awk '{print $2}'|xargs) 49 | pids=$isStart 50 | arr=$isStart 51 | } 52 | 53 | get_task_pids(){ 54 | isStart=$(ps aux|grep -E '(task.py|BT-Task)'|grep -v grep|awk '{print $2}'|xargs) 55 | pids=$isStart 56 | arr=$isStart 57 | } 58 | 59 | panel_start() 60 | { 61 | isStart=`ps aux|grep 'runserver:app'|grep -v grep|awk '{print $2}'` 62 | if [ "$isStart" != '' ];then 63 | kill -9 $isStart 64 | fi 65 | get_panel_pids 66 | if [ "$isStart" == '' ];then 67 | rm -f $pidfile 68 | panel_port_check 69 | echo -e "Starting Bt-Panel...\c" 70 | nohup $panel_path/BT-Panel >> $log_file 2>&1 & 71 | isStart="" 72 | n=0 73 | while [[ "$isStart" == "" ]]; 74 | do 75 | echo -e ".\c" 76 | sleep 0.5 77 | get_panel_pids 78 | let n+=1 79 | if [ $n -gt 8 ];then 80 | break; 81 | fi 82 | done 83 | if [ "$isStart" == '' ];then 84 | echo -e "\033[31mfailed\033[0m" 85 | echo '------------------------------------------------------' 86 | tail -n 20 $log_file 87 | echo '------------------------------------------------------' 88 | echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" 89 | fi 90 | echo -e " \033[32mdone\033[0m" 91 | else 92 | echo "Starting Bt-Panel... Bt-Panel (pid $(echo $isStart)) already running" 93 | fi 94 | 95 | get_task_pids 96 | if [ "$isStart" == '' ];then 97 | echo -e "Starting Bt-Tasks... \c" 98 | nohup $panel_path/BT-Task >> $task_log_file 2>&1 & 99 | sleep 0.2 100 | get_task_pids 101 | if [ "$isStart" == '' ];then 102 | echo -e "\033[31mfailed\033[0m" 103 | echo '------------------------------------------------------' 104 | tail -n 20 $task_log_file 105 | echo '------------------------------------------------------' 106 | echo -e "\033[31mError: BT-Task service startup failed.\033[0m" 107 | return; 108 | fi 109 | echo -e " \033[32mdone\033[0m" 110 | else 111 | echo "Starting Bt-Tasks... Bt-Tasks (pid $isStart) already running" 112 | fi 113 | } 114 | 115 | panel_port_check() 116 | { 117 | is_process=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $1}'|sort|uniq|xargs) 118 | for pn in ${is_process[@]} 119 | do 120 | if [ "$pn" = "nginx" ];then 121 | /etc/init.d/nginx restart 122 | fi 123 | 124 | if [ "$pn" = "httpd" ];then 125 | /etc/init.d/httpd restart 126 | fi 127 | 128 | if [ "$pn" = "mysqld" ];then 129 | /etc/init.d/mysqld restart 130 | fi 131 | 132 | if [ "$pn" = "superviso" ];then 133 | pkill -9 superviso 134 | sleep 0.2 135 | supervisord -c /etc/supervisor/supervisord.conf 136 | fi 137 | 138 | if [ "$pn" = "pure-ftpd" ];then 139 | /etc/init.d/pure-ftpd restart 140 | fi 141 | 142 | if [ "$pn" = "memcached" ];then 143 | /etc/init.d/memcached restart 144 | fi 145 | 146 | if [ "$pn" = "sudo" ];then 147 | if [ -f /etc/init.d/redis ];then 148 | /etc/init.d/redis restart 149 | fi 150 | fi 151 | 152 | if [ "$pn" = "php-fpm" ];then 153 | php_v=(52 53 54 55 56 70 71 72 73 74); 154 | for pv in ${php_v[@]}; 155 | do 156 | if [ -f /etc/init.d/php-fpm-${pv} ];then 157 | if [ -f /www/server/php/%{pv}/sbin/php-fpm ];then 158 | if [ -f /tmp/php-cgi-${pv}.sock ];then 159 | /etc/init.d/php-fpm-${pv} start 160 | fi 161 | /etc/init.d/php-fpm-${pv} restart 162 | fi 163 | fi 164 | done 165 | fi 166 | done 167 | 168 | is_ports=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $2}'|xargs) 169 | if [ "$is_ports" != '' ];then 170 | kill -9 $is_ports 171 | sleep 1 172 | fi 173 | } 174 | 175 | panel_stop() 176 | { 177 | echo -e "Stopping Bt-Tasks...\c"; 178 | get_task_pids 179 | arr=($pids) 180 | for p in ${arr[@]} 181 | do 182 | kill -9 $p 183 | done 184 | echo -e " \033[32mdone\033[0m" 185 | 186 | echo -e "Stopping Bt-Panel...\c"; 187 | 188 | get_panel_pids 189 | for p in ${arr[@]} 190 | do 191 | kill -9 $p &>/dev/null 192 | done 193 | 194 | if [ -f $pidfile ];then 195 | rm -f $pidfile 196 | fi 197 | echo -e " \033[32mdone\033[0m" 198 | } 199 | 200 | panel_status() 201 | { 202 | port=$(cat $panel_path/data/port.pl) 203 | get_panel_pids 204 | if [ "$isStart" != '' ];then 205 | echo -e "\033[32mBt-Panel (pid $(echo $isStart)) already running\033[0m" 206 | else 207 | echo -e "\033[31mBt-Panel not running\033[0m" 208 | fi 209 | 210 | get_task_pids 211 | if [ "$isStart" != '' ];then 212 | echo -e "\033[32mBt-Task (pid $isStart) already running\033[0m" 213 | else 214 | echo -e "\033[31mBt-Task not running\033[0m" 215 | fi 216 | } 217 | 218 | panel_reload() 219 | { 220 | isStart=$(ps aux|grep 'runserver:app'|grep -v grep|awk '{print $2}') 221 | if [ "$isStart" != '' ];then 222 | kill -9 $isStart 223 | sleep 0.5 224 | fi 225 | get_panel_pids 226 | if [ "$isStart" != '' ];then 227 | 228 | get_panel_pids 229 | for p in ${arr[@]} 230 | do 231 | kill -9 $p 232 | done 233 | rm -f $pidfile 234 | panel_port_check 235 | echo -e "Reload Bt-Panel.\c"; 236 | nohup $panel_path/BT-Panel >> $log_file 2>&1 & 237 | isStart="" 238 | n=0 239 | while [[ "$isStart" == "" ]]; 240 | do 241 | echo -e ".\c" 242 | sleep 0.5 243 | get_panel_pids 244 | let n+=1 245 | if [ $n -gt 8 ];then 246 | break; 247 | fi 248 | done 249 | if [ "$isStart" == '' ];then 250 | echo -e "\033[31mfailed\033[0m" 251 | echo '------------------------------------------------------' 252 | tail -n 20 $log_file 253 | echo '------------------------------------------------------' 254 | echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" 255 | return; 256 | fi 257 | echo -e " \033[32mdone\033[0m" 258 | else 259 | echo -e "\033[31mBt-Panel not running\033[0m" 260 | panel_start 261 | fi 262 | } 263 | 264 | install_used() 265 | { 266 | if [ ! -f $panel_path/aliyun.pl ];then 267 | return; 268 | fi 269 | password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 12) 270 | username=$($pythonV $panel_path/tools.py panel $password) 271 | echo "$password" > $panel_path/default.pl 272 | rm -f $panel_path/aliyun.pl 273 | } 274 | 275 | error_logs() 276 | { 277 | tail -n 100 $log_file 278 | } 279 | 280 | 281 | case "$1" in 282 | 'start') 283 | install_used 284 | panel_start 285 | ;; 286 | 'stop') 287 | panel_stop 288 | ;; 289 | 'restart') 290 | panel_stop 291 | sleep 1 292 | panel_start 293 | ;; 294 | 'reload') 295 | panel_reload 296 | ;; 297 | 'status') 298 | panel_status 299 | ;; 300 | 'logs') 301 | error_logs 302 | ;; 303 | 'panel') 304 | $pythonV $panel_path/tools.py cli $2 305 | ;; 306 | 'default') 307 | port=$(cat $panel_path/data/port.pl) 308 | password=$(cat $panel_path/default.pl) 309 | if [ -f $panel_path/data/domain.conf ];then 310 | address=$(cat $panel_path/data/domain.conf) 311 | fi 312 | if [ -f $panel_path/data/admin_path.pl ];then 313 | auth_path=$(cat $panel_path/data/admin_path.pl) 314 | fi 315 | if [ "$address" = "" ];then 316 | address=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress) 317 | fi 318 | pool=http 319 | if [ -f $panel_path/data/ssl.pl ];then 320 | pool=https 321 | fi 322 | echo -e "==================================================================" 323 | echo -e "\033[32mBT-Panel default info!\033[0m" 324 | echo -e "==================================================================" 325 | echo "Bt-Panel-URL: $pool://$address:$port$auth_path" 326 | echo -e `$pythonV $panel_path/tools.py username` 327 | echo -e "password: $password" 328 | echo -e "\033[33mWarning:\033[0m" 329 | echo -e "\033[33mIf you cannot access the panel, \033[0m" 330 | echo -e "\033[33mrelease the following port (8888|888|80|443|20|21) in the security group\033[0m" 331 | echo -e "==================================================================" 332 | ;; 333 | *) 334 | $pythonV $panel_path/tools.py cli $1 335 | ;; 336 | esac 337 | -------------------------------------------------------------------------------- /install/src/bt7.init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # chkconfig: 2345 55 25 3 | # description: bt Cloud Service 4 | 5 | ### BEGIN INIT INFO 6 | # Provides: bt 7 | # Required-Start: $all 8 | # Required-Stop: $all 9 | # Default-Start: 2 3 4 5 10 | # Default-Stop: 0 1 6 11 | # Short-Description: starts bt 12 | # Description: starts the bt 13 | ### END INIT INFO 14 | panel_init(){ 15 | panel_path=/www/server/panel 16 | pidfile=$panel_path/logs/panel.pid 17 | cd $panel_path 18 | env_path=$panel_path/pyenv/bin/activate 19 | if [ -f $env_path ];then 20 | source $env_path 21 | pythonV=$panel_path/pyenv/bin/python 22 | chmod -R 700 $panel_path/pyenv/bin 23 | else 24 | pythonV=/usr/bin/python 25 | fi 26 | reg="^#\!$pythonV\$" 27 | is_sed=$(cat $panel_path/BT-Panel|head -n 1|grep -E $reg) 28 | if [ "${is_sed}" = "" ];then 29 | sed -i "s@^#!.*@#!$pythonV@" $panel_path/BT-Panel 30 | fi 31 | is_sed=$(cat $panel_path/BT-Task|head -n 1|grep -E $reg) 32 | if [ "${is_sed}" = "" ];then 33 | sed -i "s@^#!.*@#!$pythonV@" $panel_path/BT-Task 34 | fi 35 | chmod 700 $panel_path/BT-Panel 36 | chmod 700 $panel_path/BT-Task 37 | log_file=$panel_path/logs/error.log 38 | task_log_file=$panel_path/logs/task.log 39 | if [ -f $panel_path/data/ssl.pl ];then 40 | log_file=/dev/null 41 | fi 42 | 43 | port=$(cat $panel_path/data/port.pl) 44 | } 45 | panel_init 46 | 47 | get_panel_pids(){ 48 | isStart=$(ps aux|grep -E '(runserver|BT-Panel)'|grep -v grep|awk '{print $2}'|xargs) 49 | pids=$isStart 50 | arr=$isStart 51 | } 52 | 53 | get_task_pids(){ 54 | isStart=$(ps aux|grep -E '(task.py|BT-Task)'|grep -v grep|awk '{print $2}'|xargs) 55 | pids=$isStart 56 | arr=$isStart 57 | } 58 | 59 | panel_start() 60 | { 61 | isStart=`ps aux|grep 'runserver:app'|grep -v grep|awk '{print $2}'` 62 | if [ "$isStart" != '' ];then 63 | kill -9 $isStart 64 | fi 65 | get_panel_pids 66 | if [ "$isStart" == '' ];then 67 | rm -f $pidfile 68 | panel_port_check 69 | echo -e "Starting Bt-Panel...\c" 70 | nohup $panel_path/BT-Panel >> $log_file 2>&1 & 71 | isStart="" 72 | n=0 73 | while [[ "$isStart" == "" ]]; 74 | do 75 | echo -e ".\c" 76 | sleep 0.5 77 | get_panel_pids 78 | let n+=1 79 | if [ $n -gt 8 ];then 80 | break; 81 | fi 82 | done 83 | if [ "$isStart" == '' ];then 84 | echo -e "\033[31mfailed\033[0m" 85 | echo '------------------------------------------------------' 86 | tail -n 20 $log_file 87 | echo '------------------------------------------------------' 88 | echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" 89 | fi 90 | echo -e " \033[32mdone\033[0m" 91 | else 92 | echo "Starting Bt-Panel... Bt-Panel (pid $(echo $isStart)) already running" 93 | fi 94 | 95 | get_task_pids 96 | if [ "$isStart" == '' ];then 97 | echo -e "Starting Bt-Tasks... \c" 98 | nohup $panel_path/BT-Task >> $task_log_file 2>&1 & 99 | sleep 0.2 100 | get_task_pids 101 | if [ "$isStart" == '' ];then 102 | echo -e "\033[31mfailed\033[0m" 103 | echo '------------------------------------------------------' 104 | tail -n 20 $task_log_file 105 | echo '------------------------------------------------------' 106 | echo -e "\033[31mError: BT-Task service startup failed.\033[0m" 107 | return; 108 | fi 109 | echo -e " \033[32mdone\033[0m" 110 | else 111 | echo "Starting Bt-Tasks... Bt-Tasks (pid $isStart) already running" 112 | fi 113 | } 114 | 115 | panel_port_check() 116 | { 117 | is_process=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $1}'|sort|uniq|xargs) 118 | for pn in ${is_process[@]} 119 | do 120 | if [ "$pn" = "nginx" ];then 121 | /etc/init.d/nginx restart 122 | fi 123 | 124 | if [ "$pn" = "httpd" ];then 125 | /etc/init.d/httpd restart 126 | fi 127 | 128 | if [ "$pn" = "mysqld" ];then 129 | /etc/init.d/mysqld restart 130 | fi 131 | 132 | if [ "$pn" = "superviso" ];then 133 | pkill -9 superviso 134 | sleep 0.2 135 | supervisord -c /etc/supervisor/supervisord.conf 136 | fi 137 | 138 | if [ "$pn" = "pure-ftpd" ];then 139 | /etc/init.d/pure-ftpd restart 140 | fi 141 | 142 | if [ "$pn" = "memcached" ];then 143 | /etc/init.d/memcached restart 144 | fi 145 | 146 | if [ "$pn" = "sudo" ];then 147 | if [ -f /etc/init.d/redis ];then 148 | /etc/init.d/redis restart 149 | fi 150 | fi 151 | 152 | if [ "$pn" = "php-fpm" ];then 153 | php_v=(52 53 54 55 56 70 71 72 73 74); 154 | for pv in ${php_v[@]}; 155 | do 156 | if [ -f /etc/init.d/php-fpm-${pv} ];then 157 | if [ -f /www/server/php/%{pv}/sbin/php-fpm ];then 158 | if [ -f /tmp/php-cgi-${pv}.sock ];then 159 | /etc/init.d/php-fpm-${pv} start 160 | fi 161 | /etc/init.d/php-fpm-${pv} restart 162 | fi 163 | fi 164 | done 165 | fi 166 | done 167 | 168 | is_ports=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $2}'|xargs) 169 | if [ "$is_ports" != '' ];then 170 | kill -9 $is_ports 171 | sleep 1 172 | fi 173 | } 174 | 175 | panel_stop() 176 | { 177 | echo -e "Stopping Bt-Tasks...\c"; 178 | get_task_pids 179 | arr=($pids) 180 | for p in ${arr[@]} 181 | do 182 | kill -9 $p 183 | done 184 | echo -e " \033[32mdone\033[0m" 185 | 186 | echo -e "Stopping Bt-Panel...\c"; 187 | 188 | get_panel_pids 189 | for p in ${arr[@]} 190 | do 191 | kill -9 $p &>/dev/null 192 | done 193 | 194 | if [ -f $pidfile ];then 195 | rm -f $pidfile 196 | fi 197 | echo -e " \033[32mdone\033[0m" 198 | } 199 | 200 | panel_status() 201 | { 202 | port=$(cat $panel_path/data/port.pl) 203 | get_panel_pids 204 | if [ "$isStart" != '' ];then 205 | echo -e "\033[32mBt-Panel (pid $(echo $isStart)) already running\033[0m" 206 | else 207 | echo -e "\033[31mBt-Panel not running\033[0m" 208 | fi 209 | 210 | get_task_pids 211 | if [ "$isStart" != '' ];then 212 | echo -e "\033[32mBt-Task (pid $isStart) already running\033[0m" 213 | else 214 | echo -e "\033[31mBt-Task not running\033[0m" 215 | fi 216 | } 217 | 218 | panel_reload() 219 | { 220 | isStart=$(ps aux|grep 'runserver:app'|grep -v grep|awk '{print $2}') 221 | if [ "$isStart" != '' ];then 222 | kill -9 $isStart 223 | sleep 0.5 224 | fi 225 | get_panel_pids 226 | if [ "$isStart" != '' ];then 227 | 228 | get_panel_pids 229 | for p in ${arr[@]} 230 | do 231 | kill -9 $p 232 | done 233 | rm -f $pidfile 234 | panel_port_check 235 | echo -e "Reload Bt-Panel.\c"; 236 | nohup $panel_path/BT-Panel >> $log_file 2>&1 & 237 | isStart="" 238 | n=0 239 | while [[ "$isStart" == "" ]]; 240 | do 241 | echo -e ".\c" 242 | sleep 0.5 243 | get_panel_pids 244 | let n+=1 245 | if [ $n -gt 8 ];then 246 | break; 247 | fi 248 | done 249 | if [ "$isStart" == '' ];then 250 | echo -e "\033[31mfailed\033[0m" 251 | echo '------------------------------------------------------' 252 | tail -n 20 $log_file 253 | echo '------------------------------------------------------' 254 | echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" 255 | return; 256 | fi 257 | echo -e " \033[32mdone\033[0m" 258 | else 259 | echo -e "\033[31mBt-Panel not running\033[0m" 260 | panel_start 261 | fi 262 | } 263 | 264 | install_used() 265 | { 266 | if [ ! -f $panel_path/aliyun.pl ];then 267 | return; 268 | fi 269 | password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 12) 270 | username=$($pythonV $panel_path/tools.py panel $password) 271 | safe_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8) 272 | echo "$safe_path" > $panel_path/admin_path.pl 273 | echo "$password" > $panel_path/default.pl 274 | rm -f $panel_path/aliyun.pl 275 | } 276 | 277 | error_logs() 278 | { 279 | tail -n 100 $log_file 280 | } 281 | 282 | 283 | case "$1" in 284 | 'start') 285 | install_used 286 | panel_start 287 | ;; 288 | 'stop') 289 | panel_stop 290 | ;; 291 | 'restart') 292 | panel_stop 293 | sleep 1 294 | panel_start 295 | ;; 296 | 'reload') 297 | panel_reload 298 | ;; 299 | 'status') 300 | panel_status 301 | ;; 302 | 'logs') 303 | error_logs 304 | ;; 305 | 'panel') 306 | $pythonV $panel_path/tools.py cli $2 307 | ;; 308 | 'default') 309 | 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) 310 | port=$(cat $panel_path/data/port.pl) 311 | password=$(cat $panel_path/default.pl) 312 | if [ -f $panel_path/data/domain.conf ];then 313 | address=$(cat $panel_path/data/domain.conf) 314 | fi 315 | if [ -f $panel_path/data/admin_path.pl ];then 316 | auth_path=$(cat $panel_path/data/admin_path.pl) 317 | fi 318 | if [ "$address" = "" ];then 319 | address=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress) 320 | fi 321 | pool=http 322 | if [ -f $panel_path/data/ssl.pl ];then 323 | pool=https 324 | fi 325 | echo -e "==================================================================" 326 | echo -e "\033[32mBT-Panel default info!\033[0m" 327 | echo -e "==================================================================" 328 | echo "外网面板地址: $pool://$address:$port$auth_path" 329 | echo "内网面板地址: http://${LOCAL_IP}:$port$auth_path" 330 | echo -e "\033[33m*以下仅为初始默认账户密码,若无法登录请执行bt命令重置账户/密码登录\033[0m" 331 | echo -e `$pythonV $panel_path/tools.py username` 332 | echo -e "password: $password" 333 | echo -e "\033[33mIf you cannot access the panel,\033[0m" 334 | echo -e "\033[33mrelease the following panel port [${port}] in the security group\033[0m" 335 | echo -e "\033[33m若无法访问面板,请检查防火墙/安全组是否有放行面板[${port}]端口\033[0m" 336 | echo -e "==================================================================" 337 | ;; 338 | *) 339 | $pythonV $panel_path/tools.py cli $1 340 | ;; 341 | esac 342 | -------------------------------------------------------------------------------- /install_panel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 3 | export PATH 4 | LANG=en_US.UTF-8 5 | 6 | panel_Url='https://github.com/PagodaPanel/LinuxPanel/releases/latest/download/install.zip' 7 | bt_Url='https://raw.githubusercontent.com/PagodaPanel/install/master' 8 | 9 | cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"") 10 | if [[ "$cn" != "" ]];then 11 | panel_Url='https://ghproxy.com/github.com/PagodaPanel/LinuxPanel/releases/latest/download/install.zip' 12 | bt_Url='https://fastly.jsdelivr.net/gh/PagodaPanel/install@latest' 13 | fi 14 | 15 | if [ "$1" == "dev" ];then 16 | panel_Url='https://ghproxy.com/github.com/PagodaPanel/LinuxPanel/releases/download/beta/install.zip' 17 | fi 18 | 19 | if [ $(whoami) != "root" ];then 20 | echo "请使用root权限执行宝塔安装命令!" 21 | exit 1; 22 | fi 23 | 24 | is64bit=$(getconf LONG_BIT) 25 | if [ "${is64bit}" != '64' ];then 26 | Red_Error "抱歉, 当前面板版本不支持32位系统, 请使用64位系统或安装宝塔5.9!"; 27 | fi 28 | 29 | Centos6Check=$(cat /etc/redhat-release | grep ' 6.' | grep -iE 'centos|Red Hat') 30 | if [ "${Centos6Check}" ];then 31 | echo "Centos6不支持安装宝塔面板,请更换Centos7/8安装宝塔面板" 32 | exit 1 33 | fi 34 | 35 | UbuntuCheck=$(cat /etc/issue|grep Ubuntu|awk '{print $2}'|cut -f 1 -d '.') 36 | if [ "${UbuntuCheck}" ] && [ "${UbuntuCheck}" -lt "16" ];then 37 | echo "Ubuntu ${UbuntuCheck}不支持安装宝塔面板,建议更换Ubuntu18/20安装宝塔面板" 38 | exit 1 39 | fi 40 | 41 | cd ~ 42 | setup_path="/www" 43 | python_bin=$setup_path/server/panel/pyenv/bin/python 44 | cpu_cpunt=$(cat /proc/cpuinfo|grep processor|wc -l) 45 | 46 | if [ "$1" ];then 47 | IDC_CODE=$1 48 | fi 49 | 50 | GetSysInfo(){ 51 | if [ -s "/etc/redhat-release" ];then 52 | SYS_VERSION=$(cat /etc/redhat-release) 53 | elif [ -s "/etc/issue" ]; then 54 | SYS_VERSION=$(cat /etc/issue) 55 | fi 56 | SYS_INFO=$(uname -a) 57 | SYS_BIT=$(getconf LONG_BIT) 58 | MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}') 59 | CPU_INFO=$(getconf _NPROCESSORS_ONLN) 60 | 61 | echo -e ${SYS_VERSION} 62 | echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO} 63 | echo -e ${SYS_INFO} 64 | echo -e "请截图以上报错信息发帖至论坛www.bt.cn/bbs求助" 65 | } 66 | Red_Error(){ 67 | echo '================================================='; 68 | printf '\033[1;31;40m%b\033[0m\n' "$@"; 69 | GetSysInfo 70 | exit 1; 71 | } 72 | Lock_Clear(){ 73 | if [ -f "/etc/bt_crack.pl" ];then 74 | chattr -R -ia /www 75 | chattr -ia /etc/init.d/bt 76 | \cp -rpa /www/backup/panel/vhost/* /www/server/panel/vhost/ 77 | mv /www/server/panel/BTPanel/__init__.bak /www/server/panel/BTPanel/__init__.py 78 | rm -f /etc/bt_crack.pl 79 | fi 80 | } 81 | Install_Check(){ 82 | if [ "${INSTALL_FORCE}" ];then 83 | return 84 | fi 85 | echo -e "----------------------------------------------------" 86 | echo -e "检查已有其他Web/mysql环境,安装宝塔可能影响现有站点及数据" 87 | echo -e "Web/mysql service is alreday installed,Can't install panel" 88 | echo -e "----------------------------------------------------" 89 | echo -e "已知风险/Enter yes to force installation" 90 | read -p "输入yes强制安装: " yes; 91 | if [ "$yes" != "yes" ];then 92 | echo -e "------------" 93 | echo "取消安装" 94 | exit; 95 | fi 96 | INSTALL_FORCE="true" 97 | } 98 | System_Check(){ 99 | MYSQLD_CHECK=$(ps -ef |grep mysqld|grep -v grep|grep -v /www/server/mysql) 100 | PHP_CHECK=$(ps -ef|grep php-fpm|grep master|grep -v /www/server/php) 101 | NGINX_CHECK=$(ps -ef|grep nginx|grep master|grep -v /www/server/nginx) 102 | HTTPD_CHECK=$(ps -ef |grep -E 'httpd|apache'|grep -v /www/server/apache|grep -v grep) 103 | if [ "${PHP_CHECK}" ] || [ "${MYSQLD_CHECK}" ] || [ "${NGINX_CHECK}" ] || [ "${HTTPD_CHECK}" ];then 104 | Install_Check 105 | fi 106 | } 107 | Get_Pack_Manager(){ 108 | if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then 109 | PM="yum" 110 | elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then 111 | PM="apt-get" 112 | fi 113 | } 114 | Auto_Swap() 115 | { 116 | swap=$(free |grep Swap|awk '{print $2}') 117 | if [ "${swap}" -gt 1 ];then 118 | echo "Swap total sizse: $swap"; 119 | return; 120 | fi 121 | if [ ! -d /www ];then 122 | mkdir /www 123 | fi 124 | swapFile="/www/swap" 125 | dd if=/dev/zero of=$swapFile bs=1M count=1025 126 | mkswap -f $swapFile 127 | swapon $swapFile 128 | echo "$swapFile swap swap defaults 0 0" >> /etc/fstab 129 | swap=`free |grep Swap|awk '{print $2}'` 130 | if [ $swap -gt 1 ];then 131 | echo "Swap total sizse: $swap"; 132 | return; 133 | fi 134 | 135 | sed -i "/\/www\/swap/d" /etc/fstab 136 | rm -f $swapFile 137 | } 138 | Service_Add(){ 139 | if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then 140 | chkconfig --add bt 141 | chkconfig --level 2345 bt on 142 | Centos9Check=$(cat /etc/redhat-release |grep ' 9') 143 | if [ "${Centos9Check}" ];then 144 | wget -O /usr/lib/systemd/system/btpanel.service ${bt_Url}/init/systemd/btpanel.service 145 | systemctl enable btpanel 146 | fi 147 | elif [ "${PM}" == "apt-get" ]; then 148 | update-rc.d bt defaults 149 | fi 150 | } 151 | Set_Centos_Repo(){ 152 | HUAWEI_CHECK=$(cat /etc/motd |grep "Huawei Cloud") 153 | if [ "${HUAWEI_CHECK}" ] && [ "${is64bit}" == "64" ];then 154 | \cp -rpa /etc/yum.repos.d/ /etc/yumBak 155 | sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo 156 | sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo 157 | rm -f /etc/yum.repos.d/epel.repo 158 | rm -f /etc/yum.repos.d/epel-* 159 | fi 160 | ALIYUN_CHECK=$(cat /etc/motd|grep "Alibaba Cloud ") 161 | if [ "${ALIYUN_CHECK}" ] && [ "${is64bit}" == "64" ] && [ ! -f "/etc/yum.repos.d/Centos-vault-8.5.2111.repo" ];then 162 | rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo 163 | wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo 164 | wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo 165 | 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 166 | sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo 167 | fi 168 | MIRROR_CHECK=$(cat /etc/yum.repos.d/CentOS-Linux-AppStream.repo |grep "[^#]mirror.centos.org") 169 | if [ "${MIRROR_CHECK}" ] && [ "${is64bit}" == "64" ];then 170 | \cp -rpa /etc/yum.repos.d/ /etc/yumBak 171 | sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo 172 | sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo 173 | fi 174 | } 175 | get_node_url(){ 176 | if [ ! -f /bin/curl ];then 177 | if [ "${PM}" = "yum" ]; then 178 | yum install curl -y 179 | elif [ "${PM}" = "apt-get" ]; then 180 | apt-get install curl -y 181 | fi 182 | fi 183 | 184 | NODE_URL='http://download.bt.cn'; 185 | download_Url=$NODE_URL 186 | echo "Download node: $download_Url"; 187 | echo '---------------------------------------------'; 188 | } 189 | Remove_Package(){ 190 | local PackageName=$1 191 | if [ "${PM}" == "yum" ];then 192 | isPackage=$(rpm -q ${PackageName}|grep "not installed") 193 | if [ -z "${isPackage}" ];then 194 | yum remove ${PackageName} -y 195 | fi 196 | elif [ "${PM}" == "apt-get" ];then 197 | isPackage=$(dpkg -l|grep ${PackageName}) 198 | if [ "${PackageName}" ];then 199 | apt-get remove ${PackageName} -y 200 | fi 201 | fi 202 | } 203 | Install_RPM_Pack(){ 204 | yumPath=/etc/yum.conf 205 | Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat') 206 | if [ "${Centos8Check}" ];then 207 | Set_Centos_Repo 208 | fi 209 | isExc=$(cat $yumPath|grep httpd) 210 | if [ "$isExc" = "" ];then 211 | echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >> $yumPath 212 | fi 213 | 214 | #SYS_TYPE=$(uname -a|grep x86_64) 215 | #yumBaseUrl=$(cat /etc/yum.repos.d/CentOS-Base.repo|grep baseurl=http|cut -d '=' -f 2|cut -d '$' -f 1|head -n 1) 216 | #[ "${yumBaseUrl}" ] && checkYumRepo=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${yumBaseUrl}) 217 | #if [ "${checkYumRepo}" != "200" ] && [ "${SYS_TYPE}" ];then 218 | # curl -Ss --connect-timeout 3 -m 60 http://download.bt.cn/install/yumRepo_select.sh|bash 219 | #fi 220 | 221 | #尝试同步时间(从bt.cn) 222 | echo 'Synchronizing system time...' 223 | getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time) 224 | if [ "${getBtTime}" ];then 225 | date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")" 226 | fi 227 | 228 | if [ -z "${Centos8Check}" ]; then 229 | yum install ntp -y 230 | rm -rf /etc/localtime 231 | ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 232 | 233 | #尝试同步国际时间(从ntp服务器) 234 | ntpdate 0.asia.pool.ntp.org 235 | setenforce 0 236 | fi 237 | 238 | startTime=`date +%s` 239 | 240 | sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 241 | #yum remove -y python-requests python3-requests python-greenlet python3-greenlet 242 | 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" 243 | yum install -y ${yumPacks} 244 | 245 | for yumPack in ${yumPacks} 246 | do 247 | rpmPack=$(rpm -q ${yumPack}) 248 | packCheck=$(echo ${rpmPack}|grep not) 249 | if [ "${packCheck}" ]; then 250 | yum install ${yumPack} -y 251 | fi 252 | done 253 | if [ -f "/usr/bin/dnf" ]; then 254 | dnf install -y redhat-rpm-config 255 | fi 256 | 257 | ALI_OS=$(cat /etc/redhat-release |grep "Alibaba Cloud Linux release 3") 258 | if [ -z "${ALI_OS}" ];then 259 | yum install epel-release -y 260 | fi 261 | } 262 | Install_Deb_Pack(){ 263 | ln -sf bash /bin/sh 264 | UBUNTU_22=$(cat /etc/issue|grep "Ubuntu 22") 265 | if [ "${UBUNTU_22}" ];then 266 | apt-get remove needrestart -y 267 | fi 268 | apt-get update -y 269 | apt-get install ruby -y 270 | apt-get install lsb-release -y 271 | #apt-get install ntp ntpdate -y 272 | #/etc/init.d/ntp stop 273 | #update-rc.d ntp remove 274 | #cat >>~/.profile< /var/spool/cron/crontabs/root 304 | chmod 600 /var/spool/cron/crontabs/root 305 | fi 306 | fi 307 | } 308 | Get_Versions(){ 309 | redhat_version_file="/etc/redhat-release" 310 | deb_version_file="/etc/issue" 311 | if [ -f $redhat_version_file ];then 312 | os_type='el' 313 | is_aliyunos=$(cat $redhat_version_file|grep Aliyun) 314 | if [ "$is_aliyunos" != "" ];then 315 | return 316 | fi 317 | os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]') 318 | if [ "${os_version}" = "5" ];then 319 | os_version="" 320 | fi 321 | if [ -z "${os_version}" ];then 322 | os_version=$(cat /etc/redhat-release |grep Stream|grep -oE 8) 323 | fi 324 | else 325 | os_type='ubuntu' 326 | os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+') 327 | if [ "${os_version}" = "" ];then 328 | os_type='debian' 329 | os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+') 330 | if [ "${os_version}" = "" ];then 331 | os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+') 332 | fi 333 | if [ "${os_version}" = "8" ];then 334 | os_version="" 335 | fi 336 | if [ "${is64bit}" = '32' ];then 337 | os_version="" 338 | fi 339 | else 340 | if [ "$os_version" = "14" ];then 341 | os_version="" 342 | fi 343 | if [ "$os_version" = "12" ];then 344 | os_version="" 345 | fi 346 | if [ "$os_version" = "19" ];then 347 | os_version="" 348 | fi 349 | if [ "$os_version" = "21" ];then 350 | os_version="" 351 | fi 352 | if [ "$os_version" = "20" ];then 353 | os_version2004=$(cat /etc/issue|grep 20.04) 354 | if [ -z "${os_version2004}" ];then 355 | os_version="" 356 | fi 357 | fi 358 | fi 359 | fi 360 | } 361 | Install_Python_Lib(){ 362 | curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash 363 | pyenv_path="/www/server/panel" 364 | if [ -f $pyenv_path/pyenv/bin/python ];then 365 | is_ssl=$($python_bin -c "import ssl" 2>&1|grep cannot) 366 | $pyenv_path/pyenv/bin/python3.7 -V 367 | if [ $? -eq 0 ] && [ -z "${is_ssl}" ];then 368 | chmod -R 700 $pyenv_path/pyenv/bin 369 | is_package=$($python_bin -m psutil 2>&1|grep package) 370 | if [ "$is_package" = "" ];then 371 | wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 5 372 | $pyenv_path/pyenv/bin/pip install -U pip 373 | $pyenv_path/pyenv/bin/pip install -U setuptools 374 | $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt 375 | fi 376 | source $pyenv_path/pyenv/bin/activate 377 | chmod -R 700 $pyenv_path/pyenv/bin 378 | return 379 | else 380 | rm -rf $pyenv_path/pyenv 381 | fi 382 | fi 383 | 384 | is_loongarch64=$(uname -a|grep loongarch64) 385 | if [ "$is_loongarch64" != "" ] && [ -f "/usr/bin/yum" ];then 386 | yumPacks="python3-devel python3-pip python3-psutil python3-gevent python3-pyOpenSSL python3-paramiko python3-flask python3-rsa python3-requests python3-six python3-websocket-client" 387 | yum install -y ${yumPacks} 388 | for yumPack in ${yumPacks} 389 | do 390 | rpmPack=$(rpm -q ${yumPack}) 391 | packCheck=$(echo ${rpmPack}|grep not) 392 | if [ "${packCheck}" ]; then 393 | yum install ${yumPack} -y 394 | fi 395 | done 396 | 397 | pip3 install -U pip 398 | pip3 install Pillow psutil pyinotify pycryptodome upyun oss2 pymysql qrcode qiniu redis pymongo Cython configparser cos-python-sdk-v5 supervisor gevent-websocket pyopenssl 399 | pip3 install flask==1.1.4 400 | pip3 install Pillow -U 401 | 402 | pyenv_bin=/www/server/panel/pyenv/bin 403 | mkdir -p $pyenv_bin 404 | ln -sf /usr/local/bin/pip3 $pyenv_bin/pip 405 | ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3 406 | ln -sf /usr/local/bin/pip3 $pyenv_bin/pip3.7 407 | 408 | if [ -f "/usr/bin/python3.7" ];then 409 | ln -sf /usr/bin/python3.7 $pyenv_bin/python 410 | ln -sf /usr/bin/python3.7 $pyenv_bin/python3 411 | ln -sf /usr/bin/python3.7 $pyenv_bin/python3.7 412 | elif [ -f "/usr/bin/python3.6" ]; then 413 | ln -sf /usr/bin/python3.6 $pyenv_bin/python 414 | ln -sf /usr/bin/python3.6 $pyenv_bin/python3 415 | ln -sf /usr/bin/python3.6 $pyenv_bin/python3.7 416 | fi 417 | 418 | echo > $pyenv_bin/activate 419 | 420 | return 421 | fi 422 | 423 | py_version="3.7.8" 424 | mkdir -p $pyenv_path 425 | echo "True" > /www/disk.pl 426 | if [ ! -w /www/disk.pl ];then 427 | Red_Error "ERROR: Install python env fielded." "ERROR: /www目录无法写入,请检查目录/用户/磁盘权限!" 428 | fi 429 | os_type='el' 430 | os_version='7' 431 | is_export_openssl=0 432 | Get_Versions 433 | 434 | echo "OS: $os_type - $os_version" 435 | is_aarch64=$(uname -a|grep aarch64) 436 | if [ "$is_aarch64" != "" ];then 437 | is64bit="aarch64" 438 | fi 439 | 440 | if [ -f "/www/server/panel/pymake.pl" ];then 441 | os_version="" 442 | rm -f /www/server/panel/pymake.pl 443 | fi 444 | 445 | if [ "${os_version}" != "" ];then 446 | pyenv_file="/www/pyenv.tar.gz" 447 | wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10 448 | if [ "$?" != "0" ];then 449 | wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10 450 | fi 451 | tmp_size=$(du -b $pyenv_file|awk '{print $1}') 452 | if [ $tmp_size -lt 703460 ];then 453 | rm -f $pyenv_file 454 | echo "ERROR: Download python env fielded." 455 | else 456 | echo "Install python env..." 457 | tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null 458 | chmod -R 700 $pyenv_path/pyenv/bin 459 | if [ ! -f $pyenv_path/pyenv/bin/python ];then 460 | rm -f $pyenv_file 461 | Red_Error "ERROR: Install python env fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!" 462 | fi 463 | $pyenv_path/pyenv/bin/python3.7 -V 464 | if [ $? -eq 0 ];then 465 | rm -f $pyenv_file 466 | ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip 467 | ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython 468 | source $pyenv_path/pyenv/bin/activate 469 | return 470 | else 471 | rm -f $pyenv_file 472 | rm -rf $pyenv_path/pyenv 473 | fi 474 | fi 475 | fi 476 | 477 | cd /www 478 | python_src='/www/python_src.tar.xz' 479 | python_src_path="/www/Python-${py_version}" 480 | wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 5 481 | tmp_size=$(du -b $python_src|awk '{print $1}') 482 | if [ $tmp_size -lt 10703460 ];then 483 | rm -f $python_src 484 | Red_Error "ERROR: Download python source code fielded." "ERROR: 下载宝塔运行环境失败,请尝试重新安装!" 485 | fi 486 | tar xvf $python_src 487 | rm -f $python_src 488 | cd $python_src_path 489 | ./configure --prefix=$pyenv_path/pyenv 490 | make -j$cpu_cpunt 491 | make install 492 | if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then 493 | rm -rf $python_src_path 494 | Red_Error "ERROR: Make python env fielded." "ERROR: 编译宝塔运行环境失败!" 495 | fi 496 | cd ~ 497 | rm -rf $python_src_path 498 | wget -O $pyenv_path/pyenv/bin/activate $bt_Url/install/pyenv/activate.panel -T 5 499 | wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.8.txt -T 5 500 | ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip 501 | ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python 502 | ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip 503 | ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython 504 | chmod -R 700 $pyenv_path/pyenv/bin 505 | $pyenv_path/pyenv/bin/pip install -U pip 506 | $pyenv_path/pyenv/bin/pip install -U setuptools 507 | $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2 508 | $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt 509 | source $pyenv_path/pyenv/bin/activate 510 | 511 | is_gevent=$($python_bin -m gevent 2>&1|grep -oE package) 512 | is_psutil=$($python_bin -m psutil 2>&1|grep -oE package) 513 | if [ "${is_gevent}" != "${is_psutil}" ];then 514 | Red_Error "ERROR: psutil/gevent install failed!" 515 | fi 516 | } 517 | Install_Bt(){ 518 | panelPort="8888" 519 | if [ -f ${setup_path}/server/panel/data/port.pl ];then 520 | panelPort=$(cat ${setup_path}/server/panel/data/port.pl) 521 | else 522 | RE_NUM=$(expr $RANDOM % 5) 523 | if [ "${RE_NUM}" == "1" ];then 524 | panelPort=$(expr $RANDOM % 55535 + 10000) 525 | fi 526 | fi 527 | mkdir -p ${setup_path}/server/panel/logs 528 | mkdir -p ${setup_path}/server/panel/vhost/apache 529 | mkdir -p ${setup_path}/server/panel/vhost/nginx 530 | mkdir -p ${setup_path}/server/panel/vhost/rewrite 531 | mkdir -p ${setup_path}/server/panel/install 532 | mkdir -p /www/server 533 | mkdir -p /www/wwwroot 534 | mkdir -p /www/wwwlogs 535 | mkdir -p /www/backup/database 536 | mkdir -p /www/backup/site 537 | 538 | if [ ! -d "/etc/init.d" ];then 539 | mkdir -p /etc/init.d 540 | fi 541 | 542 | if [ -f "/etc/init.d/bt" ]; then 543 | /etc/init.d/bt stop 544 | sleep 1 545 | fi 546 | 547 | wget -O /etc/init.d/bt ${bt_Url}/install/src/bt6.init -T 10 548 | wget -O panel.zip ${panel_Url} -T 10 549 | 550 | if [ -f "${setup_path}/server/panel/data/default.db" ];then 551 | if [ -d "/${setup_path}/server/panel/old_data" ];then 552 | rm -rf ${setup_path}/server/panel/old_data 553 | fi 554 | mkdir -p ${setup_path}/server/panel/old_data 555 | d_format=$(date +"%Y%m%d_%H%M%S") 556 | \cp -arf ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/data/default_backup_${d_format}.db 557 | mv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.db 558 | mv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.db 559 | mv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.pl 560 | mv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.pl 561 | fi 562 | 563 | if [ ! -f "/usr/bin/unzip" ]; then 564 | if [ "${PM}" = "yum" ]; then 565 | yum install unzip -y 566 | elif [ "${PM}" = "apt-get" ]; then 567 | apt-get update 568 | apt-get install unzip -y 569 | fi 570 | fi 571 | 572 | unzip -o panel.zip -d ${setup_path}/server/ > /dev/null 573 | wget -O /www/server/panel/install/public.sh ${bt_Url}/install/public.sh -T 10 574 | 575 | if [ -d "${setup_path}/server/panel/old_data" ];then 576 | mv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.db 577 | mv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.db 578 | mv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.pl 579 | mv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.pl 580 | if [ -d "/${setup_path}/server/panel/old_data" ];then 581 | rm -rf ${setup_path}/server/panel/old_data 582 | fi 583 | fi 584 | 585 | if [ ! -f ${setup_path}/server/panel/tools.py ] || [ ! -f ${setup_path}/server/panel/BT-Panel ];then 586 | ls -lh panel.zip 587 | Red_Error "ERROR: Failed to download, please try install again!" "ERROR: 下载宝塔失败,请尝试重新安装!" 588 | fi 589 | 590 | rm -f panel.zip 591 | rm -f ${setup_path}/server/panel/class/*.pyc 592 | rm -f ${setup_path}/server/panel/*.pyc 593 | 594 | chmod +x /etc/init.d/bt 595 | chmod -R 600 ${setup_path}/server/panel 596 | chmod -R +x ${setup_path}/server/panel/script 597 | ln -sf /etc/init.d/bt /usr/bin/bt 598 | echo "${panelPort}" > ${setup_path}/server/panel/data/port.pl 599 | wget -O /etc/init.d/bt ${bt_Url}/install/src/bt7.init -T 10 600 | wget -O /www/server/panel/init.sh ${bt_Url}/install/src/bt7.init -T 10 601 | wget -O /www/server/panel/data/softList.conf ${download_Url}/install/conf/softList.conf 602 | } 603 | Set_Bt_Panel(){ 604 | Run_User="www" 605 | wwwUser=$(cat /etc/passwd|cut -d ":" -f 1|grep ^www$) 606 | if [ "${wwwUser}" != "www" ];then 607 | groupadd ${Run_User} 608 | useradd -s /sbin/nologin -g ${Run_User} ${Run_User} 609 | fi 610 | 611 | password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8) 612 | sleep 1 613 | admin_auth="/www/server/panel/data/admin_path.pl" 614 | if [ ! -f ${admin_auth} ];then 615 | auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8) 616 | echo "/${auth_path}" > ${admin_auth} 617 | fi 618 | chmod -R 700 $pyenv_path/pyenv/bin 619 | /www/server/panel/pyenv/bin/pip3 install flask -U 620 | /www/server/panel/pyenv/bin/pip3 install flask-sock 621 | auth_path=$(cat ${admin_auth}) 622 | cd ${setup_path}/server/panel/ 623 | /etc/init.d/bt start 624 | $python_bin -m py_compile tools.py 625 | $python_bin tools.py username 626 | username=$($python_bin tools.py panel ${password}) 627 | cd ~ 628 | echo "${password}" > ${setup_path}/server/panel/default.pl 629 | chmod 600 ${setup_path}/server/panel/default.pl 630 | sleep 3 631 | /etc/init.d/bt restart 632 | sleep 3 633 | isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}') 634 | LOCAL_CURL=$(curl 127.0.0.1:8888/login 2>&1 |grep -i html) 635 | if [ -z "${isStart}" ] && [ -z "${LOCAL_CURL}" ];then 636 | /etc/init.d/bt 22 637 | cd /www/server/panel/pyenv/bin 638 | touch t.pl 639 | ls -al python3.7 python 640 | lsattr python3.7 python 641 | Red_Error "ERROR: The BT-Panel service startup failed." "ERROR: 宝塔启动失败" 642 | fi 643 | } 644 | Set_Firewall(){ 645 | sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}') 646 | if [ "${PM}" = "apt-get" ]; then 647 | apt-get install -y ufw 648 | if [ -f "/usr/sbin/ufw" ];then 649 | ufw allow 20/tcp 650 | ufw allow 21/tcp 651 | ufw allow 22/tcp 652 | ufw allow 80/tcp 653 | ufw allow 443/tcp 654 | ufw allow 888/tcp 655 | ufw allow ${panelPort}/tcp 656 | ufw allow ${sshPort}/tcp 657 | ufw allow 39000:40000/tcp 658 | ufw_status=`ufw status` 659 | echo y|ufw enable 660 | ufw default deny 661 | ufw reload 662 | fi 663 | else 664 | if [ -f "/etc/init.d/iptables" ];then 665 | iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT 666 | iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT 667 | iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 668 | iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT 669 | iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT 670 | iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT 671 | iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT 672 | iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT 673 | #iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT 674 | iptables -A INPUT -p icmp --icmp-type any -j ACCEPT 675 | iptables -A INPUT -s localhost -d localhost -j ACCEPT 676 | iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 677 | iptables -P INPUT DROP 678 | service iptables save 679 | sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config 680 | iptables_status=$(service iptables status | grep 'not running') 681 | if [ "${iptables_status}" == '' ];then 682 | service iptables restart 683 | fi 684 | else 685 | AliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux") 686 | [ "${AliyunCheck}" ] && return 687 | yum install firewalld -y 688 | [ "${Centos8Check}" ] && yum reinstall python3-six -y 689 | systemctl enable firewalld 690 | systemctl start firewalld 691 | firewall-cmd --set-default-zone=public > /dev/null 2>&1 692 | firewall-cmd --permanent --zone=public --add-port=20/tcp > /dev/null 2>&1 693 | firewall-cmd --permanent --zone=public --add-port=21/tcp > /dev/null 2>&1 694 | firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1 695 | firewall-cmd --permanent --zone=public --add-port=80/tcp > /dev/null 2>&1 696 | firewall-cmd --permanent --zone=public --add-port=443/tcp > /dev/null 2>&1 697 | firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1 698 | firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1 699 | firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp > /dev/null 2>&1 700 | #firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1 701 | firewall-cmd --reload 702 | fi 703 | fi 704 | } 705 | Get_Ip_Address(){ 706 | getIpAddress="" 707 | getIpAddress=$(curl -fsSL --connect-timeout 10 -m 60 https://ipinfo.io/ip) 708 | 709 | ipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))") 710 | if [ "${ipv4Check}" == "None" ];then 711 | ipv6Address=$(echo ${getIpAddress}|tr -d "[]") 712 | ipv6Check=$($python_bin -c "import re; print(re.match('^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))") 713 | if [ "${ipv6Check}" == "None" ]; then 714 | getIpAddress="SERVER_IP" 715 | else 716 | echo "True" > ${setup_path}/server/panel/data/ipv6.pl 717 | sleep 1 718 | /etc/init.d/bt restart 719 | fi 720 | fi 721 | 722 | if [ "${getIpAddress}" != "SERVER_IP" ];then 723 | echo "${getIpAddress}" > ${setup_path}/server/panel/data/iplist.txt 724 | fi 725 | 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) 726 | } 727 | Setup_Count(){ 728 | echo /www > /var/bt_setupPath.conf 729 | } 730 | Install_Main(){ 731 | startTime=`date +%s` 732 | Lock_Clear 733 | System_Check 734 | Get_Pack_Manager 735 | get_node_url 736 | 737 | MEM_TOTAL=$(free -g|grep Mem|awk '{print $2}') 738 | if [ "${MEM_TOTAL}" -le "1" ];then 739 | [[ -z "$NOSWAP" ]] && Auto_Swap 740 | fi 741 | 742 | if [ "${PM}" = "yum" ]; then 743 | Install_RPM_Pack 744 | elif [ "${PM}" = "apt-get" ]; then 745 | Install_Deb_Pack 746 | fi 747 | 748 | Install_Python_Lib 749 | Install_Bt 750 | 751 | [[ -e /www/server/panel/data/selfhost.pl ]] && BT_SELFHOST=$(cat /www/server/panel/data/selfhost.pl | tr -d '[:space:]') 752 | if [ ! -z "$BT_SELFHOST" ]; then 753 | wget -O /tmp/selfhost.sh $bt_Url/install/selfhost.sh 754 | bash /tmp/selfhost.sh -s "$BT_SELFHOST" -d /www/server/panel 755 | echo "$BT_SELFHOST" > /www/server/panel/data/selfhost.pl 756 | fi 757 | 758 | Set_Bt_Panel 759 | Service_Add 760 | Set_Firewall 761 | 762 | Get_Ip_Address 763 | Setup_Count ${IDC_CODE} 764 | } 765 | 766 | echo " 767 | +---------------------------------------------------------------------- 768 | | Bt-WebPanel FOR CentOS/Ubuntu/Debian 769 | +---------------------------------------------------------------------- 770 | | Copyright © 2015-2099 BT-SOFT(http://www.bt.cn) All rights reserved. 771 | +---------------------------------------------------------------------- 772 | | The WebPanel URL will be http://SERVER_IP:8888 when installed. 773 | +---------------------------------------------------------------------- 774 | " 775 | while [ "$go" != 'y' ] && [ "$go" != 'n' ] 776 | do 777 | read -p "Do you want to install Bt-Panel to the $setup_path directory now?(y/n): " go; 778 | done 779 | 780 | if [ "$go" == 'n' ];then 781 | exit; 782 | fi 783 | 784 | ARCH_LINUX=$(cat /etc/os-release |grep "Arch Linux") 785 | if [ "${ARCH_LINUX}" ] && [ -f "/usr/bin/pacman" ];then 786 | pacman -Sy 787 | pacman -S curl wget unzip firewalld openssl pkg-config make gcc cmake libxml2 libxslt libvpx gd libsodium oniguruma sqlite libzip autoconf inetutils sudo --noconfirm 788 | fi 789 | 790 | Install_Main 791 | echo > /www/server/panel/data/bind.pl 792 | echo -e "==================================================================" 793 | echo -e "\033[32mCongratulations! Installed successfully!\033[0m" 794 | echo -e "==================================================================" 795 | echo "外网面板地址: http://${getIpAddress}:${panelPort}${auth_path}" 796 | echo "内网面板地址: http://${LOCAL_IP}:${panelPort}${auth_path}" 797 | echo -e "username: $username" 798 | echo -e "password: $password" 799 | echo -e "\033[33mIf you cannot access the panel,\033[0m" 800 | echo -e "\033[33mrelease the following panel port [${panelPort}] in the security group\033[0m" 801 | echo -e "\033[33m若无法访问面板,请检查防火墙/安全组是否有放行面板[${panelPort}]端口\033[0m" 802 | echo -e "==================================================================" 803 | 804 | endTime=`date +%s` 805 | ((outTime=($endTime-$startTime)/60)) 806 | echo -e "Time consumed:\033[32m $outTime \033[0mMinute!" 807 | --------------------------------------------------------------------------------