mdserver-web/scripts/install.sh

172 lines
4.8 KiB
Bash
Raw Normal View History

2018-09-13 10:26:34 -04:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
2022-06-21 13:10:16 -04:00
# LANG=en_US.UTF-8
2018-09-13 10:26:34 -04:00
is64bit=`getconf LONG_BIT`
2018-09-13 10:20:52 -04:00
2022-12-13 00:09:15 -05:00
{
2019-12-12 13:54:48 -05:00
if [ -f /etc/motd ];then
2022-06-10 03:14:00 -04:00
echo "welcome to mdserver-web panel" > /etc/motd
2019-12-12 13:54:48 -05:00
fi
2018-09-13 10:26:34 -04:00
startTime=`date +%s`
2019-01-15 04:57:33 -05:00
_os=`uname`
2022-06-10 03:14:00 -04:00
echo "use system: ${_os}"
2022-06-10 04:31:44 -04:00
2022-06-10 03:59:25 -04:00
if [ ${_os} == "Darwin" ]; then
2022-06-10 03:46:52 -04:00
OSNAME='macos'
2023-05-05 05:52:13 -04:00
elif grep -Eqi "openSUSE" /etc/*-release; then
2022-07-03 11:04:50 -04:00
OSNAME='opensuse'
zypper refresh
2022-12-12 11:50:38 -05:00
zypper install cron wget curl zip unzip
2023-05-05 05:52:13 -04:00
elif grep -Eqi "FreeBSD" /etc/*-release; then
2022-07-04 06:56:13 -04:00
OSNAME='freebsd'
2023-09-27 03:22:44 -04:00
elif grep -Eqi "EulerOS" /etc/*-release || grep -Eqi "openEuler" /etc/*-release; then
2023-09-10 00:19:14 -04:00
OSNAME='euler'
yum install -y wget curl zip unzip tar crontabs
2023-05-05 05:52:13 -04:00
elif grep -Eqi "CentOS" /etc/issue || grep -Eqi "CentOS" /etc/*-release; then
2022-12-15 04:53:17 -05:00
OSNAME='rhel'
yum install -y wget curl zip unzip tar crontabs
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Fedora" /etc/issue || grep -Eqi "Fedora" /etc/*-release; then
2023-05-05 10:49:39 -04:00
OSNAME='rhel'
2022-12-15 04:53:17 -05:00
yum install -y wget curl zip unzip tar crontabs
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Rocky" /etc/issue || grep -Eqi "Rocky" /etc/*-release; then
2022-12-15 04:53:17 -05:00
OSNAME='rhel'
yum install -y wget curl zip unzip tar crontabs
2023-05-05 05:52:13 -04:00
elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eqi "AlmaLinux" /etc/*-release; then
2022-12-09 12:21:38 -05:00
OSNAME='rhel'
2022-12-12 11:50:38 -05:00
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
2022-12-15 04:53:17 -05:00
OSNAME='amazon'
yum install -y wget curl zip unzip tar crontabs
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Debian" /etc/issue || grep -Eqi "Debian" /etc/os-release; then
2022-06-10 03:46:52 -04:00
OSNAME='debian'
2022-06-23 00:50:37 -04:00
apt update -y
2022-12-12 11:50:38 -05:00
apt install -y wget curl zip unzip tar cron
2023-05-05 05:52:13 -04:00
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eqi "Ubuntu" /etc/os-release; then
2022-12-15 04:53:17 -05:00
OSNAME='ubuntu'
apt update -y
apt install -y wget curl zip unzip tar cron
2019-01-15 04:57:33 -05:00
else
OSNAME='unknow'
fi
2023-11-07 22:59:28 -05:00
if [ "$EUID" -ne 0 ] && [ "$OSNAME" != "macos" ];then
echo "Please run as root!"
exit
fi
2022-06-20 11:55:33 -04:00
2023-06-28 22:41:10 -04:00
# HTTP_PREFIX="https://"
# LOCAL_ADDR=common
# ping -c 1 github.com > /dev/null 2>&1
# if [ "$?" != "0" ];then
# LOCAL_ADDR=cn
# HTTP_PREFIX="https://ghproxy.com/"
# fi
2023-02-24 04:07:24 -05:00
HTTP_PREFIX="https://"
LOCAL_ADDR=common
2023-09-08 23:35:08 -04:00
cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
2023-09-15 01:23:28 -04:00
if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then
2023-02-24 04:07:24 -05:00
LOCAL_ADDR=cn
2023-06-28 22:41:10 -04:00
HTTP_PREFIX="https://ghproxy.com/"
2023-02-24 04:07:24 -05:00
fi
2023-07-01 00:24:04 -04:00
echo "local:${LOCAL_ADDR}"
2023-06-28 22:41:10 -04:00
2022-06-20 11:55:33 -04:00
if [ $OSNAME != "macos" ];then
2022-11-16 07:37:42 -05:00
if id www &> /dev/null ;then
echo ""
else
groupadd www
useradd -g www -s /bin/bash www
fi
2022-06-20 11:55:33 -04:00
mkdir -p /www/server
mkdir -p /www/wwwroot
mkdir -p /www/wwwlogs
mkdir -p /www/backup/database
mkdir -p /www/backup/site
2022-08-05 14:48:26 -04:00
# https://cdn.jsdelivr.net/gh/midoks/mdserver-web@latest/scripts/install.sh
2022-12-10 01:40:06 -05:00
if [ ! -d /www/server/mdserver-web ];then
2023-03-29 04:35:09 -04:00
if [ "$LOCAL_ADDR" == "common" ];then
2023-03-29 23:56:48 -04:00
curl --insecure -sSLo /tmp/master.zip ${HTTP_PREFIX}github.com/midoks/mdserver-web/archive/refs/heads/master.zip
cd /tmp && unzip /tmp/master.zip
mv -f /tmp/mdserver-web-master /www/server/mdserver-web
rm -rf /tmp/master.zip
rm -rf /tmp/mdserver-web-master
2022-08-05 14:48:26 -04:00
else
2023-03-29 23:56:48 -04:00
curl --insecure -sSLo /tmp/master.zip https://code.midoks.me/midoks/mdserver-web/archive/master.zip
2023-04-03 04:48:53 -04:00
cd /tmp && unzip /tmp/master.zip
2023-03-29 23:59:55 -04:00
mv -f /tmp/mdserver-web /www/server/mdserver-web
2023-03-29 23:56:48 -04:00
rm -rf /tmp/master.zip
rm -rf /tmp/mdserver-web
2022-08-05 14:48:26 -04:00
fi
2023-03-29 23:56:48 -04:00
2022-06-20 11:55:33 -04:00
fi
2022-12-10 01:40:06 -05:00
# install acme.sh
if [ ! -d /root/.acme.sh ];then
2023-02-24 04:07:24 -05:00
if [ "$LOCAL_ADDR" != "common" ];then
2023-03-14 08:03:53 -04:00
curl --insecure -sSLo /tmp/acme.tar.gz https://gitee.com/neilpang/acme.sh/repository/archive/master.tar.gz
2022-12-10 01:40:06 -05:00
tar xvzf /tmp/acme.tar.gz -C /tmp
cd /tmp/acme.sh-master
bash acme.sh install
fi
if [ ! -d /root/.acme.sh ];then
curl https://get.acme.sh | sh
fi
fi
2022-06-20 11:55:33 -04:00
fi
2022-06-10 03:14:00 -04:00
echo "use system version: ${OSNAME}"
2023-02-24 04:12:31 -05:00
if [ "${OSNAME}" == "macos" ];then
2023-03-29 04:32:46 -04:00
curl --insecure -fsSL https://code.midoks.me/midoks/mdserver-web/raw/branch/master/scripts/install/macos.sh | bash
2023-02-15 09:24:46 -05:00
else
cd /www/server/mdserver-web && bash scripts/install/${OSNAME}.sh
fi
2022-11-11 05:52:00 -05:00
2023-02-15 09:05:16 -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
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-11 05:52:00 -05:00
do
echo -e ".\c"
sleep 1
let n+=1
if [ $n -gt 20 ];then
echo -e "start mw fail"
2022-11-11 06:06:32 -05:00
exit 1
2022-11-11 05:52:00 -05:00
fi
done
2022-11-10 09:49:24 -05:00
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
2018-11-22 22:39:15 -05:00
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-10 14:31:12 -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:22 -04:00
fi
2022-10-05 23:12:01 -04:00
2018-09-13 10:26:34 -04:00
endTime=`date +%s`
2022-06-10 11:24:42 -04:00
((outTime=(${endTime}-${startTime})/60))
2022-06-21 00:30:54 -04:00
echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"
2022-06-29 09:26:14 -04:00
2023-08-26 04:04:35 -04:00
} 1> >(tee mw-install.log) 2>&1
2022-12-12 12:49:40 -05:00
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 ."
2022-12-12 12:49:40 -05:00
echo "安装完毕,如果出现错误,请带上同目录下的安装日志 mw-install.log 联系我们反馈."