mdserver-web/scripts/update.sh

235 lines
7.2 KiB
Bash
Raw Permalink Normal View History

2019-03-04 01:24:49 -05: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
2019-03-04 01:24:49 -05:00
export PATH
2022-06-21 13:10:16 -04:00
# LANG=en_US.UTF-8
2019-03-04 01:24:49 -05:00
is64bit=`getconf LONG_BIT`
startTime=`date +%s`
2024-10-31 14:51:54 -04:00
if [ -f /www/server/mdserver-web/tools.py ];then
2025-08-18 09:24:45 -04:00
echo -e "存在旧版代码,不能安装!,已知风险的情况下"
echo -e "rm -rf /www/server/mdserver-web"
echo -e "可安装!"
exit 0
2024-10-31 14:51:27 -04:00
fi
2019-03-04 01:24:49 -05:00
_os=`uname`
2022-06-10 03:14:00 -04:00
echo "use system: ${_os}"
2022-06-10 03:49:08 -04:00
2022-06-24 06:59:43 -04:00
if [ "$EUID" -ne 0 ]
then echo "Please run as root!"
exit
fi
2022-12-14 01:17:44 -05:00
if [ ${_os} != "Darwin" ] && [ ! -d /www/server/mdserver-web/logs ]; then
2025-08-18 09:24:45 -04:00
mkdir -p /www/server/mdserver-web/logs
2022-12-13 01:39:04 -05:00
fi
2024-07-23 13:09:02 -04:00
LOG_FILE=/var/log/mw-update.log
2022-12-13 01:39:04 -05:00
{
2022-12-15 04:53:17 -05:00
2025-08-18 07:30:17 -04:00
HTTP_PREFIX="https://"
LOCAL_ADDR=common
cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then
2025-08-18 09:24:45 -04:00
LOCAL_ADDR=cn
2025-08-18 07:30:17 -04:00
fi
if [ "$LOCAL_ADDR" != "common" ];then
2025-08-18 09:24:45 -04:00
declare -A PROXY_URL
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/"
PROXY_URL["gh_927223_xyz"]="https://gh.927223.xyz/https://"
PROXY_URL["gh_proxy_net"]="https://gh-proxy.net/"
2025-08-18 09:24:45 -04:00
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[*]}
2025-08-18 07:30:17 -04:00
fi
function AutoSizeStr(){
2025-08-18 09:24:45 -04:00
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})"
2025-08-18 07:30:17 -04:00
}
function ChooseProxyURL(){
2025-08-18 09:24:45 -04:00
clear
2025-08-18 07:30:17 -04:00
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`
2025-08-18 09:24:45 -04:00
AutoSizeStr "${V}" "$num"
cm_i=`expr $cm_i + 1`
done
2025-08-18 07:30:17 -04:00
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
2025-08-18 09:24:45 -04:00
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
2025-08-18 07:30:17 -04:00
INPUT=`expr $INPUT - 1`
INPUT_KEY=${SOURCE_LIST_KEY[$INPUT]}
HTTP_PREFIX=${PROXY_URL[$INPUT_KEY]}
}
if [ "$LOCAL_ADDR" != "common" ];then
2025-08-18 09:24:45 -04:00
ChooseProxyURL
2025-08-18 10:41:08 -04:00
if [ "$HTTP_PREFIX" != "https://" ];then
2025-08-18 09:24:45 -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
fi
2025-08-18 07:30:17 -04:00
fi
2022-06-20 07:19:51 -04:00
if [ ${_os} == "Darwin" ]; then
2025-08-18 09:24:45 -04:00
OSNAME='macos'
2023-05-05 05:52:13 -04:00
elif grep -Eqi "openSUSE" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='opensuse'
zypper refresh
2023-09-27 03:22:44 -04:00
elif grep -Eqi "EulerOS" /etc/*-release || grep -Eqi "openEuler" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='euler'
2023-05-05 05:52:13 -04:00
elif grep -Eqi "FreeBSD" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='freebsd'
2023-05-05 05:52:13 -04:00
elif grep -Eqi "CentOS" /etc/issue || grep -Eqi "CentOS" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='rhel'
yum install -y wget zip unzip
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Fedora" /etc/issue || grep -Eqi "Fedora" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='rhel'
yum install -y wget zip unzip
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Rocky" /etc/issue || grep -Eqi "Rocky" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='rhel'
yum install -y wget zip unzip
2023-05-05 05:52:13 -04:00
elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eqi "AlmaLinux" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='rhel'
yum install -y wget zip unzip
2025-04-08 06:21:53 -04:00
elif grep -Eqi "Anolis" /etc/issue || grep -Eqi "Anolis" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='rhel'
yum install -y wget curl zip unzip tar crontabs
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eqi "Amazon Linux" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='amazon'
yum install -y wget zip unzip
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Debian" /etc/issue || grep -Eqi "Debian" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='debian'
apt install -y wget zip unzip
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eqi "Ubuntu" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='ubuntu'
apt install -y wget zip unzip
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Raspbian" /etc/issue || grep -Eqi "Raspbian" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='raspbian'
2025-07-22 05:54:47 -04:00
elif grep -Eqi "Alpine" /etc/issue || grep -Eqi "Alpine" /etc/*-release; then
2025-08-18 09:24:45 -04:00
OSNAME='alpine'
apk update
apk add devscripts -force-broken-world
apk add wget zip unzip tar -force-broken-world
2019-03-04 01:24:49 -05:00
else
2025-08-18 09:24:45 -04:00
OSNAME='unknow'
2019-03-04 01:24:49 -05:00
fi
2025-08-18 07:30:17 -04:00
echo "LOCAL:${LOCAL_ADDR}"
2023-02-24 04:14:28 -05:00
2023-04-04 00:42:47 -04:00
CP_CMD=/usr/bin/cp
if [ -f /bin/cp ];then
2025-08-18 09:24:45 -04:00
CP_CMD=/bin/cp
2023-04-04 00:42:47 -04:00
fi
2025-08-18 07:30:17 -04:00
echo "update mdserver-web code start"
2023-04-04 00:42:47 -04:00
2025-08-18 07:30:17 -04:00
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
$CP_CMD -rf /tmp/mdserver-web-master/* /www/server/mdserver-web
rm -rf /tmp/master.tar.gz
rm -rf /tmp/mdserver-web-master
2022-12-31 08:06:55 -05:00
2025-08-18 07:30:17 -04:00
echo "update mdserver-web code end"
2022-12-31 08:06:55 -05:00
2022-06-20 11:55:33 -04:00
2020-07-10 03:59:04 -04:00
#pip uninstall public
2022-06-10 03:14:00 -04:00
echo "use system version: ${OSNAME}"
2022-06-27 00:54:32 -04:00
cd /www/server/mdserver-web && bash scripts/update/${OSNAME}.sh
2019-03-04 01:24:49 -05:00
2022-11-14 23:53:58 -05:00
bash /etc/rc.d/init.d/mw restart
2022-11-10 09:49:24 -05:00
bash /etc/rc.d/init.d/mw default
2022-11-10 09:51:16 -05:00
if [ -f /usr/bin/mw ];then
2025-08-18 09:24:45 -04:00
rm -rf /usr/bin/mw
2022-11-10 09:51:16 -05:00
fi
2022-10-05 23:12:01 -04:00
if [ ! -e /usr/bin/mw ]; then
2025-08-18 09:24:45 -04:00
if [ ! -f /usr/bin/mw ];then
ln -s /etc/rc.d/init.d/mw /usr/bin/mw
fi
2022-10-05 23:12:01 -04:00
fi
2019-03-04 01:24:49 -05:00
endTime=`date +%s`
2022-06-10 04:11:35 -04:00
((outTime=($endTime-$startTime)/60))
2022-12-13 01:39:04 -05:00
echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"
2024-07-23 13:09:02 -04:00
} 1> >(tee $LOG_FILE) 2>&1