forked from OgarProject/Ogar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ogar-linux-script.sh
226 lines (194 loc) · 5.5 KB
/
ogar-linux-script.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Ogar Linux Script
#!/bin/sh
##Function Definition
#Download, extract .tar.gz and clean function
download_and_extract () {
if [ ! -d Ogar-master ]; then
if [ ! -f master.tar.gz ]; then
echo "No local master.tar.gz found, downloading with curl."
curl -O -L https://github.com/forairan/Ogar/archive/master.tar.gz
fi
if [ ! -f master.tar.gz ]; then
echo "curl failed to download master.tar.gz, trying wget."
wget https://github.com/forairan/Ogar/archive/master.tar.gz
if [ ! -f master.tar.gz ]; then
echo "wget failed as well. Aborting!"
exit 1
fi
fi
echo "master.tar.gz found!"
echo "Extracting master.tar.gz to /tmp."
tar -xzf master.tar.gz -C /tmp
echo "Removing master.tar.gz."
rm master.tar.gz
echo "Entering temporary directory."
cd /tmp || exit 1
echo "Organising and cleaning up the extracted files."
rm Ogar-master/src/Start.bat
rm Ogar-master/.gitignore
fi
}
#Install Function
ogar_install() {
echo "INSTALLING"
if [ "$2" = "" ]; then
echo "Please specify the directory in which you would like to install Ogar."
exit 1
fi
echo "The Ogar server will be installed inside $2/ogar."
echo "Do you wish to continue? (Y/N)"
read -r yn
case $yn in
[Yy]* ) ;;
* ) exit 1;;
esac
if [ ! -d "$2" ]; then
echo "$2 doesn't exist or is otherwise not accessible. Make sure you use absolute paths."
exit 1
fi
if [[ ! "$2" = /* ]]
then
echo "$2 isn't an absolute path! This is required for proper installation."
exit 1
fi
if grep "Arch Linux" /etc/*-release > /dev/null; then
echo "You are running Arch Linux. It is recommended to use the Ogar AUR package - https://aur4.archlinux.org/packages/ogar-git/"
echo "Do you wish to continue? (Y/N)"
read -r yn
case $yn in
[Yy]* ) ;;
* ) exit 1;;
esac
fi
download_and_extract
echo "Copying the generated ogar folder to $2."
cp -RTf Ogar-master "$2"/ogar
echo "Removing temporary files"
rm -R Ogar-master
echo "Creating ogar user and group if they don't exist"
if ! getent group "ogar" >/dev/null; then
groupadd -r ogar
fi
if ! getent passwd "ogar" >/dev/null; then
useradd -r -M -N -g ogar -d "$2"/ogar -s /usr/bin/nologin -c 'Ogar Server' ogar
fi
echo "Installing ws module"
rm -R /root/.npm
cd "$2"/ogar || exit 1
npm install ws
echo "Symlinking gameserver.ini to /etc/ogar"
ln -s "$2"/ogar/gameserver.ini /etc/ogar
echo "Setting proper permissions"
chown -R ogar:ogar "$2"/ogar
chmod -R 755 "$2"/ogar
echo "Finished installing! :D"
}
#Update Function
ogar_update() {
echo "UPDATING"
if [ "$2" = "" ]; then
echo "Please specify your existing Ogar installation."
exit 1
fi
echo "The Ogar server inside $2/ogar will be updated."
echo "Do you wish to continue? (Y/N)"
read -r yn
case $yn in
[Yy]* ) ;;
* ) exit 1;;
esac
if [ ! -f "$2/ogar/src/index.js" ]; then
echo "$2/ogar/src/index.js either way doesn't exist or isn't accesible. Are you sure this is an Ogar installation?"
exit 1
fi
if [[ ! "$2" = /* ]]
then
echo "$2 isn't an absolute path! This is required for proper installation."
exit 1
fi
download_and_extract
echo "Do you wish to install a fresh gamserver.ini? (Y/N)"
read -r yn
case $yn in
[Yy]* ) ;;
* ) rm Ogar-master/gameserver.ini;;
esac
echo "Copying the generated ogar folder to $2."
cp -RTf Ogar-master "$2"/ogar
echo "Removing temporary files"
rm -R Ogar-master
echo "Updating ws module"
rm -R /root/.npm
cd "$2"/ogar || exit 1
npm install ws
echo "Setting proper permissions"
chown -R ogar:ogar "$2"/ogar
chmod -R 755 "$2"/ogar
echo "Finished updating! :D"
}
#Uninstall Function
ogar_uninstall() {
echo "UNINSTALLING"
if [ "$2" = "" ]; then
echo "Please specify the directory in which Ogar is installed."
exit 1
fi
if [ ! -f "$2/ogar/src/index.js" ]; then
echo "$2/ogar/src/index.js either way doesn't exist or isn't accesible. Are you sure this is an Ogar installation?"
exit 1
fi
echo "The ENTIRE $2/ogar folder will be DELETED."
echo "Do you wish to continue? (Y/N)"
read -r yn
case $yn in
[Yy]* ) ;;
* ) exit 1;;
esac
echo "Removing ogar user and group"
if getent passwd "ogar" >/dev/null; then
userdel ogar > /dev/null
fi
if getent group "ogar" >/dev/null; then
groupdel ogar >/dev/null
fi
echo "Unlinking /etc/ogar"
unlink /etc/ogar
echo "Removing ws module"
cd "$2"/ogar || exit 1
npm uninstall ws
echo "Removing the ENTIRE Ogar folder"
rm -R "$2"/ogar
echo "Finished uninstalling!"
}
echo "OGAR INSTALL, UPDATE AND UNINSTALL SCRIPT"
echo "Make sure you have: nodejs, npm, tar and wget/curl (for automatic downloads) installed!"
echo "However, you may also download and extract master.tar.gz manually."
echo "Place it in the same directory as the installer and name the extracted folder Ogar-master."
echo "----------------------------------------------------------------------------------------------------"
echo 'IMPORTANT: Use the following command to start the server in interactive mode for improved security:'
echo 'sudo -u ogar -H /bin/sh -c "cd; /bin/node src/index.js"'
if [ ! "$(id -u)" = 0 ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
case "$1" in
install)
ogar_install $1 $2
;;
update)
ogar_update $1 $2
;;
uninstall)
ogar_uninstall $1 $2
;;
"")
echo "Blank sub-command. Please specify if you want to install, update or uninstall."
exit 1
;;
*)
echo "Invalid sub-command. Please specify if you want to install, update or uninstall."
exit 1
;;
esac
#If I havn't exited abnormally yet, exit normally normally now
exit 0