forked from psymin/wf_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwf_tool.sh
executable file
·315 lines (233 loc) · 6.71 KB
/
wf_tool.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
# wf_tool.sh
#
# A tool for installing warfork servers in a uniform and repeatable manner
# LinuxGSM is far superior in every way, but this gets the job done
USERNAME="anonymous" # Your steam username
PASSWORD="" # Your steam password
APPID="1136510" # The appid of the warfork server (this will change
# in the future to a dedicated tool that can be fetched
# anonymously
HOMEDIR=`eval echo ~$USER`
# set the user's home dir to a variable
INSTALLDIR="${HOMEDIR}/warfork"
# set INSTALLDIR to the explicit path you want
# or leave default for /home/steamcmd/wf_server
PLATFORM="linux" # Valid values are "windows" "macos" or "linux"
STEAMCMD="/usr/games/steamcmd"
UDP="44400" # UDP port of the server
TCP="44444" # TCP port of the server
#####
# functions
#####
os_version () {
# in theory this variable can be set and used
# to add support for more distros than just Ubuntu 18.04 LTS
if [[ -f /etc/debian_version ]]
then
OS_VERSION=`cat /etc/debian_version`
else
OS_VERSION="unsupported"
fi
}
os_version
wf_update () {
if [[ -f ${INSTALLDIR}/steamapps/appmanifest_${APPID=}.acf ]]
then
BUILDID=`grep buildid ${INSTALLDIR}/steamapps/appmanifest_${APPID=}.acf | awk '{print $2}'`
REMOTEBUILDID=`${STEAMCMD} +@sSteamCmdForcePlatformType ${PLATFORM} +@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login ${USERNAME} ${PASSWORD} +force_install_dir ${INSTALLDIR} +app_info_update 1 +app_info_print ${APPID} +quit | grep buildid | awk '{print $2}'`
if [[ ${BUILDID} != ${REMOTEBUILDID} ]]
then
echo "Update necessary"
echo "${BUILDID} != ${REMOTEBUILDID}"
screen -S warfork -X stuff 'say server updating to latest steam build'$(echo -ne '\015')
${STEAMCMD} +@sSteamCmdForcePlatformType ${PLATFORM} +@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login ${USERNAME} ${PASSWORD} +force_install_dir ${INSTALLDIR} +app_update ${APPID} validate +quit
screen -S warfork -X stuff 'say update complete'$(echo -ne '\015')
screen -S warfork -X stuff 'say manual server restrat required'$(echo -ne '\015')
fi
else
echo "Warfork is not installed (${APPID})"
echo "Install it with ./wf_tool.sh install"
fi
}
wf_install () {
${STEAMCMD} +@sSteamCmdForcePlatformType ${PLATFORM} +@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login ${USERNAME} ${PASSWORD} +force_install_dir ${INSTALLDIR} +app_update ${APPID} validate +quit
}
wf_start () {
cd ${INSTALLDIR}/Warfork.app/Contents/Resources
/usr/bin/screen -d -S "warfork" -m ${INSTALLDIR}/Warfork.app/Contents/Resources/wf_server.x86_64
}
wf_setup () {
${STEAMCMD} +@sSteamCmdForcePlatformType ${PLATFORM} +login ${USERNAME} ${PASSWORD} +quit
}
wf_cron () {
#Add a cronjob to the user to update and start server."
CRON=`crontab -l`
if [[ $CRON == "" ]]
then
echo "*/5 * * * * ${HOMEDIR}/wf_tool.sh update
@reboot ${HOMEDIR}/wf_tool.sh start" | /usr/bin/crontab
else
echo "crontab for your user is not empty"
echo "manually set your crontab using crontab -e"
echo
echo "*/5 * * * * ${HOMEDIR}/wf_tool.sh update"
echo "@reboot ${HOMEDIR}/wf_tool.sh start"
fi
}
wf_status () {
ps uwww -C wf_server.x86_64
SCREENINFO=`screen -list warfork 2>/dev/null`
echo
echo screen info
echo
echo ${SCREENINFO}
echo
echo UDP info
echo
/bin/nc -vz -u localhost ${UDP}
echo
echo TCP info
echo
/bin/nc -vz localhost ${TCP}
}
wf_tools () {
case $OS_VERSION in
buster/sid)
sudo apt-get install steamcmd screen
;;
unsupported)
echo "OS unsupported at this time"
;;
*)
echo "Only Ubuntu 18.04 (buster/sid) is supported currently."
echo "Your OS is ${OS_VERSION}"
esac
}
wf_console () {
echo "WARNING: to detach from this screen session you need to type CTRL-A D"
echo "Hold the CTRL key and the D key, then press the A key."
echo ""
echo "CTRL-A D to exit the session without killing the server."
echo ""
echo -n "Sleeping for 10 seconds"
for i in `seq 1 10`
do
sleep 1 && echo -n .
done
/usr/bin/screen -r warfork
}
wf_config () {
cp ${INSTALLDIR}/Warfork.app/Contents/Resources/basewf/dedicated_autoexec.cfg ${HOMEDIR}/.local/share/warfork-2.1/basewf/dedicated_autoexec.cfg
}
wf_usage () {
echo "Usage: ./wf_update.sh <command>"
echo "-------------------------------"
echo "Valid commands:"
echo "start (start the server)"
echo "update (update/install the server"
echo "setup (set up steamcmd for the first time"
echo "cron (add cronjob for updates and start on boot)"
echo "tools (install steamcmd and other tools)"
echo "osupdate (update the host operating system)"
echo "status (check status of service)"
echo "stop (stops the server)"
echo "console (attaches to the wf_server screen)"
echo "everything (does everything but start server)"
}
wf_stop () {
screen -S warfork -X stuff 'quit'$(echo -ne '\015')
}
wf_osupdate () {
case $OS_VERSION in
buster/sid)
sudo apt-get update
sudo apt-get upgrade
;;
unsupported)
echo "OS unsupported at this time"
;;
*)
echo "Only Ubuntu 18.04 (buster/sid) is supported currently."
echo "Your OS is ${OS_VERSION}"
esac
}
wf_everything () {
echo "Operating System Update"
wf_osupdate
echo "Tools install"
wf_tools
echo "First time setup for steamcmd"
wf_setup
echo "Warfork server fetch from steam"
wf_install
#echo "Starting the server"
#wf_start
#echo "Checking status of server"
#wf_status
#echo "Stopping server"
#wf_stop
# for some reason starting the server in this function fails
echo "Adding cronjob for updates and starting on boot"
wf_cron
echo "#########################################"
echo "# #"
echo "# Your server should now be installed #"
echo "# #"
echo "#########################################"
echo
echo "A default server config was installed here:"
echo "${HOMEDIR}/.local/share/warfork-2.1/basewf/dedicated_autoexec.cfg"
echo
echo "Edit that config (nano, vi, or copy it from your local machine)"
echo
echo "Start the server with ./wf_tool.sh start"
echo
echo "Verify status of the server with ./wf_tool.sh status"
echo
echo "Stop the server with ./wf_tool.sh stop"
echo
echo "Ask for help on Discord https://discord.gg/VY95TKZ"
echo
}
case "$1" in
start)
wf_start
;;
stop)
wf_stop
;;
update)
wf_update
;;
install)
wf_install
;;
setup)
wf_setup
;;
cron)
wf_cron
;;
boot)
wf_boot
;;
tools)
wf_tools
;;
osupdate)
wf_osupdate
;;
status)
wf_status
;;
console)
wf_console
;;
everything)
wf_everything
;;
*)
wf_usage
;;
esac