Apache/Nginx/php/MySQL/pgsql/gitlab/java(已有环境不可安装)
#!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHLANG=en_US.UTF-8cd ~setup_path="/www"python_bin=$setup_path/server/panel/pyenv/bin/pythoncpu_cpunt=$(cat /proc/cpuinfo|grep processor|wc -l)if [ "$1" ];thenIDC_CODE=$1fiGetSysInfo(){if [ -s "/etc/redhat-release" ];thenSYS_VERSION=$(cat /etc/redhat-release)elif [ -s "/etc/issue" ]; thenSYS_VERSION=$(cat /etc/issue)fiSYS_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' "$1";GetSysInfoexit 1;}is64bit=$(getconf LONG_BIT)if [ "${is64bit}" != '64' ];thenRed_Error "抱歉, 当前面板版本不支持32位系统, 请使用64位系统或安装宝塔5.9!";fiLock_Clear(){if [ -f "/etc/bt_crack.pl" ];thenchattr -R -ia /wwwchattr -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__.pyrm -f /etc/bt_crack.plfi}Install_Check(){while [ "$yes" != 'yes' ] && [ "$yes" != 'n' ]doecho -e "----------------------------------------------------"echo -e "已有Web环境,安装宝塔可能影响现有站点"echo -e "Web service is alreday installed,Can't install panel"echo -e "----------------------------------------------------"read -p "输入yes强制安装/Enter yes to force installation (yes/n): " yes;doneif [ "$yes" == 'n' ];thenexit;fi}System_Check(){for serviceS in nginx httpd mysqlddoif [ -f "/etc/init.d/${serviceS}" ]; thenif [ "${serviceS}" = "httpd" ]; thenserviceCheck=$(cat /etc/init.d/${serviceS}|grep /www/server/apache)elif [ "${serviceS}" = "mysqld" ]; thenserviceCheck=$(cat /etc/init.d/${serviceS}|grep /www/server/mysql)elseserviceCheck=$(cat /etc/init.d/${serviceS}|grep /www/server/${serviceS})fi[ -z "${serviceCheck}" ] && Install_Checkfidone}Get_Pack_Manager(){if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; thenPM="yum"elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; thenPM="apt-get"fi}Auto_Swap(){swap=$(free |grep Swap|awk '{print $2}')if [ "${swap}" -gt 1 ];thenecho "Swap total sizse: $swap";return;fiif [ ! -d /www ];thenmkdir /wwwfiswapFile="/www/swap"dd if=/dev/zero of=$swapFile bs=1M count=1025mkswap -f $swapFileswapon $swapFileecho "$swapFile swap swap defaults 0 0" >> /etc/fstabswap=`free |grep Swap|awk '{print $2}'`if [ $swap -gt 1 ];thenecho "Swap total sizse: $swap";return;fised -i "/\/www\/swap/d" /etc/fstabrm -f $swapFile}Service_Add(){if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; thenchkconfig --add btchkconfig --level 2345 bt onelif [ "${PM}" == "apt-get" ]; thenupdate-rc.d bt defaultsfi}get_node_url(){if [ ! -f /bin/curl ];thenif [ "${PM}" = "yum" ]; thenyum install curl -yelif [ "${PM}" = "apt-get" ]; thenapt-get install curl -yfifiecho '---------------------------------------------';echo "Selected download node...";nodes=(http://dg2.bt.cn http://dg1.bt.cn http://180.101.160.68:5880 http://103.224.251.67 http://45.76.53.20 http://120.206.184.160 http://113.107.111.78 http://128.1.164.196);tmp_file1=/dev/shm/net_test1.pltmp_file2=/dev/shm/net_test2.pl[ -f "${tmp_file1}" ] && rm -f ${tmp_file1}[ -f "${tmp_file2}" ] && rm -f ${tmp_file2}touch $tmp_file1touch $tmp_file2for node in ${nodes[@]};doNODE_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" ];thenif [ $TIME_TOTAL -lt 100 ];thenif [ $RES -ge 1500 ];thenecho "$RES $node" >> $tmp_file1fielseif [ $RES -ge 1500 ];thenecho "$TIME_TOTAL $node" >> $tmp_file2fifii=$(($i+1))if [ $TIME_TOTAL -lt 100 ];thenif [ $RES -ge 3000 ];thenbreak;fififidoneNODE_URL=$(cat $tmp_file1|sort -r -g -t " " -k 1|head -n 1|awk '{print $2}')if [ -z "$NODE_URL" ];thenNODE_URL=$(cat $tmp_file2|sort -g -t " " -k 1|head -n 1|awk '{print $2}')if [ -z "$NODE_URL" ];thenNODE_URL='http://download.bt.cn';fifirm -f $tmp_file1rm -f $tmp_file2download_Url=$NODE_URLecho "Download node: $download_Url";echo '---------------------------------------------';}Remove_Package(){local PackageNmae=$1if [ "${PM}" == "yum" ];thenisPackage=$(rpm -q ${PackageNmae}|grep "not installed")if [ -z "${isPackage}" ];thenyum remove ${PackageNmae} -yfielif [ "${PM}" == "apt-get" ];thenisPackage=$(dpkg -l|grep ${PackageNmae})if [ "${PackageNmae}" ];thenapt-get remove ${PackageNmae} -yfifi}Install_RPM_Pack(){yumPath=/etc/yum.confCentos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')isExc=$(cat $yumPath|grep httpd)if [ "$isExc" = "" ];thenecho "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >> $yumPathfiyumBaseUrl=$(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" ];thencurl -Ss --connect-timeout 3 -m 60 http://download.bt.cn/install/yumRepo_select.sh|bashfi#尝试同步时间(从bt.cn)echo 'Synchronizing system time...'getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time)if [ "${getBtTime}" ];thendate -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"fiif [ -z "${Centos8Check}" ]; thenyum install ntp -yrm -rf /etc/localtimeln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime#尝试同步国际时间(从ntp服务器)ntpdate 0.asia.pool.ntp.orgsetenforce 0fistartTime=`date +%s`sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config#yum remove -y python-requests python3-requests python-greenlet python3-greenletyumPacks="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}dorpmPack=$(rpm -q ${yumPack})packCheck=$(echo ${rpmPack}|grep not)if [ "${packCheck}" ]; thenyum install ${yumPack} -yfidoneif [ -f "/usr/bin/dnf" ]; thendnf install -y redhat-rpm-configfiyum install epel-release -y}Install_Deb_Pack(){ln -sf bash /bin/shapt-get update -yapt-get install ruby -yapt-get install lsb-release -y#apt-get install ntp ntpdate -y#/etc/init.d/ntp stop#update-rc.d ntp remove#cat >>~/.profile<<EOF#TZ='Asia/Shanghai'; export TZ#EOF#rm -rf /etc/localtime#cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime#echo 'Synchronizing system time...'#ntpdate 0.asia.pool.ntp.org#apt-get upgrade -yfor pace in wget curl libcurl4-openssl-dev gcc make zip unzip openssl libssl-dev gcc libxml2 libxml2-dev libxslt zlib1g zlib1g-dev libjpeg-dev libpng-dev lsof libpcre3 libpcre3-dev cron net-tools swig build-essential libffi-dev libbz2-dev libncurses-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libdb++-dev libpcap-dev xz-utils git;do apt-get -y install $pace --force-yes; doneif [ ! -d '/etc/letsencrypt' ];thenmkdir -p /etc/letsencrypmkdir -p /var/spool/cronif [ ! -f '/var/spool/cron/crontabs/root' ];thenecho '' > /var/spool/cron/crontabs/rootchmod 600 /var/spool/cron/crontabs/rootfifi}Install_Bt(){panelPort="8888"if [ -f ${setup_path}/server/panel/data/port.pl ];thenpanelPort=$(cat ${setup_path}/server/panel/data/port.pl)fimkdir -p ${setup_path}/server/panel/logsmkdir -p ${setup_path}/server/panel/vhost/apachemkdir -p ${setup_path}/server/panel/vhost/nginxmkdir -p ${setup_path}/server/panel/vhost/rewritemkdir -p ${setup_path}/server/panel/installmkdir -p /www/servermkdir -p /www/wwwrootmkdir -p /www/wwwlogsmkdir -p /www/backup/databasemkdir -p /www/backup/siteif [ ! -f "/usr/bin/unzip" ]; thenif [ "${PM}" = "yum" ]; thenyum install unzip -yelif [ "${PM}" = "apt-get" ]; thenapt-get install unzip -yfifiif [ -f "/etc/init.d/bt" ]; then/etc/init.d/bt stopsleep 1fiwget -O panel.zip ${download_Url}/install/src/panel6.zip -T 10wget -O /etc/init.d/bt ${download_Url}/install/src/bt6.init -T 10wget -O /www/server/panel/install/public.sh ${download_Url}/install/public.sh -T 10if [ -f "${setup_path}/server/panel/data/default.db" ];thenif [ -d "/${setup_path}/server/panel/old_data" ];thenrm -rf ${setup_path}/server/panel/old_datafimkdir -p ${setup_path}/server/panel/old_datad_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}.dbmv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.dbmv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.dbmv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.plmv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.plfiunzip -o panel.zip -d ${setup_path}/server/ > /dev/nullif [ -d "${setup_path}/server/panel/old_data" ];thenmv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.dbmv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.dbmv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.plmv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.plif [ -d "/${setup_path}/server/panel/old_data" ];thenrm -rf ${setup_path}/server/panel/old_datafifirm -f panel.zipif [ ! -f ${setup_path}/server/panel/tools.py ];thenRed_Error "ERROR: Failed to download, please try install again!"firm -f ${setup_path}/server/panel/class/*.pycrm -f ${setup_path}/server/panel/*.pycchmod +x /etc/init.d/btchmod -R 600 ${setup_path}/server/panelchmod -R +x ${setup_path}/server/panel/scriptln -sf /etc/init.d/bt /usr/bin/btecho "${panelPort}" > ${setup_path}/server/panel/data/port.plwget -O /etc/init.d/bt ${download_Url}/install/src/bt7.init -T 10wget -O /www/server/panel/init.sh ${download_Url}/install/src/bt7.init -T 10}Install_Python_Lib(){curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bashpyenv_path="/www/server/panel"if [ -f $pyenv_path/pyenv/bin/python ];thenchmod -R 700 $pyenv_path/pyenv/binis_package=$($python_bin -m psutil 2>&1|grep package)if [ "$is_package" = "" ];thenwget -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.txtfisource $pyenv_path/pyenv/bin/activatereturnfipy_version="3.7.8"mkdir -p $pyenv_pathos_type='el'os_version='7'is_export_openssl=0Get_VersionsCentos6_OpensslOther_Opensslecho "OS: $os_type - $os_version"is_aarch64=$(uname -a|grep aarch64)if [ "$is_aarch64" != "" ];thenos_version="aarch64"fiif [ "${os_version}" != "" ];thenpyenv_file="/www/pyenv.tar.gz"wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10tmp_size=$(du -b $pyenv_file|awk '{print $1}')if [ $tmp_size -lt 703460 ];thenrm -f $pyenv_fileecho "ERROR: Download python env fielded."elseecho "Install python env..."tar zxvf $pyenv_file -C $pyenv_path/ &> /dev/nullchmod -R 700 $pyenv_path/pyenv/binif [ ! -f $pyenv_path/pyenv/bin/python ];thenrm -f $pyenv_fileRed_Error "ERROR: Install python env fielded."firm -f $pyenv_fileln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpipln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpythonsource $pyenv_path/pyenv/bin/activatereturnfifiif [ -f /usr/local/openssl/lib/libssl.so ];thenexport LDFLAGS="-L/usr/local/openssl/lib"export CPPFLAGS="-I/usr/local/openssl/include"export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig"echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib" >> /etc/profilesource /etc/profileficd /wwwpython_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 5tmp_size=$(du -b $python_src|awk '{print $1}')if [ $tmp_size -lt 10703460 ];thenrm -f $python_srcRed_Error "ERROR: Download python source code fielded."fitar xvf $python_srcrm -f $python_srccd $python_src_path./configure --prefix=$pyenv_path/pyenvmake -j$cpu_cpuntmake installif [ ! -f $pyenv_path/pyenv/bin/python3.7 ];thenrm -rf $python_src_pathRed_Error "ERROR: Make python env fielded."ficd ~rm -rf $python_src_pathwget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 5wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.8.txt -T 5ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pipln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/pythonln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpipln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpythonchmod -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.txtsource $pyenv_path/pyenv/bin/activate}Other_Openssl(){openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];thenopensslVersion="1.0.2r"if [ ! -f "/usr/local/openssl/lib/libssl.so" ];thencd /wwwopenssl_src_file=/www/openssl.tar.gzwget -O $openssl_src_file ${download_Url}/src/openssl-${opensslVersion}.tar.gztmp_size=$(du -b $openssl_src_file|awk '{print $1}')if [ $tmp_size -lt 703460 ];thenrm -f $openssl_src_fileRed_Error "ERROR: Download openssl-1.0.2 source code fielded."fitar -zxf $openssl_src_filerm -f $openssl_src_filecd openssl-${opensslVersion}#zlib-dynamic shared./config --openssldir=/usr/local/openssl zlib-dynamic sharedmake -j${cpuCore}make installecho "/usr/local/openssl/lib" > /etc/ld.so.conf.d/zopenssl.confldconfigcd ..rm -rf openssl-${opensslVersion}is_export_openssl=1cd ~fifi}Insatll_Libressl(){openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];thenopensslVersion="3.0.2"cd /wwwopenssl_src_file=/www/openssl.tar.gzwget -O $openssl_src_file ${download_Url}/install/pyenv/libressl-${opensslVersion}.tar.gztmp_size=$(du -b $openssl_src_file|awk '{print $1}')if [ $tmp_size -lt 703460 ];thenrm -f $openssl_src_fileRed_Error "ERROR: Download libressl-$opensslVersion source code fielded."fitar -zxf $openssl_src_filerm -f $openssl_src_filecd libressl-${opensslVersion}./config –prefix=/usr/local/libmake -j${cpuCore}make installldconfigldconfig -vcd ..rm -rf libressl-${opensslVersion}is_export_openssl=1cd ~fi}Centos6_Openssl(){if [ "$os_type" != 'el' ];thenreturnfiif [ "$os_version" != '6' ];thenreturnfiecho 'Centos6 install openssl-1.0.2...'openssl_rpm_file="/www/openssl.rpm"wget -O $openssl_rpm_file $download_Url/rpm/centos6/${is64bit}/bt-openssl102.rpm -T 10tmp_size=$(du -b $openssl_rpm_file|awk '{print $1}')if [ $tmp_size -lt 102400 ];thenrm -f $openssl_rpm_fileRed_Error "ERROR: Download python env fielded."firpm -ivh $openssl_rpm_filerm -f $openssl_rpm_fileis_export_openssl=1}Get_Versions(){redhat_version_file="/etc/redhat-release"deb_version_file="/etc/issue"if [ -f $redhat_version_file ];thenos_type='el'is_aliyunos=$(cat $redhat_version_file|grep Aliyun)if [ "$is_aliyunos" != "" ];thenreturnfios_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')if [ "${os_version}" = "5" ];thenos_version=""fielseos_type='ubuntu'os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')if [ "${os_version}" = "" ];thenos_type='debian'os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')if [ "${os_version}" = "" ];thenos_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')fiif [ "${os_version}" = "8" ];thenos_version=""fiif [ "${is64bit}" = '32' ];thenos_version=""fielseif [ "$os_version" = "14" ];thenos_version=""fiif [ "$os_version" = "12" ];thenos_version=""fiif [ "$os_version" = "19" ];thenos_version=""fififi}Set_Bt_Panel(){password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)sleep 1admin_auth="/www/server/panel/data/admin_path.pl"if [ ! -f ${admin_auth} ];thenauth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)echo "/${auth_path}" > ${admin_auth}fiauth_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 usernameusername=$($python_bin tools.py panel ${password})cd ~echo "${password}" > ${setup_path}/server/panel/default.plchmod 600 ${setup_path}/server/panel/default.plsleep 3/etc/init.d/bt restartsleep 3isStart=$(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 22Red_Error "ERROR: The BT-Panel service startup failed."fi}Set_Firewall(){sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')if [ "${PM}" = "apt-get" ]; thenapt-get install -y ufwif [ -f "/usr/sbin/ufw" ];thenufw allow 888,20,21,22,80,${panelPort},${sshPort}/tcpufw allow 39000:40000/tcpufw_status=`ufw status`echo y|ufw enableufw default denyufw reloadfielseif [ -f "/etc/init.d/iptables" ];theniptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPTiptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPTiptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPTiptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPTiptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPTiptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPTiptables -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 ACCEPTiptables -A INPUT -p icmp --icmp-type any -j ACCEPTiptables -A INPUT -s localhost -d localhost -j ACCEPTiptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPTiptables -P INPUT DROPservice iptables savesed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-configiptables_status=$(service iptables status | grep 'not running')if [ "${iptables_status}" == '' ];thenservice iptables restartfielseAliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux")[ "${AliyunCheck}" ] && returnyum install firewalld -y[ "${Centos8Check}" ] && yum reinstall python3-six -ysystemctl enable firewalldsystemctl start firewalldfirewall-cmd --set-default-zone=public > /dev/null 2>&1firewall-cmd --permanent --zone=public --add-port=20/tcp > /dev/null 2>&1firewall-cmd --permanent --zone=public --add-port=21/tcp > /dev/null 2>&1firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1firewall-cmd --permanent --zone=public --add-port=80/tcp > /dev/null 2>&1firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1firewall-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>&1firewall-cmd --reloadfifi}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" ]; thenisHosts=$(cat /etc/hosts|grep 'www.bt.cn')if [ -z "${isHosts}" ];thenecho "" >> /etc/hostsecho "103.224.251.67 www.bt.cn" >> /etc/hostsgetIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)if [ -z "${getIpAddress}" ];thensed -i "/bt.cn/d" /etc/hostsfififiipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")if [ "${ipv4Check}" == "None" ];thenipv6Address=$(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" ]; thengetIpAddress="SERVER_IP"elseecho "True" > ${setup_path}/server/panel/data/ipv6.plsleep 1/etc/init.d/bt restartfifiif [ "${getIpAddress}" != "SERVER_IP" ];thenecho "${getIpAddress}" > ${setup_path}/server/panel/data/iplist.txtfiLOCAL_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>&1if [ "$1" != "" ];thenecho $1 > /www/server/panel/data/o.plcd /www/server/panel$python_bin tools.py ofiecho /www > /var/bt_setupPath.conf}Install_Main(){startTime=`date +%s`Lock_ClearSystem_CheckGet_Pack_Managerget_node_urlMEM_TOTAL=$(free -g|grep Mem|awk '{print $2}')if [ "${MEM_TOTAL}" -le "1" ];thenAuto_Swapfiif [ "${PM}" = "yum" ]; thenInstall_RPM_Packelif [ "${PM}" = "apt-get" ]; thenInstall_Deb_PackfiInstall_Python_LibInstall_BtSet_Bt_PanelService_AddSet_FirewallGet_Ip_AddressSetup_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' ]doread -p "Do you want to install Bt-Panel to the $setup_path directory now?(y/n): " go;doneif [ "$go" == 'n' ];thenexit;fiInstall_Mainecho -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!"
