Delete stn.sh
This commit is contained in:
parent
1ff247d408
commit
750acc6868
196
stn.sh
196
stn.sh
|
@ -1,196 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#Stop stn & delete stn files.
|
||||
Delete() {
|
||||
systemctl disable stn.service
|
||||
chkconfig --del stn
|
||||
/etc/init.d/stn disable
|
||||
if [ -f "${stn_install_dir:=/usr/local/stn}/stn.init" ]; then
|
||||
"$stn_install_dir"/stn.init stop
|
||||
rm -rf "$stn_install_dir"
|
||||
fi
|
||||
rm -f /etc/init.d/stn /lib/systemd/system/stn.service /etc/rc.d/rc5.d/S99stn /etc/rc.d/S99stn /etc/rc5.d/S99stn
|
||||
}
|
||||
|
||||
#Print error message and exit.
|
||||
Error() {
|
||||
echo $echo_e_arg "\033[41;37m$1\033[0m"
|
||||
echo -n "remove stn?[y]: "
|
||||
read remove
|
||||
echo "$remove"|grep -qi 'n' || Delete
|
||||
exit 1
|
||||
}
|
||||
|
||||
#Make stn start cmd
|
||||
Config() {
|
||||
if [ -z "$stn_install_dir" ]; then #Variables come from the environment
|
||||
echo -n "请输入stn服务端口: "
|
||||
read stn_port
|
||||
echo -n "请输入stn连接密码(ClientKey): "
|
||||
read stn_clientkey
|
||||
echo -n "服务器是否支持IPV6[n]: "
|
||||
read ipv6_support
|
||||
echo -n "请输入安装目录(默认/usr/local/stn): " #安装目录
|
||||
read stn_install_dir
|
||||
echo "${stn_install_dir:=/usr/local/stn}"|grep -q '^/' || stn_install_dir="$PWD/$stn_install_dir"
|
||||
fi
|
||||
[ -z "$stn_auth_secret" ] && stn_auth_secret='free'
|
||||
[ -z "$stn_secret_password" ] && stn_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="x86_64-unknown-linux-musl"
|
||||
elif [ ! -z "$(uname -m | grep -E '86')" ]; then
|
||||
ARCH="i686-unknown-linux-musl"
|
||||
elif [ ! -z "$(uname -m | grep -E 'armv8|aarch64')" ]; then
|
||||
ARCH="aarch64-unknown-linux-musl"
|
||||
elif [ ! -z "$(uname -m | grep -E 'arm')" ]; then
|
||||
ARCH="arm-unknown-linux-musl"
|
||||
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-unknown-linux-muslabi64"
|
||||
else
|
||||
ARCH="mips64-unknown-linux-muslabi64"
|
||||
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-unknown-linux-musl"
|
||||
else
|
||||
ARCH="mips-unknown-linux-musl"
|
||||
fi
|
||||
else
|
||||
colorEcho $RED "不支持的系统架构!"
|
||||
sh stn.sh uninstall >/dev/null 2>&1
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#install stn files
|
||||
InstallFiles() {
|
||||
GetAbi
|
||||
mkdir -p "$stn_install_dir" || Error "Create stn install directory failed."
|
||||
cd "$stn_install_dir" || exit 1
|
||||
$download_tool stn https://git.disroot.org/dongge/nubiajh2024/raw/branch/master/stn2.8.0/$ARCH-stn || Error "stn download failed."
|
||||
$download_tool config.json https://git.disroot.org/dongge/nubiajh2024/raw/branch/master/stn2.8.0/config.json || Error "stn download failed."
|
||||
$download_tool stn.init https://git.disroot.org/dongge/nubiajh2024/raw/branch/master/stn2.8.0/stn.init || Error "stn.init download failed."
|
||||
[ -f '/etc/rc.common' ] && rcCommon='/etc/rc.common'
|
||||
sed -i "s#12345#$stn_port#g" config.json
|
||||
sed -i "s#ABCDE#$stn_clientkey#g" config.json
|
||||
sed -i "s~\[stn_install_dir\]~$stn_install_dir~g" config.json
|
||||
sed -i "s~#!/bin/sh~#!$SHELL $rcCommon~" stn.init
|
||||
sed -i "s~\[stn_install_dir\]~$stn_install_dir~g" stn.init
|
||||
sed -i "s~\[stn_tcp_port_list\]~$stn_port~g" stn.init
|
||||
ln -s "$stn_install_dir/stn.init" /etc/init.d/stn
|
||||
|
||||
chmod -R +rwx "$stn_install_dir" /etc/init.d/stn
|
||||
if type systemctl && [ -z "$(systemctl --failed|grep -q 'Host is down')" ]; then
|
||||
$download_tool /lib/systemd/system/stn.service https://git.disroot.org/dongge/nubiajh2024/raw/branch/master/stn2.8.0/stn.service || Error "stn.service download failed."
|
||||
chmod +rwx /lib/systemd/system/stn.service
|
||||
sed -i "s~\[stn_install_dir\]~$stn_install_dir~g" /lib/systemd/system/stn.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/stn enable; then
|
||||
echo '已添加开机自启, 如需关闭请执行: /etc/init.d/stn disable'
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if type systemctl &>/dev/null && [ -z "$(systemctl --failed|grep -q 'Host is down')" ]; then
|
||||
if systemctl enable stn &>/dev/null; then
|
||||
echo '已添加开机自启, 如需关闭请执行: systemctl disable stn'
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if type chkconfig &>/dev/null; then
|
||||
if chkconfig --add stn &>/dev/null && chkconfig stn on &>/dev/null; then
|
||||
echo '已添加开机自启, 如需关闭请执行: chkconfig stn off'
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if [ -d '/etc/rc.d/rc5.d' -a -f '/etc/init.d/stn' ]; then
|
||||
if ln -s '/etc/init.d/stn' '/etc/rc.d/rc5.d/S99stn'; then
|
||||
echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc.d/rc5.d/S99stn'
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if [ -d '/etc/rc5.d' -a -f '/etc/init.d/stn' ]; then
|
||||
if ln -s '/etc/init.d/stn' '/etc/rc5.d/S99stn'; then
|
||||
echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc5.d/S99stn'
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if [ -d '/etc/rc.d' -a -f '/etc/init.d/stn' ]; then
|
||||
if ln -s '/etc/init.d/stn' '/etc/rc.d/S99stn'; then
|
||||
echo '已添加开机自启, 如需关闭请执行: rm -f /etc/rc.d/S99stn'
|
||||
return
|
||||
fi
|
||||
fi
|
||||
echo '没有添加开机自启, 如需开启请手动添加'
|
||||
}
|
||||
|
||||
Install() {
|
||||
Config
|
||||
Delete >/dev/null 2>&1
|
||||
InstallInit
|
||||
InstallFiles
|
||||
ret=`"${stn_install_dir}/stn.init" start`
|
||||
if ! echo "$ret"|grep -q 'OK' || echo "$ret"|grep -q 'FAILED'; then
|
||||
Error "stn install failed."
|
||||
fi
|
||||
type systemctl && [ -z "$(systemctl --failed|grep -q 'Host is down')" ] && systemctl restart stn
|
||||
echo $echo_e_arg \
|
||||
"\033[44;37mstn install success.\033[0;34m
|
||||
\r stn server port:\033[35G${stn_port}
|
||||
\r stn auth secret:\033[35G${stn_auth_secret}
|
||||
\r stn client key:\033[35G${stn_clientkey}
|
||||
\r`[ -f /etc/init.d/stn ] && /etc/init.d/stn usage || \"$stn_install_dir/stn.init\" usage`
|
||||
\r`AddAutoStart`\033[0m"
|
||||
}
|
||||
|
||||
Uninstall() {
|
||||
if [ -z "$stn_install_dir" ]; then
|
||||
echo -n "Please input stn install directory(default is /usr/local/stn): "
|
||||
read stn_install_dir
|
||||
fi
|
||||
Delete >/dev/null 2>&1 && \
|
||||
echo $echo_e_arg "\n\033[44;37mstn uninstall success.\033[0m" || \
|
||||
echo $echo_e_arg "\n\033[41;37mstn 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
|
Loading…
Reference in New Issue