docker-tmserver/entrypoint-tmserver.sh

134 lines
4.5 KiB
Bash
Raw Normal View History

2019-05-11 16:09:58 +02:00
#!/bin/bash
#
set -e
2019-09-27 10:55:08 +02:00
if [[ "$(id -u)" = "0" ]]; then
chown -R trackmania /opt/tmserver
exec su-exec trackmania "$0"
fi
2019-09-27 11:01:03 +02:00
# Change dir to /opt/tmserver
cd /opt/tmserver
2019-05-11 16:09:58 +02:00
# Evaluate all the available environment variables
if [[ -z "${SERVER_LOGIN}" ]]; then
echo "Server account login is missing. Server cannot start."
2019-09-27 11:07:14 +02:00
echo "Please set environment variable SERVER_LOGIN."
2019-05-11 16:09:58 +02:00
exit 9
fi
if [[ -z "${SERVER_LOGIN_PASSWORD}" ]]; then
echo "Server account password is missing. Server cannot start."
2019-09-27 11:07:14 +02:00
echo "Please set environment variable SERVER_LOGIN_PASSWORD."
2019-05-11 16:09:58 +02:00
exit 9
fi
if [[ -z "${SERVER_PORT}" ]]; then
echo "No server port was set. Defaulting to port 2350"
2019-09-28 11:49:02 +02:00
export SERVER_PORT="2350"
2019-05-11 16:09:58 +02:00
fi
if [[ -z "${SERVER_P2P_PORT}" ]]; then
echo "No server peer2peer port was set. Defaulting to port 3450"
2019-09-28 11:49:02 +02:00
export SERVER_P2P_PORT="3450"
2019-05-11 16:09:58 +02:00
fi
if [[ -z "${SERVER_SA_PASSWORD}" ]]; then
echo "No SuperAdmin password was set. Generating a random one. You can change it afterwards but it's also not that important"
echo "Might aswell leave it as randomly generated"
2019-09-28 11:49:02 +02:00
export SERVER_SA_PASSWORD=$(pwgen -s 12)
2019-05-11 16:09:58 +02:00
echo "SuperAdmin password: ${SERVER_SA_PASSWORD}"
2019-09-27 11:07:14 +02:00
echo "Please write this down or pipe the docker logs to a file."
2019-05-11 16:09:58 +02:00
fi
if [[ -z "${SERVER_ADM_PASSWORD}" ]]; then
echo "No Admin password was set. Generating a random one. You can change it afterwards but it's also not that important"
echo "Might aswell leave it as randomly generated"
2019-09-28 11:49:02 +02:00
export SERVER_ADM_PASSWORD=$(pwgen -s 12)
2019-05-11 16:09:58 +02:00
echo "Admin password: ${SERVER_ADM_PASSWORD}"
2019-09-27 11:07:14 +02:00
echo "Please write this down or pipe the docker logs to a file."
2019-05-11 16:09:58 +02:00
fi
if [[ -z "${SERVER_NAME}" ]]; then
echo "No server name was set. Defaulting to 'Trackmania Server'"
2019-09-28 11:49:02 +02:00
export SERVER_NAME="Trackmania Server"
2019-05-11 16:09:58 +02:00
fi
if [[ -z "${SERVER_COMMENT}" ]]; then
echo "No server description was set. Defaulting to 'This is a Trackmania Server'"
2019-09-28 11:49:02 +02:00
export SERVER_COMMENT="This is a Trackmania Server"
2019-05-11 16:09:58 +02:00
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${GAMEMODE}" ]]; then
echo "No gamemode was specified. Defaulting to TimeAttack."
2019-09-28 11:49:02 +02:00
export GAMEMODE="1"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${CHATTIME}" ]]; then
echo "No chat timeout was specified. Defaulting to 10000 ms."
2019-09-28 11:49:02 +02:00
export CHATTIME="10000"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${FINISHTIMEOUT}" ]]; then
echo "No finish timeout was specified. Defaulting to adaptive mode."
2019-09-28 11:49:02 +02:00
export FINISHTIMEOUT="1"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${DISABLERESPAWN}" ]]; then
echo "Respawns were not specified. Defaulting to enabled."
2019-09-28 11:49:02 +02:00
export DISABLERESPAWN="0"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${ROUNDS_POINTSLIMIT}" ]]; then
echo "No points limit was specified for rounds mode. Defaulting to 30."
2019-09-28 11:49:02 +02:00
export ROUNDS_POINTSLIMIT="30"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${TIMEATTACK_LIMIT}" ]]; then
echo "No time limit was specified for time attack mode. Defaulting to 180000 ms."
2019-09-28 11:49:02 +02:00
export TIMEATTACK_LIMIT="180000"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${TEAM_POINTSLIMIT}" ]]; then
echo "No points limit was specified for team mode. Defaulting to 50."
2019-09-28 11:49:02 +02:00
export TEAM_POINTSLIMIT="50"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${TEAM_MAXPOINTS}" ]]; then
echo "No number of maximum points per round was specified for team mode. Defaulting to 6."
2019-09-28 11:49:02 +02:00
export TEAM_MAXPOINTS="6"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${LAPS_NBLAPS}" ]]; then
echo "No number of laps was specified for laps mode. Defaulting to 5."
2019-09-28 11:49:02 +02:00
export LAPS_NBLAPS="5"
fi
2019-09-27 10:55:08 +02:00
if [[ -z "${LAPS_TIMELIMIT}" ]]; then
echo "No time limit was specified for laps mode. Defaulting to no limit."
2019-09-28 11:49:02 +02:00
export LAPS_TIMELIMIT="0"
fi
echo "Evaluation over"
2019-09-28 13:25:49 +02:00
echo "Checking for custom playlist"
CUSTOM_PLAYLIST='playlist/playlist.txt'
TEMPLATE_PLAYLIST='GameData/Tracks/MatchSettings/_playlist.txt'
TMP_FILE='GameData/Tracks/MatchSettings/_playlist.txt.tmp'
if [[ -f 'playlist/playlist.txt' ]]; then
count=1
while read l; do
xmlstarlet ed -s /playlist -t elem -n challenge $TEMPLATE_PLAYLIST > $TMP_FILE
xmlstarlet ed -s "/playlist/challenge[${count}]" -t elem -n file -v "${l}" $TMP_FILE > $TEMPLATE_PLAYLIST
count=$((count+1))
done < $CUSTOM_PLAYLIST
else
xmlstarlet ed -s /playlist -t elem -n challenge $TEMPLATE_PLAYLIST > $TMP_FILE
xmlstarlet ed -s "playlist/challenge[1]" -t elem -n file -v "Challenges/Nadeo/A01-Race.Challenge.Gbx" $TMP_FILE > $TEMPLATE_PLAYLIST
fi
echo "Evaluating custom playlist over"
echo "Substition in config files"
2019-05-11 16:09:58 +02:00
#Trackmania Files
2019-09-27 11:01:03 +02:00
envsubst < GameData/Config/_config.txt > GameData/Config/config.txt
2019-09-27 11:21:22 +02:00
envsubst < GameData/Tracks/MatchSettings/_playlist.txt > GameData/Tracks/MatchSettings/playlist.txt
2019-09-27 11:01:03 +02:00
exec "./TrackmaniaServer" "/nodaemon" "/internet" "/game_settings=MatchSettings/playlist.txt" "/dedicated_cfg=config.txt"