mdserver-web/plugins/gogs/install.sh

108 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2018-12-14 03:06:59 -05:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
curPath=`pwd`
rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
2023-09-07 01:04:30 -04:00
if [ -f ${rootPath}/bin/activate ];then
source ${rootPath}/bin/activate
fi
2018-12-14 03:06:59 -05:00
GOGS_DOWNLOAD='https://dl.gogs.io'
getOs(){
os=`uname`
if [ "Darwin" == "$os" ];then
echo 'darwin'
else
echo 'linux'
fi
return 0
}
getBit(){
echo `getconf LONG_BIT`
}
Install_gogs()
{
2022-09-04 05:18:45 -04:00
2018-12-14 03:06:59 -05:00
mkdir -p $serverPath/source/gogs
2024-11-30 08:44:09 -05:00
echo '正在安装脚本文件...'
2018-12-14 03:06:59 -05:00
version=$1
os=`getOs`
2022-06-25 12:32:11 -04:00
# if id git &> /dev/null ;then
# echo "git uid is `id -u git`"
# echo "git shell is `grep "^git:" /etc/passwd |cut -d':' -f7 `"
# else
# groupadd git
# useradd -g git git
# fi
2022-06-25 13:00:14 -04:00
git config --global push.default simple
2022-06-25 11:55:29 -04:00
2018-12-14 03:06:59 -05:00
if [ "darwin" == "$os" ];then
file=gogs_${version}_darwin_amd64.zip
else
2018-12-14 22:18:33 -05:00
file=gogs_${version}_linux_amd64.zip
2018-12-14 03:06:59 -05:00
fi
if [ ! -f $serverPath/source/gogs/$file ];then
2022-11-28 08:46:56 -05:00
wget --no-check-certificate -O $serverPath/source/gogs/$file ${GOGS_DOWNLOAD}/${version}/${file}
2018-12-14 03:06:59 -05:00
fi
cd $serverPath/source/gogs && unzip -o $file -d gogs_${version}
mv $serverPath/source/gogs/gogs_${version}/gogs/ $serverPath/gogs
2022-06-25 11:11:04 -04:00
if [ -d $serverPath/gogs ];then
echo $version > $serverPath/gogs/version.pl
2022-06-28 21:33:14 -04:00
cd ${rootPath} && python3 ${rootPath}/plugins/gogs/index.py start
cd ${rootPath} && python3 ${rootPath}/plugins/gogs/index.py initd_install
2022-06-25 11:11:04 -04:00
fi
2019-03-13 05:19:33 -04:00
# if id -u gogs > /dev/null 2>&1; then
# echo "gogs user exists"
# else
# useradd gogs
# cp /etc/sudoers{,.`date +"%Y-%m-%d_%H-%M-%S"`}
# echo "gogs ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# fi
2019-03-11 04:40:29 -04:00
2024-11-30 08:44:09 -05:00
echo 'install success'
2018-12-14 03:06:59 -05:00
}
Uninstall_gogs()
{
2022-06-28 21:33:14 -04:00
2022-07-03 10:22:03 -04:00
if [ -f /usr/lib/systemd/system/gogs.service ];then
2022-06-25 10:52:49 -04:00
systemctl stop gogs
2022-06-28 21:33:14 -04:00
systemctl disable gogs
2022-07-03 10:22:03 -04:00
rm -rf /usr/lib/systemd/system/gogs.service
2022-06-28 21:33:14 -04:00
systemctl daemon-reload
2022-06-25 10:52:49 -04:00
fi
2022-06-28 21:33:14 -04:00
if [ -f $serverPath/gogs/initd/gogs ];then
$serverPath/gogs/initd/gogs stop
fi
rm -rf $serverPath/gogs
2024-11-30 08:44:09 -05:00
echo 'uninstall success'
2018-12-14 03:06:59 -05:00
}
action=$1
version=$2
if [ "${1}" == 'install' ];then
Install_gogs $version
else
Uninstall_gogs $version
fi