docker-minecraft-server/start-configuration

183 lines
4.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2020-03-06 15:52:17 +00:00
. /start-utils
shopt -s nullglob
#umask 002
export HOME=/data
if [ ! -e /data/eula.txt ]; then
EULA="${EULA,,}"
if [ "$EULA" != "true" ]; then
2020-03-06 15:52:17 +00:00
log ""
log "Please accept the Minecraft EULA at"
log " https://account.mojang.com/documents/minecraft_eula"
log "by adding the following immediately after 'docker run':"
log " -e EULA=TRUE"
log ""
exit 1
fi
echo "# Generated via Docker on $(date)" > /data/eula.txt
2020-04-12 19:31:19 +00:00
if ! echo "eula=$EULA" >> /data/eula.txt; then
2020-03-06 15:52:17 +00:00
log "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}"
exit 2
fi
fi
2020-03-06 15:52:17 +00:00
log "Running as uid=$(id -u) gid=$(id -g) with /data as '$(ls -lnd /data)'"
if ! touch /data/.verify_access; then
2020-03-06 15:52:17 +00:00
log "ERROR: /data doesn't seem to be writable. Please make sure attached directory is writable by uid=$(id -u)"
exit 2
fi
rm /data/.verify_access || true
if [[ $PROXY ]]; then
export http_proxy="$PROXY"
export https_proxy="$PROXY"
2020-03-06 15:52:17 +00:00
log "INFO: Giving proxy time to startup..."
sleep 5
fi
export SERVER_PROPERTIES=/data/server.properties
export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json
case "X$VERSION" in
X|XLATEST|Xlatest)
2020-04-12 19:31:19 +00:00
VANILLA_VERSION=$(curl -fsSL $VERSIONS_JSON | jq -r '.latest.release')
;;
XSNAPSHOT|Xsnapshot)
2020-04-12 19:31:19 +00:00
VANILLA_VERSION=$(curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot')
;;
X[1-9]*)
2020-04-12 19:31:19 +00:00
VANILLA_VERSION=$VERSION
;;
*)
2020-04-12 19:31:19 +00:00
VANILLA_VERSION=$(curl -fsSL $VERSIONS_JSON | jq -r '.latest.release')
;;
esac
2020-04-12 19:31:19 +00:00
export VANILLA_VERSION
log "Resolved version given ${VERSION} into ${VANILLA_VERSION}"
2020-04-12 19:31:19 +00:00
cd /data || exit 1
export ORIGINAL_TYPE=${TYPE^^}
2020-05-20 13:17:58 +00:00
if isTrue "${ENABLE_AUTOPAUSE}"; then
log "Autopause functionality enabled"
# update server port to listen to
regseq="^\s*sequence\s*=\s*$SERVER_PORT\s*$"
linenum=$(grep -nm1 sequence /autopause/knockd-config.cfg | cut -d : -f 1 | tail -n1)
if ! [[ $(awk "NR==$linenum" /autopause/knockd-config.cfg) =~ $regseq ]]; then
sed -i "${linenum}s/sequence.*/sequence = $SERVER_PORT/" /autopause/knockd-config.cfg
log "Updated server port in knockd config"
fi
# update rcon port to listen to
regseq="^\s*sequence\s*=\s*$RCON_PORT\s*$"
linenum=$(grep -nm2 sequence /autopause/knockd-config.cfg | cut -d : -f 1 | tail -n1)
if ! [[ $(awk "NR==$linenum" /autopause/knockd-config.cfg) =~ $regseq ]]; then
sed -i "${linenum}s/sequence.*/sequence = $RCON_PORT/" /autopause/knockd-config.cfg
log "Updated rcon port in knockd config"
fi
if ! [[ $AUTOPAUSE_PERIOD =~ ^[0-9]+$ ]]; then
AUTOPAUSE_PERIOD=10
export AUTOPAUSE_PERIOD
log "Warning: AUTOPAUSE_PERIOD is not numeric, set to 10 (seconds)"
fi
if [ "$AUTOPAUSE_PERIOD" -eq "0" ] ; then
AUTOPAUSE_PERIOD=10
export AUTOPAUSE_PERIOD
log "Warning: AUTOPAUSE_PERIOD must not be 0, set to 10 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_KN =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_KN=120
export AUTOPAUSE_TIMEOUT_KN
log "Warning: AUTOPAUSE_TIMEOUT_KN is not numeric, set to 120 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_EST =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_EST=3600
export AUTOPAUSE_TIMEOUT_EST
log "Warning: AUTOPAUSE_TIMEOUT_EST is not numeric, set to 3600 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_INIT =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_INIT=600
export AUTOPAUSE_TIMEOUT_INIT
log "Warning: AUTOPAUSE_TIMEOUT_INIT is not numeric, set to 600 (seconds)"
fi
if [[ -n $MAX_TICK_TIME ]] ; then
log "Warning: MAX_TICK_TIME is non-default, for autopause to work properly, this check should be disabled (-1 for versions >= 1.8.1)"
else
if versionLessThan 1.8.1; then
# 10 years
MAX_TICK_TIME=315360000000
else
MAX_TICK_TIME=-1
fi
export MAX_TICK_TIME
fi
/autopause/autopause-daemon.sh &
fi
log "Resolving type given ${TYPE}"
case "${TYPE^^}" in
*BUKKIT|SPIGOT)
2020-04-12 19:31:19 +00:00
exec /start-deployBukkitSpigot "$@"
;;
PAPER)
2020-04-12 19:31:19 +00:00
exec /start-deployPaper "$@"
;;
2020-04-25 00:13:51 +00:00
TUINITY)
exec /start-deployTuinity "$@"
2020-04-24 23:56:15 +00:00
;;
FORGE)
2020-04-12 19:31:19 +00:00
exec /start-deployForge "$@"
;;
2019-07-10 03:19:59 +00:00
FABRIC)
2020-04-12 19:31:19 +00:00
exec /start-deployFabric "$@"
2019-07-10 03:19:59 +00:00
;;
FTB|CURSEFORGE)
2020-04-12 19:31:19 +00:00
exec /start-deployFTB "$@"
;;
VANILLA)
2020-04-12 19:31:19 +00:00
exec /start-deployVanilla "$@"
;;
SPONGEVANILLA)
2020-04-12 19:31:19 +00:00
exec /start-deploySpongeVanilla "$@"
;;
CUSTOM)
2020-04-12 19:31:19 +00:00
exec /start-deployCustom "$@"
;;
CURSE_INSTANCE)
exec /start-validateCurseInstance "$@"
;;
MAGMA)
exec /start-magma "$@"
;;
*)
2020-03-06 15:52:17 +00:00
log "Invalid type: '$TYPE'"
log "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FTB, CURSEFORGE, SPONGEVANILLA"
exit 1
;;
esac