-
-
Notifications
You must be signed in to change notification settings - Fork 215
/
nging-installer.sh
executable file
·154 lines (126 loc) · 3.27 KB
/
nging-installer.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
152
153
154
# via curl:
# sudo sh -c "$(curl -fsSL https://raw.githubusercontent.com/admpub/nging/master/nging-installer.sh)"
# via wget:
# sudo sh -c "$(wget https://raw.githubusercontent.com/admpub/nging/master/nging-installer.sh -O -)"
# or
# sudo wget https://raw.githubusercontent.com/admpub/nging/master/nging-installer.sh -O ./nging-installer.sh && chmod +x ./nging-installer.sh && ./nging-installer.sh
osname=`uname -s`
arch=`uname -m`
version="5.2.6"
if [ "$2" != "" ] && [ "$2" != "-" ]; then
version="$2"
fi
url="https://img.nging.coscms.com/nging/v${version}/"
savedir="nging"
case "$arch" in
"x86_64"|"amd64")
arch="amd64"
;;
"i386"|"i686")
arch="386"
;;
"aarch64_be"|"aarch64"|"armv8b"|"armv8l"|"armv8"|"arm64")
arch="arm64"
;;
"armv7")
arch="arm-7"
;;
"armv7l")
arch="arm-6"
savedir="nging_linux_arm-7" # 兼容旧版
;;
"armv6")
arch="arm-6"
;;
"armv5"|"arm")
arch="arm-5"
;;
*)
echo "Unsupported Arch:${arch}"
exit 1
;;
esac
case $osname in
"Darwin")
osname="darwin"
;;
"Linux")
osname="linux"
;;
"FreeBSD")
osname="freebsd"
;;
*)
echo "Unsupported System:${osname}"
exit 1
;;
esac
binname="nging"
filename="nging_${osname}_$arch"
filefullname="$filename.tar.gz"
exitOnFailure() {
echo "❌ command failed"
exit 1
}
install() {
wget -c "${url}$filefullname" -O ./$filefullname || exitOnFailure
mkdir ./$savedir
tar -zxvf $filefullname -C ./$savedir || exitOnFailure
#unzip $filefullname -d ./$filename || exitOnFailure
cp -R ./$savedir/$filename/* ./$savedir || exitOnFailure
rm -rf "./$savedir/$filename"
rm $filefullname
chmod +x ./$savedir/$binname || exitOnFailure
cd ./$savedir
#./$binname
./$binname service install || exitOnFailure
./$binname service start || exitOnFailure
echo "🎉 Congratulations! Installed successfully."
}
upgrade() {
# 停止服务
cd ./$savedir
./$binname service stop
cd ../
wget -c "${url}$filefullname" -O ./$filefullname || exitOnFailure
mkdir ./$savedir
tar -zxvf $filefullname -C ./$savedir || exitOnFailure
#unzip $filefullname -d ./$filename || exitOnFailure
sleep 5s && pkill `pwd`/$savedir/$binname
cp -R ./$savedir/$filename/* ./$savedir || exitOnFailure
rm -rf "./$savedir/$filename"
rm $filefullname
chmod +x ./$savedir/$binname || exitOnFailure
cd ./$savedir
#./$binname
# 再次启动服务
./$binname service start
echo "🎉 Congratulations! Successfully upgraded."
}
uninstall() {
cd ./$savedir
./$binname service stop || exitOnFailure
./$binname service uninstall || exitOnFailure
cd ../
sleep 5s && pkill `pwd`/$savedir/$binname
echo "🎉 Congratulations! Successfully uninstalled."
rm -r ./$savedir || exitOnFailure
echo "🎉 Congratulations! File deleted successfully."
}
if [ "$3" != "" ]; then
savedir="$3"
fi
case "$1" in
"up"|"upgrade")
upgrade
;;
"un"|"uninstall")
uninstall
;;
"install")
install
;;
*)
install
;;
esac