mdserver-web/scripts/install_dev.sh

301 lines
8.8 KiB
Bash
Raw Normal View History

2022-06-21 00:04:48 -04:00
#!/bin/bash
2023-11-08 12:32:59 -05:00
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
2022-06-21 00:04:48 -04:00
export PATH
2025-08-18 04:03:31 -04:00
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]'
2022-06-21 13:10:16 -04:00
# LANG=en_US.UTF-8
2022-06-21 00:04:48 -04:00
is64bit=`getconf LONG_BIT`
2025-08-18 04:03:31 -04:00
2024-10-31 14:51:54 -04:00
if [ -f /www/server/mdserver-web/tools.py ];then
2024-10-31 14:51:27 -04:00
echo -e "存在旧版代码,不能安装!,已知风险的情况下"
echo -e "rm -rf /www/server/mdserver-web"
echo -e "可安装!"
2024-10-31 14:52:34 -04:00
exit 0
2024-10-31 14:51:27 -04:00
fi
2022-12-20 00:33:59 -05:00
echo -e "您正在安装的是\033[31mmdserver-web测试版\033[0m非开发测试用途请使用正式版 install.sh "
2023-02-18 09:06:51 -05:00
echo -e "You are installing\033[31m mdserver-web dev version\033[0m, normally use install.sh for production.\n"
2023-01-02 07:46:09 -05:00
sleep 1
2022-12-13 00:09:15 -05:00
2024-07-23 13:04:16 -04:00
LOG_FILE=/var/log/mw-install.log
2022-12-13 00:09:15 -05:00
{
2025-08-18 04:27:54 -04:00
HTTP_PREFIX="https://"
2025-08-18 04:15:57 -04:00
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
2025-08-18 04:33:57 -04:00
if [ "$LOCAL_ADDR" != "common" ];then
declare -A PROXY_URL
2025-08-18 05:01:11 -04:00
PROXY_URL["gh_proxy_com"]="https://gh-proxy.com/"
2025-08-18 09:24:45 -04:00
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/"
2025-08-18 09:48:27 -04:00
PROXY_URL["ghproxy_net"]="https://ghproxy.net/"
2025-08-18 09:24:45 -04:00
PROXY_URL["source"]="https://"
2025-08-18 04:21:14 -04:00
2025-08-18 04:19:48 -04:00
2025-08-18 04:33:57 -04:00
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
2025-08-18 03:57:38 -04:00
2025-08-18 04:03:31 -04:00
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 '| |'
2025-08-18 05:16:29 -04:00
echo -e '| 欢迎使用 Linux 一键安装mdserver-web面板源码 |'
2025-08-18 04:03:31 -04:00
echo -e '| |'
echo -e '| ============================================= |'
echo -e '| |'
echo -e '+---------------------------------------------------+'
echo -e ''
echo -e '#####################################################'
echo -e ''
2025-08-18 04:22:57 -04:00
echo -e ' 提供以下国内代理地址可供选择: '
2025-08-18 04:03:31 -04:00
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]}
2025-08-18 04:27:54 -04:00
HTTP_PREFIX=${PROXY_URL[$INPUT_KEY]}
2025-08-18 04:03:31 -04:00
}
2025-08-18 04:33:57 -04:00
if [ "$LOCAL_ADDR" != "common" ];then
ChooseProxyURL
2025-08-18 05:37:33 -04:00
2025-08-18 10:41:08 -04:00
if [ "$HTTP_PREFIX" != "https://" ];then
2025-08-18 06:03:43 -04:00
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
2025-08-18 06:08:17 -04:00
fi
2025-08-18 04:33:57 -04:00
fi
2025-08-18 04:03:31 -04:00
2025-08-18 04:13:35 -04:00
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 -Eq "openSUSE" /etc/*-release; then
OSNAME='opensuse'
zypper refresh
zypper install -y wget curl zip unzip unrar rar
elif grep -Eq "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 zip unzip tar
elif grep -Eqi "Fedora" /etc/issue || grep -Eqi "Fedora" /etc/*-release; then
OSNAME='rhel'
yum install -y wget zip unzip tar
elif grep -Eqi "Rocky" /etc/issue || grep -Eqi "Rocky" /etc/*-release; then
OSNAME='rhel'
yum install -y wget zip unzip
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 zip unzip tar
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eqi "Amazon Linux" /etc/*-release; then
OSNAME='amazon'
yum install -y wget zip unzip tar
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eqi "Ubuntu" /etc/*-release; then
OSNAME='ubuntu'
apt install -y wget zip unzip tar
elif grep -Eqi "Debian" /etc/issue || grep -Eqi "Debian" /etc/*-release; then
OSNAME='debian'
apt update -y
apt install -y devscripts
apt install -y wget zip unzip tar
elif grep -Eqi "Alpine" /etc/issue || grep -Eqi "Alpine" /etc/*-release; then
OSNAME='alpine'
apk update
apk add devscripts -force-broken-world
apk add curl 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
2025-08-18 07:30:17 -04:00
echo "LOCAL:${LOCAL_ADDR}"
2025-08-18 04:13:35 -04:00
echo "OSNAME:${OSNAME}"
2022-06-21 00:04:48 -04:00
if [ $OSNAME != "macos" ];then
2024-06-15 08:32:11 -04:00
if id www &> /dev/null ;then
echo ""
else
groupadd www
useradd -g www -s /usr/sbin/nologin www
fi
2022-06-21 00:04:48 -04:00
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
2025-08-18 04:28:23 -04:00
echo "downloading ${HTTP_PREFIX}github.com/midoks/mdserver-web/archive/refs/heads/dev.zip"
2025-08-18 04:25:54 -04:00
curl --insecure -sSLo /tmp/dev.zip ${HTTP_PREFIX}github.com/midoks/mdserver-web/archive/refs/heads/dev.zip
2025-08-18 04:30:13 -04:00
cd /tmp && unzip /tmp/dev.zip
2025-08-18 04:25:54 -04:00
mv -f /tmp/mdserver-web-dev /www/server/mdserver-web
rm -rf /tmp/dev.zip
rm -rf /tmp/mdserver-web-dev
2022-06-21 00:04:48 -04:00
fi
2022-12-20 00:04:55 -05:00
# install acme.sh
if [ ! -d /root/.acme.sh ];then
2023-02-24 03:53:48 -05:00
if [ "$LOCAL_ADDR" != "common" ];then
2025-08-18 04:29:07 -04:00
curl -sSL -o /tmp/acme.tar.gz ${HTTP_PREFIX}github.com/acmesh-official/acme.sh/archive/master.tar.gz
2022-12-20 00:04:55 -05:00
tar xvzf /tmp/acme.tar.gz -C /tmp
cd /tmp/acme.sh-master
bash acme.sh install
2025-08-18 05:04:58 -04:00
else
2025-08-18 05:05:35 -04:00
curl -fsSL https://get.acme.sh | bash
2022-12-20 00:04:55 -05:00
fi
fi
2022-06-21 00:04:48 -04:00
fi
echo "use system version: ${OSNAME}"
2023-02-15 09:15:08 -05:00
if [ "${OSNAME}" == "macos" ];then
2025-08-18 05:11:40 -04:00
curl --insecure -fsSL ${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/refs/heads/dev/scripts/install/macos.sh | bash
2023-02-15 09:15:08 -05:00
else
cd /www/server/mdserver-web && bash scripts/install/${OSNAME}.sh
fi
2022-06-21 00:04:48 -04:00
2023-02-15 09:04:58 -05:00
if [ "${OSNAME}" == "macos" ];then
echo "macos end"
exit 0
fi
2022-11-11 05:52:00 -05:00
cd /www/server/mdserver-web && bash cli.sh start
2022-11-10 09:49:24 -05:00
isStart=`ps -ef|grep 'gunicorn -c setting.py app:app' |grep -v grep|awk '{print $2}'`
n=0
2022-11-11 06:06:32 -05:00
while [ ! -f /etc/rc.d/init.d/mw ];
2022-11-10 09:49:24 -05:00
do
echo -e ".\c"
sleep 1
let n+=1
if [ $n -gt 20 ];then
echo -e "start mw fail"
exit 1
fi
done
cd /www/server/mdserver-web && bash /etc/rc.d/init.d/mw stop
cd /www/server/mdserver-web && bash /etc/rc.d/init.d/mw start
cd /www/server/mdserver-web && bash /etc/rc.d/init.d/mw default
2022-11-11 05:52:00 -05:00
sleep 2
2022-10-05 23:12:01 -04:00
if [ ! -e /usr/bin/mw ]; then
2022-11-19 09:05:45 -05:00
if [ -f /etc/rc.d/init.d/mw ];then
2022-11-10 09:49:24 -05:00
ln -s /etc/rc.d/init.d/mw /usr/bin/mw
2022-10-05 23:12:01 -04:00
fi
2022-06-25 10:11:44 -04:00
fi
2022-06-21 00:04:48 -04:00
endTime=`date +%s`
((outTime=(${endTime}-${startTime})/60))
2022-06-23 04:04:08 -04:00
echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"
2022-12-13 00:09:15 -05:00
2024-07-23 13:04:16 -04:00
} 1> >(tee $LOG_FILE) 2>&1
2022-12-13 00:09:15 -05:00
echo -e "\nInstall completed. If error occurs, please contact us with the log file mw-install.log ."
echo "安装完毕,如果出现错误,请带上同目录下的安装日志 mw-install.log 联系我们反馈."