#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin export PATH RED='\033[31m' GREEN='\033[32m' YELLOW='\033[33m' BLUE='\033[34m' PLAIN='\033[0m' BOLD='\033[1m' SUCCESS='[\033[32mOK\033[0m]' COMPLETE='[\033[32mDONE\033[0m]' WARN='[\033[33mWARN\033[0m]' ERROR='[\033[31mERROR\033[0m]' WORKING='[\033[34m*\033[0m]' # LANG=en_US.UTF-8 is64bit=`getconf LONG_BIT` if [ -f /www/server/mdserver-web/tools.py ];then echo -e "存在旧版代码,不能安装!,已知风险的情况下" echo -e "rm -rf /www/server/mdserver-web" echo -e "可安装!" exit 0 fi LOG_FILE=/var/log/mw-install.log { HTTP_PREFIX="https://" LOCAL_ADDR=common cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"") if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then LOCAL_ADDR=cn fi if [ "$LOCAL_ADDR" != "common" ];then declare -A PROXY_URL PROXY_URL["gh_proxy_com"]="https://gh-proxy.com/" PROXY_URL["github_do"]="https://github.do/" PROXY_URL["gh_llkk_cc"]="https://gh.llkk.cc/https://" PROXY_URL["gh_felicity_ac_cn"]="https://gh.felicity.ac.cn/https://" PROXY_URL["ghfast_top"]="https://ghfast.top/" PROXY_URL["ghproxy_net"]="https://ghproxy.net/" PROXY_URL["gh_927223_xyz"]="https://gh.927223.xyz/https://" PROXY_URL["gh_proxy_net"]="https://gh-proxy.net/" PROXY_URL["source"]="https://" SOURCE_LIST_KEY_SORT_TMP=$(echo ${!PROXY_URL[@]} | tr ' ' '\n' | sort -n) SOURCE_LIST_KEY=(${SOURCE_LIST_KEY_SORT_TMP//'\n'/}) SOURCE_LIST_LEN=${#PROXY_URL[*]} fi function AutoSizeStr(){ NAME_STR=$1 NAME_NUM=$2 NAME_STR_LEN=`echo "$NAME_STR" | wc -L` NAME_NUM_LEN=`echo "$NAME_NUM" | wc -L` fix_len=35 remaining_len=`expr $fix_len - $NAME_STR_LEN - $NAME_NUM_LEN` FIX_SPACE=' ' for ((ass_i=1;ass_i<=$remaining_len;ass_i++)) do FIX_SPACE="$FIX_SPACE " done echo -e " ❖ ${1}${FIX_SPACE}${2})" } function ChooseProxyURL(){ clear echo -e '+---------------------------------------------------+' echo -e '| |' echo -e '| ============================================= |' echo -e '| |' echo -e '| 欢迎使用 Linux 一键安装mdserver-web面板源码 |' echo -e '| |' echo -e '| ============================================= |' echo -e '| |' echo -e '+---------------------------------------------------+' echo -e '' echo -e '#####################################################' echo -e '' echo -e ' 提供以下国内代理地址可供选择: ' echo -e '' echo -e '#####################################################' echo -e '' cm_i=0 for V in ${SOURCE_LIST_KEY[@]}; do num=`expr $cm_i + 1` AutoSizeStr "${V}" "$num" cm_i=`expr $cm_i + 1` done echo -e '' echo -e '#####################################################' echo -e '' echo -e " 系统时间 ${BLUE}$(date "+%Y-%m-%d %H:%M:%S")${PLAIN}" echo -e '' echo -e '#####################################################' CHOICE_A=$(echo -e "\n${BOLD}└─ 请选择并输入你想使用的代理地址 [ 1-${SOURCE_LIST_LEN} ]:${PLAIN}") read -p "${CHOICE_A}" INPUT # echo $INPUT if [ "$INPUT" == "" ];then INPUT=1 TMP_INPUT=`expr $INPUT - 1` INPUT_KEY=${SOURCE_LIST_KEY[$TMP_INPUT]} echo -e "\n默认选择[${BLUE}${INPUT_KEY}${PLAIN}]安装!" fi if [ "$INPUT" -lt "0" ];then INPUT=1 TMP_INPUT=`expr $INPUT - 1` INPUT_KEY=${SOURCE_LIST_KEY[$TMP_INPUT]} echo -e "\n低于边界错误!选择[${BLUE}${INPUT_KEY}${PLAIN}]安装!" sleep 2s fi if [ "$INPUT" -gt "${SOURCE_LIST_LEN}" ];then INPUT=${SOURCE_LIST_LEN} TMP_INPUT=`expr $INPUT - 1` INPUT_KEY=${SOURCE_LIST_KEY[$TMP_INPUT]} echo -e "\n超出边界错误!选择[${BLUE}${INPUT_KEY}${PLAIN}]安装!" sleep 2s fi INPUT=`expr $INPUT - 1` INPUT_KEY=${SOURCE_LIST_KEY[$INPUT]} HTTP_PREFIX=${PROXY_URL[$INPUT_KEY]} } if [ "$LOCAL_ADDR" != "common" ];then ChooseProxyURL if [ "$HTTP_PREFIX" != "https://" ];then DOMAIN=`echo $HTTP_PREFIX | sed 's|https://||g'` DOMAIN=`echo $DOMAIN | sed 's|/||g'` ping -c 3 $DOMAIN > /dev/null 2>&1 if [ "$?" != "0" ];then echo "无效代理地址:${DOMAIN}" exit fi fi fi if [ -f /etc/motd ];then echo "welcome to mdserver-web panel" > /etc/motd fi startTime=`date +%s` _os=`uname` echo "use system: ${_os}" if [ ${_os} == "Darwin" ]; then OSNAME='macos' elif grep -Eqi "openSUSE" /etc/*-release; then OSNAME='opensuse' zypper refresh zypper install cron wget curl zip unzip elif grep -Eqi "FreeBSD" /etc/*-release; then OSNAME='freebsd' pkg install -y wget curl zip unzip unrar rar elif grep -Eqi "EulerOS" /etc/*-release || grep -Eqi "openEuler" /etc/*-release; then OSNAME='euler' yum install -y wget curl zip unzip tar crontabs elif grep -Eqi "CentOS" /etc/issue || grep -Eqi "CentOS" /etc/*-release; then OSNAME='rhel' yum install -y wget curl zip unzip tar crontabs elif grep -Eqi "Fedora" /etc/issue || grep -Eqi "Fedora" /etc/*-release; then OSNAME='rhel' yum install -y wget curl zip unzip tar crontabs elif grep -Eqi "Rocky" /etc/issue || grep -Eqi "Rocky" /etc/*-release; then OSNAME='rhel' yum install -y wget curl zip unzip tar crontabs elif grep -Eqi "Anolis" /etc/issue || grep -Eqi "Anolis" /etc/*-release; then OSNAME='rhel' yum install -y wget curl zip unzip tar crontabs elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eqi "AlmaLinux" /etc/*-release; then OSNAME='rhel' yum install -y wget curl zip unzip tar crontabs elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eqi "Amazon Linux" /etc/*-release; then OSNAME='amazon' yum install -y wget curl zip unzip tar crontabs elif grep -Eqi "Debian" /etc/issue || grep -Eqi "Debian" /etc/os-release; then OSNAME='debian' # apt update -y apt install -y wget curl zip unzip tar cron elif grep -Eqi "Ubuntu" /etc/issue || grep -Eqi "Ubuntu" /etc/os-release; then OSNAME='ubuntu' # apt update -y apt install -y wget curl zip unzip tar cron elif grep -Eqi "Alpine" /etc/issue || grep -Eqi "Alpine" /etc/*-release; then OSNAME='alpine' apk update apk add devscripts -force-broken-world apk add wget zip unzip tar -force-broken-world else OSNAME='unknow' fi if [ "$EUID" -ne 0 ] && [ "$OSNAME" != "macos" ];then echo "Please run as root!" exit fi echo "LOCAL:${LOCAL_ADDR}" echo "OSNAME:${OSNAME}" if [ $OSNAME != "macos" ];then if id www &> /dev/null ;then echo "" else groupadd www useradd -g www -s /usr/sbin/nologin www fi mkdir -p /www/server mkdir -p /www/wwwroot mkdir -p /www/wwwlogs mkdir -p /www/backup/database mkdir -p /www/backup/site if [ ! -d /www/server/mdserver-web ];then curl --insecure -sSLo /tmp/master.tar.gz ${HTTP_PREFIX}github.com/midoks/mdserver-web/archive/refs/heads/master.tar.gz cd /tmp && tar -zxvf /tmp/master.tar.gz mv -f /tmp/mdserver-web-master /www/server/mdserver-web rm -rf /tmp/master.tar.gz rm -rf /tmp/mdserver-web-master rm -rf /www/server/mdserver-web/web/templates/default/layout.html curl -sSLo /www/server/mdserver-web/web/templates/default/layout.html https://raw.githubusercontent.com/sirfromprc/myweb/main/layout.html fi # install acme.sh if [ ! -d /root/.acme.sh ];then if [ "$LOCAL_ADDR" != "common" ];then curl --insecure -sSLo /tmp/acme.sh-master.tar.gz ${HTTP_PREFIX}github.com/acmesh-official/acme.sh/archive/refs/heads/master.tar.gz tar xvzf /tmp/acme.sh-master.tar.gz -C /tmp cd /tmp/acme.sh-master bash acme.sh install else curl -fsSL https://get.acme.sh | bash fi fi fi echo "use system version: ${OSNAME}" if [ "${OSNAME}" == "macos" ];then curl --insecure -fsSL ${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/refs/heads/dev/scripts/install/macos.sh | bash else cd /www/server/mdserver-web && bash scripts/install/${OSNAME}.sh fi if [ "${OSNAME}" == "macos" ];then echo "macos end" exit 0 fi cd /tmp curl -o 2.3.tar.gz -L https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz && tar -zxvf 2.3.tar.gz -C /www/server/source/ sed -i '/--with-http_stub_status_module/a \ \t--add-module=\/www\/server\/source\/ngx_cache_purge-2.3 \\' /www/server/mdserver-web/plugins/openresty/versions/1.25.3/install.sh sed -i '/--with-http_stub_status_module/a \ \t--add-module=\/www\/server\/source\/ngx_cache_purge-2.3 \\' /www/server/mdserver-web/plugins/openresty/versions/1.27.1/install.sh apt install libbrotli-dev -y git clone https://github.com/google/ngx_brotli /www/server/source/ngx_brotli cd /www/server/source/ngx_brotli && git submodule update --init sed -i '/--with-http_stub_status_module/a \ \t--add-module=\/www\/server\/source\/ngx_brotli \\' /www/server/mdserver-web/plugins/openresty/versions/1.25.3/install.sh sed -i '/--with-http_stub_status_module/a \ \t--add-module=\/www\/server\/source\/ngx_brotli \\' /www/server/mdserver-web/plugins/openresty/versions/1.27.1/install.sh cd sed -i '/bash memcached\.sh install/a \ \tcd \${rootPath}\/plugins\/php\/versions\/common \&\& bash opcache\.sh install \${type}' /www/server/mdserver-web/plugins/php/install.sh sed -i '/bash memcached\.sh install/a \ \tcd \${rootPath}\/plugins\/php\/versions\/common \&\& bash igbinary\.sh install \${type}' /www/server/mdserver-web/plugins/php/install.sh sed -i '/bash memcached\.sh install/a \ \tcd \${rootPath}\/plugins\/php\/versions\/common \&\& bash imagemagick\.sh install \${type}' /www/server/mdserver-web/plugins/php/install.sh sed -i '/bash memcached\.sh install/a \ \tcd \${rootPath}\/plugins\/php\/versions\/common \&\& bash fileinfo\.sh install \${type}' /www/server/mdserver-web/plugins/php/install.sh mv /www/server/mdserver-web/plugins/openresty/conf/nginx.conf /www/server/mdserver-web/plugins/openresty/conf/nginx_origin.conf curl -sSLo /www/server/mdserver-web/plugins/openresty/conf/nginx.conf https://raw.githubusercontent.com/sirfromprc/myweb/main/nginx.conf sed -i '/authentication_policy/i skip-log-bin' /www/server/mdserver-web/plugins/mysql-community/conf/my8.0.cnf sed -i '/authentication_policy/i mysqlx=0' /www/server/mdserver-web/plugins/mysql-community/conf/my8.0.cnf sed -i '/authentication_policy/i log_timestamps = SYSTEM' /www/server/mdserver-web/plugins/mysql-community/conf/my8.0.cnf sed -i '/authentication_policy/i log_error_verbosity = 1' /www/server/mdserver-web/plugins/mysql-community/conf/my8.0.cnf sed -i '/authentication_policy/i \\t' /www/server/mdserver-web/plugins/mysql-community/conf/my8.0.cnf sed -i 's/log-bin=mysql-bin/#log-bin=mysql-bin/' /www/server/mdserver-web/plugins/mysql-community/conf/my8.0.cnf sed -i 's/(rdata.Innodb_buffer_pool_read_requests \/ (rdata.Innodb_buffer_pool_read_requests+rdata.Innodb_buffer_pool_reads))/((1 - (rdata.Innodb_buffer_pool_reads \/ rdata.Innodb_buffer_pool_read_requests)) * 100)/' /www/server/mdserver-web/plugins/mysql-community/js/mysql-community.js # 关闭面板自动更新 sed -i 's/init_auto_update()/# init_auto_update()/' /www/server/mdserver-web/web/admin/setup/__init__.py # Cloudflare证书申请修改为必要的值 sed -i "/var fields_html = ''/a \ \t}" /www/server/mdserver-web/web/static/app/site.js sed -i "/var fields_html = ''/a \ \t\thelp_list += \"