-
Notifications
You must be signed in to change notification settings - Fork 3
/
start.sh
executable file
·96 lines (86 loc) · 1.96 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
#!/bin/bash
# Load password from config.sh
set -e
cd ~/server
source config/config.sh
help() {
# TODO: Expand upon this
echo "Usage: $0 [--help, -h] [--version, -v] [--config, -c]" 1>&2
exit 1
}
# Check that arguments were passed
if [[ $# == 0 ]]; then
help
fi
# Parse arguments
! PARSE=$(getopt --options hv:c: --longoptions help,version:,config: --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
help
fi
eval set -- "$PARSE"
# Save arguments into variables
while true; do
case "$1" in
-h|--help)
help
shift ;;
-v|--version)
VERSIONARG="$2"
shift 2 ;;
-c|--config)
CONFIGARG="$2"
shift 2 ;;
--)
shift
break ;;
*)
echo "whoops! (the programmer made a mistake!)"
exit 3 ;;
esac
done
## Check for 'all' arguments
if [ "$VERSIONARG" = "all" ]; then
# Store all versions in array
BINARIES=($(ls binaries))
else
# Single version, check if exists, store in array
if [ -d "binaries/$VERSIONARG" ]; then
BINARIES=("$VERSIONARG")
else
echo "Binary $VERSIONARG doesn't exist!"
exit 1
fi
fi
if [ "$CONFIGARG" = "all" ]; then
# Store all configs in array
CONFIGS=($(find config/enabled -type f | sed 's%^config/enabled/%%'))
else
# Single config, check if exists, store in array
if [ -f "config/enabled/$CONFIGARG.conf" ]; then
CONFIGS=("$CONFIGARG.conf")
else
echo "Config $CONFIGARG.conf not enabled or doesn't exist!"
exit 1
fi
fi
# Loop through chosen binaries and run with chosen configs.
for i in "${BINARIES[@]}"
do
if [[ ! -d /tmp/"$i" ]]; then
mkdir /tmp/"$i"
fi
for c in "${CONFIGS[@]}"
do
cd ~/server
CONFIG="config/enabled/$c"
TEMP="teeworlds.$RANDOM.conf"
cat "$CONFIG" >> "/tmp/$TEMP"
cd /tmp
echo "sv_rcon_password $adminpass" >> $TEMP
echo "sv_rcon_mod_password $modpass" >> $TEMP
# Random port
echo "sv_port $(shuf -i 5000-50000 -n 1)" >> $TEMP
# Run the servers
nohup bash -c "~/server/binaries/\"$i\"/teeworlds_srv -f $TEMP; rm /tmp/$TEMP" > /tmp/"$i"/$(basename "$c").out &
done
done