-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinstall.sh
151 lines (140 loc) · 3.38 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
#=================================================
# System Required: CentOS/Debian/ArchLinux with Systemd Support
# Description: NodeStatus Client-Go
# Version: v1.0.1
# Author: Kagurazaka Mizuki
#=================================================
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[信息]${Font_color_suffix}"
Error="${Red_font_prefix}[错误]${Font_color_suffix}"
Tip="${Green_font_prefix}[注意]${Font_color_suffix}"
is_update=0
function check_sys() {
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif grep -q -E -i "debian|ubuntu" /etc/issue; then
release="debian"
elif grep -q -E -i "centos|red hat|redhat" /etc/issue; then
release="centos"
elif grep -q -E -i "Arch|Manjaro" /etc/issue; then
release="arch"
elif grep -q -E -i "debian|ubuntu" /proc/version; then
release="debian"
elif grep -q -E -i "centos|red hat|redhat" /proc/version; then
release="centos"
else
echo -e "NodeStatus Client 暂不支持该 Linux 发行版"
exit 1
fi
bit=$(uname -m)
}
function check_pid() {
PID=$(pgrep -f "status-client")
}
function install_dependencies() {
case ${release} in
centos)
yum install -y wget curl
;;
debian)
apt-get update -y
apt-get install -y wget curl
;;
arch)
pacman -Syu --noconfirm wget curl
;;
*)
exit 1
;;
esac
}
function input_dsn() {
echo -e "${Info} 请输入服务端的 DSN, 格式为 “ws(s)://username:password@yourdomain”"
read -re dsn
}
function install_client() {
case ${bit} in
x86_64)
arch=amd64
;;
i386)
arch=386
;;
aarch64 | aarch64_be | arm64 | armv8b | armv8l)
arch=arm64
;;
arm | armv6l | armv7l | armv5tel | armv5tejl)
arch=arm
;;
mips | mips64)
arch=mips
;;
*)
exit 1
;;
esac
mkdir -p /usr/local/NodeStatus/client/
cd /tmp && wget -N "https://github.com/cokemine/nodestatus-client-go/releases/latest/download/status-client_linux_${arch}.tar.gz"
tar -zxvf "status-client_linux_${arch}.tar.gz" status-client
mv status-client /usr/local/NodeStatus/client/
chmod +x /usr/local/NodeStatus/client/status-client
[[ -n ${dsn} ]] && echo -e "DSN=\"${dsn}\"" >/usr/local/NodeStatus/client/config.conf
wget https://raw.githubusercontent.com/cokemine/nodestatus-client-go/master/service/status-client.service -P /usr/lib/systemd/system/
systemctl enable status-client
systemctl start status-client
check_pid
if [[ -n ${PID} ]]; then
echo -e "${Info} NodeStatus Client 启动成功!"
else
echo -e "${Error} NodeStatus Client 启动失败!"
fi
}
function uninstall_client() {
systemctl stop status-client
systemctl disable status-client
if [[ ${is_update} == 0 ]]; then
rm -rf /usr/local/NodeStatus/client/
else
rm -rf /usr/local/NodeStatus/client/status-client
fi
rm -rf /usr/lib/systemd/system/status-client.service
}
check_sys
action=0
while [[ $# -gt 0 ]]; do
case $1 in
-d | --dsn)
dsn="$2"
shift
shift
;;
uninstall)
action=2
shift
;;
update)
action=1
shift
;;
*)
action=0
shift
;;
esac
done
case "${action}" in
0)
[[ -z ${dsn} ]] && input_dsn
install_dependencies
install_client
;;
1)
is_update=1
uninstall_client
install_client
;;
2)
uninstall_client
;;
esac