-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.sh
executable file
·248 lines (203 loc) · 6.31 KB
/
start.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
#!/bin/bash
# Termination function
function cleanupAndUnlock {
# Clean up generated files
for PORT in $BZLUSRVPORT
do
rm run/$PORT-pid.txt
rm run/$PORT-plugins.txt
rm run/$PORT-map.txt
rm run/$PORT-maplist.txt
rm run/$PORT-bzfs.txt
done
if [[ $BZLURPLYSRVPORT ]]
then
rm run/$BZLURPLYSRVPORT-pid.txt
rm run/$BZLURPLYSRVPORT-bzfs.txt
rm run/$BZLURPLYSRVPORT-plugins.txt
fi
# Release lock file
rmdir run/main.lock 2>/dev/null
# Remove the keepalive file if we were not terminated by the stop script
if [[ -f run/main.keepalive ]]
then
rm run/main.keepalive
fi
}
# Change directory to the one containing this script, which allows this script to be called from anywhere
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Ensure our needed directories exist
mkdir -p logs/errors recordings run
# Try to create lock file, or exit if it exists
if [[ -e run/main.lock ]]
then
exit 0
elif [[ `mkdir run/main.lock 2>&1` ]]
then
echo Unable to create lock file.
exit 1
fi
# Touch keepalive file
touch run/main.keepalive
# Set default configuration values, then load configuration to override them as appropriate
BZBINDIR=/usr/local/bin
BZLIBDIR=/usr/local/lib/bzflag
BZLUSRVKEY=""
BZLUSRVADDR=""
BZLURPLYSRVPORT=5195
BZLUSRVPORT="5196 5197 5198"
BZLUSRVLOC=""
BZLUDBGLVL=""
BZLUBANFILE=support/bans.txt
if [[ -f config.txt ]]
then
source config.txt
fi
# Enter subshell
(
# Set trap so we don't leave stale info behind upon exiting
trap cleanupAndUnlock SIGINT SIGTERM
# Start loop for each port
for PORT in $BZLUSRVPORT
do
# Create map list
echo -e "HiX HiX\nDucati Ducati\nDucatiMini DucatiMini\nBabel Babel\nPillbox Pillbox" > run/$PORT-maplist.txt
# Start loop
while [[ -e run/main.keepalive ]]
do
# Prepare configuration
if [[ -f run/$PORT-map.txt ]]
then
BZLUMAP=`cat run/$PORT-map.txt`
else
BZLUMAP=HiX
echo $BZLUMAP > run/$PORT-map.txt
fi
BZLUSRVTITLE="Official Leagues United Match Server :: $BZLUMAP"
if [[ $BZLUSRVLOC ]]
then
BZLUSRVTITLE="$BZLUSRVTITLE :: $BZLUSRVLOC"
fi
echo -publictitle \"$BZLUSRVTITLE\" > run/$PORT-bzfs.txt
if [[ $BZLUSRVADDR ]]
then
BZLUSRVADDRARG="$BZLUSRVADDR:$PORT"
else
BZLUSRVADDRARG=
fi
echo -publickey $BZLUSRVKEY >> run/$PORT-bzfs.txt
echo -p $PORT >> run/$PORT-bzfs.txt
echo -pidfile run/$PORT-pid.txt >> run/$PORT-bzfs.txt
echo -conf support/bzfs.txt >> run/$PORT-bzfs.txt
echo -e "[leagueOverSeer]" > run/$PORT-plugins.txt
echo -e "\tROTATIONAL_LEAGUE=true" >> run/$PORT-plugins.txt
echo -e "\tMAPCHANGE_PATH=run/$PORT-map.txt" >> run/$PORT-plugins.txt
echo -e "\tLEAGUE_OVERSEER_URL=http://leaguesunited.org/api/leagueOverseer" >> run/$PORT-plugins.txt
echo -e "\tDEBUG_LEVEL=0" >> run/$PORT-plugins.txt
echo -e "" >> run/$PORT-plugins.txt
echo -e "[mapchange]" >> run/$PORT-plugins.txt
echo -e "\tConfigurationFile=run/$PORT-maplist.txt" >> run/$PORT-plugins.txt
echo -e "\tOutputFile=run/$PORT-map.txt" >> run/$PORT-plugins.txt
echo -e "" >> run/$PORT-plugins.txt
echo -e "[ServerControl]" >> run/$PORT-plugins.txt
echo -e "\tBanFile=$BZLUBANFILE" >> run/$PORT-plugins.txt
if [[ $BZLUMAP == "Ducati" ]]
then
BZLUMAPARG="-conf support/Ducati.conf"
elif [[ $BZLUMAP == "DucatiMini" ]]
then
BZLUMAPARG="-conf support/DucatiMini.conf"
else
BZLUMAPARG="-world support/$BZLUMAP.bzw"
fi
echo $BZLUMAPARG >> run/$PORT-bzfs.txt
echo \
-loadplugin $BZLIBDIR/leagueOverSeer.so,run/$PORT-plugins.txt \
-loadplugin $BZLIBDIR/mapchange.so,run/$PORT-plugins.txt \
-loadplugin $BZLIBDIR/serverControl.so,run/$PORT-plugins.txt \
-loadplugin $BZLIBDIR/TimeLimit.so,15,20,30 >> run/$PORT-bzfs.txt
if [[ "$BZLUDBGLVL" == 1 ]]
then
echo -d >> run/$PORT-bzfs.txt
elif [[ "$BZLUDBGLVL" == 2 ]]
then
echo -dd >> run/$PORT-bzfs.txt
elif [[ "$BZLUDBGLVL" == 3 ]]
then
echo -ddd >> run/$PORT-bzfs.txt
elif [[ "$BZLUDBGLVL" == 4 ]]
then
echo -dddd >> run/$PORT-bzfs.txt
else
echo -loadplugin $BZLIBDIR/logDetail.so >> run/$PORT-bzfs.txt
fi
echo -ts >> run/$PORT-bzfs.txt
echo -banfile $BZLUBANFILE >> run/$PORT-bzfs.txt
# Start the server
$BZBINDIR/bzfs \
-conf run/$PORT-bzfs.txt \
-publicaddr $BZLUSRVADDRARG \
>> logs/$PORT.txt \
2> logs/errors/$PORT.txt
sleep 1
done &
done
# Start loop for replay port
if [[ $BZLURPLYSRVPORT ]]
then
while [[ -e run/main.keepalive ]]
do
# Prepare configuration
BZLUSRVTITLE="Official Leagues United Replay Server"
if [[ $BZLUSRVLOC ]]
then
BZLUSRVTITLE="$BZLUSRVTITLE :: $BZLUSRVLOC"
fi
echo -publictitle \"$BZLUSRVTITLE\" > run/$BZLURPLYSRVPORT-bzfs.txt
if [[ $BZLUSRVADDR ]]
then
BZLUSRVADDRARG="-publicaddr $BZLUSRVADDR:$BZLURPLYSRVPORT"
else
BZLUSRVADDRARG=
fi
echo -p $BZLURPLYSRVPORT >> run/$BZLURPLYSRVPORT-bzfs.txt
echo -publickey $BZLUSRVKEY >> run/$BZLURPLYSRVPORT-bzfs.txt
echo -pidfile run/$BZLURPLYSRVPORT-pid.txt >> run/$BZLURPLYSRVPORT-bzfs.txt
echo -conf support/bzfs.txt >> run/$BZLURPLYSRVPORT-bzfs.txt
echo -e "[ServerControl]" >> run/$BZLURPLYSRVPORT-plugins.txt
echo -e "\tBanFile=$BZLUBANFILE" >> run/$BZLURPLYSRVPORT-plugins.txt
echo -loadplugin $BZLIBDIR/serverControl.so,run/$BZLURPLYSRVPORT-plugins.txt >> run/$BZLURPLYSRVPORT-bzfs.txt
if [[ "$BZLUDBGLVL" == 1 ]]
then
echo -d >> run/$BZLURPLYSRVPORT-bzfs.txt
elif [[ "$BZLUDBGLVL" == 2 ]]
then
echo -dd >> run/$BZLURPLYSRVPORT-bzfs.txt
elif [[ "$BZLUDBGLVL" == 3 ]]
then
echo -ddd >> run/$BZLURPLYSRVPORT-bzfs.txt
elif [[ "$BZLUDBGLVL" == 4 ]]
then
echo -dddd >> run/$BZLURPLYSRVPORT-bzfs.txt
else
echo -loadplugin $BZLIBDIR/logDetail.so >> run/$BZLURPLYSRVPORT-bzfs.txt
fi
echo -ts >> run/$BZLURPLYSRVPORT-bzfs.txt
echo -banfile $BZLUBANFILE >> run/$BZLURPLYSRVPORT-bzfs.txt
echo -replay >> run/$BZLURPLYSRVPORT-bzfs.txt
# Start the server
$BZBINDIR/bzfs \
-conf run/$BZLURPLYSRVPORT-bzfs.txt \
$BZLUSRVADDRARG \
>> logs/$BZLURPLYSRVPORT.txt \
2> logs/errors/$BZLURPLYSRVPORT.txt
sleep 1
done &
fi
# Wait for all of those to be terminated and finish
wait
# Clean up
cleanupAndUnlock
) &
# TODO
# * Create configuration option for a custom report pipe and implement in launch loop