Delete ygk.sh

This commit is contained in:
dongge88 2025-01-21 19:33:22 +08:00
parent d81bf51833
commit 4e31460cbf
1 changed files with 0 additions and 196 deletions

196
ygk.sh
View File

@ -1,196 +0,0 @@
#!/bin/bash
#Stop ygk & delete ygk files.
Delete() {
systemctl disable ygk.service
chkconfig --del ygk
/etc/init.d/ygk disable
if [ -f "${ygk_install_dir:=/usr/local/ygk}/ygk.init" ]; then
"$ygk_install_dir"/ygk.init stop
rm -rf "$ygk_install_dir"
fi
rm -f /etc/init.d/ygk /lib/systemd/system/ygk.service /etc/rc.d/rc5.d/S99ygk /etc/rc.d/S99ygk /etc/rc5.d/S99ygk
}
#Print error message and exit.
Error() {
echo $echo_e_arg "\033[41;37m$1\033[0m"
echo -n "remove ygk?[y]: "
read remove
echo "$remove"|grep -qi 'n' || Delete
exit 1
}
#Make ygk start cmd
Config() {
if [ -z "$ygk_install_dir" ]; then #Variables come from the environment
echo -n "请输入ygk服务端口: "
read ygk_port
echo -n "请输入ygk连接密码(ClientKey): "
read ygk_clientkey
echo -n "服务器是否支持IPV6[n]: "
read ipv6_support
echo -n "请输入安装目录(默认/usr/local/ygk): " #安装目录
read ygk_install_dir
echo "${ygk_install_dir:=/usr/local/ygk}"|grep -q '^/' || ygk_install_dir="$PWD/$ygk_install_dir"
fi
[ -z "$ygk_auth_secret" ] && ygk_auth_secret='free'
[ -z "$ygk_secret_password" ] && ygk_secret_password='free'
echo "$ipv6_support"|grep -qi '^y' && ipv6_support="true" || ipv6_support="false"
}
GetAbi() {
machine=`uname -m`
latestVersion="v2.8.0"
if [ ! -z "$(uname -m | grep -E 'amd64|x86_64')" ]; then
ARCH="x64"
elif [ ! -z "$(uname -m | grep -E '86')" ]; then
ARCH="x86"
elif [ ! -z "$(uname -m | grep -E 'armv8|aarch64')" ]; then
ARCH="arm64"
elif [ ! -z "$(uname -m | grep -E 'arm')" ]; then
ARCH="arm"
elif [ ! -z "$(uname -m | grep -E 'mips64')" ]; then
# check little/big endian 0->big 1->little
if [ "$(echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}')" == "1" ]; then
ARCH="mips64el"
else
ARCH="mips64"
fi
elif [ ! -z "$(uname -m | grep -E 'mips')" ]; then
# check little/big endian 0->big 1->little
if [ "$(echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}')" == "1" ]; then
ARCH="mipsel"
else
ARCH="mips"
fi
else
colorEcho $RED "不支持的系统架构!"
sh ygk.sh uninstall >/dev/null 2>&1
exit 1
fi
}
#install ygk files
InstallFiles() {
GetAbi
mkdir -p "$ygk_install_dir" || Error "Create ygk install directory failed."
cd "$ygk_install_dir" || exit 1
$download_tool ygk https://releases.pagure.org/builds/ygk/$ARCH || Error "ygk download failed."
$download_tool config.json https://releases.pagure.org/builds/ygk/ygk.json || Error "ygk.json download failed."
$download_tool ygk.init https://releases.pagure.org/builds/ygk/ygk.init || Error "ygk.init download failed."
[ -f '/etc/rc.common' ] && rcCommon='/etc/rc.common'
sed -i "s#12345#$ygk_port#g" config.json
sed -i "s#ABCDE#$ygk_clientkey#g" config.json
sed -i "s~\[ygk_install_dir\]~$ygk_install_dir~g" config.json
sed -i "s~#!/bin/sh~#!$SHELL $rcCommon~" ygk.init
sed -i "s~\[ygk_install_dir\]~$ygk_install_dir~g" ygk.init
sed -i "s~\[ygk_tcp_port_list\]~$ygk_port~g" ygk.init
ln -s "$ygk_install_dir/ygk.init" /etc/init.d/ygk
chmod -R +rwx "$ygk_install_dir" /etc/init.d/ygk
if type systemctl && [ -z "$(systemctl --failed|grep -q 'Host is down')" ]; then
$download_tool /lib/systemd/system/ygk.service https://releases.pagure.org/builds/ygk/ygk.service || Error "ygk.service download failed."
chmod +rwx /lib/systemd/system/ygk.service
sed -i "s~\[ygk_install_dir\]~$ygk_install_dir~g" /lib/systemd/system/ygk.service
systemctl daemon-reload
fi
}
#install initialization
InstallInit() {
echo -n "make a update?[n]: "
read update
PM=`type apt-get || type yum`
PM=`echo "$PM" | grep -o '/.*'`
echo "$update"|grep -qi 'y' && $PM -y update
$PM -y install curl wget unzip sed
}
AddAutoStart() {
if [ -n "$rcCommon" ]; then
if /etc/init.d/ygk enable; then
echo '已添加开机自启, 如需关闭请执行: /etc/init.d/ygk disable'
return
fi
fi
if type systemctl &>/dev/null && [ -z "$(systemctl --failed|grep -q 'Host is down')" ]; then
if systemctl enable ygk &>/dev/null; then
echo '已添加开机自启, 如需关闭请执行: systemctl disable ygk'
return
fi
fi
if type chkconfig &>/dev/null; then
if chkconfig --add ygk &>/dev/null && chkconfig ygk on &>/dev/null; then
echo '已添加开机自启, 如需关闭请执行: chkconfig ygk off'
return
fi
fi
if [ -d '/etc/rc.d/rc5.d' -a -f '/etc/init.d/ygk' ]; then
if ln -s '/etc/init.d/ygk' '/etc/rc.d/rc5.d/S99ygk'; then
echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc.d/rc5.d/S99ygk'
return
fi
fi
if [ -d '/etc/rc5.d' -a -f '/etc/init.d/ygk' ]; then
if ln -s '/etc/init.d/ygk' '/etc/rc5.d/S99ygk'; then
echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc5.d/S99ygk'
return
fi
fi
if [ -d '/etc/rc.d' -a -f '/etc/init.d/ygk' ]; then
if ln -s '/etc/init.d/ygk' '/etc/rc.d/S99ygk'; then
echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc.d/S99ygk'
return
fi
fi
echo '没有添加开机自启, 如需开启请手动添加'
}
Install() {
Config
Delete >/dev/null 2>&1
InstallInit
InstallFiles
ret=`"${ygk_install_dir}/ygk.init" start`
if ! echo "$ret"|grep -q 'OK' || echo "$ret"|grep -q 'FAILED'; then
Error "ygk install failed."
fi
type systemctl && [ -z "$(systemctl --failed|grep -q 'Host is down')" ] && systemctl restart ygk
echo $echo_e_arg \
"\033[44;37mygk install success.\033[0;34m
\r ygk server port:\033[35G${ygk_port}
\r ygk auth secret:\033[35G${ygk_auth_secret}
\r ygk client key:\033[35G${ygk_clientkey}
\r`[ -f /etc/init.d/ygk ] && /etc/init.d/ygk usage || \"$ygk_install_dir/ygk.init\" usage`
\r`AddAutoStart`\033[0m"
}
Uninstall() {
if [ -z "$ygk_install_dir" ]; then
echo -n "Please input ygk install directory(default is /usr/local/ygk): "
read ygk_install_dir
fi
Delete >/dev/null 2>&1 && \
echo $echo_e_arg "\n\033[44;37mygk uninstall success.\033[0m" || \
echo $echo_e_arg "\n\033[41;37mygk uninstall failed.\033[0m"
}
#script initialization
ScriptInit() {
emulate bash 2>/dev/null #zsh emulation mode
if echo -e ''|grep -q 'e'; then
echo_e_arg=''
echo_E_arg=''
else
echo_e_arg='-e'
echo_E_arg='-E'
fi
PM=`which apt-get || which yum`
type curl || type wget || $PM -y install curl wget
type curl && download_tool='curl -sko' || download_tool='wget --no-check-certificate -qO'
clear
}
ScriptInit
echo $*|grep -qi uninstall && Uninstall || Install