docker-minecraft-server/scripts/start-setupServerProperties

187 lines
4.9 KiB
Text
Raw Normal View History

2017-11-01 05:42:44 +00:00
#!/bin/bash
# shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
2020-03-06 15:52:17 +00:00
: "${SERVER_PROPERTIES:=/data/server.properties}"
: "${OVERRIDE_SERVER_PROPERTIES:=true}"
: "${SKIP_SERVER_PROPERTIES:=false}"
: "${ENABLE_WHITELIST:=}"
function customizeServerProps {
local firstSetup=$1
# Whitelist processing
if [ -n "$WHITELIST" ] || [ -n "$WHITELIST_FILE" ] || isTrue "${ENABLE_WHITELIST}"; then
log "Enabling whitelist functionality"
WHITELIST_PROP=true
ENFORCE_WHITELIST=true
export WHITELIST_PROP ENFORCE_WHITELIST
elif isTrue "$firstSetup" || isFalse "${ENABLE_WHITELIST}"; then
log "Disabling whitelist functionality"
WHITELIST_PROP=false
export WHITELIST_PROP
fi
2017-11-01 05:42:44 +00:00
# normalize MOTD
if [[ ${TYPE^^} = LIMBO ]]; then
if [[ $MOTD ]] && ! [[ $MOTD =~ ^{ ]]; then
# shellcheck disable=SC2089
MOTD="{\"text\":\"${MOTD}\"}"
fi
fi
2017-11-01 05:42:44 +00:00
if [[ -v MODE ]]; then
log "Setting mode"
case ${MODE,,} in
su*|0)
if versionLessThan 1.13; then
MODE=0
else
MODE=survival
fi
2017-11-01 05:42:44 +00:00
;;
c*|1)
if versionLessThan 1.13; then
MODE=1
else
MODE=creative
fi
2017-11-01 05:42:44 +00:00
;;
a*|2)
if versionLessThan 1.13; then
MODE=2
else
MODE=adventure
fi
2017-11-01 05:42:44 +00:00
;;
sp*|3)
if versionLessThan 1.13; then
MODE=3
else
MODE=spectator
fi
2017-11-01 05:42:44 +00:00
;;
*)
log "ERROR: Invalid game mode: $MODE"
2017-11-01 05:42:44 +00:00
exit 1
;;
esac
fi
if [[ -v DIFFICULTY ]]; then
case ${DIFFICULTY,,} in
peaceful|0)
if versionLessThan 1.13; then
DIFFICULTY=0
else
DIFFICULTY=peaceful
fi
2017-11-01 05:42:44 +00:00
;;
easy|1)
if versionLessThan 1.13; then
DIFFICULTY=1
else
DIFFICULTY=easy
fi
2017-11-01 05:42:44 +00:00
;;
normal|2)
if versionLessThan 1.13; then
DIFFICULTY=2
else
DIFFICULTY=normal
fi
2017-11-01 05:42:44 +00:00
;;
hard|3)
if versionLessThan 1.13; then
DIFFICULTY=3
else
DIFFICULTY=hard
fi
2017-11-01 05:42:44 +00:00
;;
*)
log "DIFFICULTY must be peaceful, easy, normal, or hard."
2017-11-01 05:42:44 +00:00
exit 1
;;
esac
fi
if [[ -v LEVEL_TYPE ]]; then
LEVEL_TYPE="${LEVEL_TYPE^^}"
fi
setPropertiesArgs=(
--definitions "/image/property-definitions.json"
)
if [[ -v CUSTOM_SERVER_PROPERTIES ]]; then
setPropertiesArgs+=(--custom-properties "$CUSTOM_SERVER_PROPERTIES")
fi
if [[ -v SERVER_PROPERTIES_ESCAPE_UNICODE ]]; then
if isTrue "$SERVER_PROPERTIES_ESCAPE_UNICODE"; then
setPropertiesArgs+=(--escape-unicode)
fi
elif versionLessThan '1.20'; then
setPropertiesArgs+=(--escape-unicode)
fi
handleDebugMode
if ! mc-image-helper set-properties "${setPropertiesArgs[@]}" "$SERVER_PROPERTIES"; then
log "ERROR: failed to update server.properties"
exit 1
fi
}
# Deploy server.properties file
if [[ ${TYPE} == "CURSEFORGE" ]]; then
export SERVER_PROPERTIES="${FTB_DIR}/server.properties"
2020-03-06 15:52:17 +00:00
log "detected FTB, changing properties path to ${SERVER_PROPERTIES}"
fi
if ! isTrue "${SKIP_SERVER_PROPERTIES}"; then
if [ ! -e "$SERVER_PROPERTIES" ]; then
log "Creating server properties in ${SERVER_PROPERTIES}"
# If not provided, generate a reasonable default message-of-the-day,
# which shows up in the server listing in the client
if ! [ -v MOTD ]; then
# snapshot is the odd case where we have to look at version to identify that label
if [[ ${ORIGINAL_TYPE} == "VANILLA" && ${VERSION} == "SNAPSHOT" ]]; then
label=SNAPSHOT
else
label=${ORIGINAL_TYPE}
fi
# Convert label to title-case
label=${label,,}
label=${label^}
MOTD="A ${label} Minecraft Server powered by Docker"
fi
customizeServerProps true
elif isTrue "${OVERRIDE_SERVER_PROPERTIES}"; then
customizeServerProps false
else
log "server.properties already created and managed manually"
fi
else
log "Skipping setup of server.properties"
2017-11-01 05:42:44 +00:00
fi
2020-05-20 13:17:58 +00:00
if isTrue "${ENABLE_AUTOPAUSE}"; then
if [ -f "$SERVER_PROPERTIES" ]; then
current_max_tick=$( grep 'max-tick-time' "$SERVER_PROPERTIES" | sed -r 's/( )+//g' | awk -F= '{print $2}' )
if (( current_max_tick > 0 && current_max_tick < 86400000 )); then
log "Warning: The server.properties for the server doesn't have the Server Watchdog (effectively) disabled."
log " Autopause functionality resuming the process might trigger the Watchdog and restart the server completely."
log " Set the MAX_TICK_TIME env variable (or max-tick-time property) to a high value (or disable the Watchdog with value -1 for versions 1.8.1+)."
fi
2020-05-20 13:17:58 +00:00
fi
fi
if isTrue "${DUMP_SERVER_PROPERTIES:-false}"; then
log "DEBUG Dumping server.properties"
cat "${SERVER_PROPERTIES}"
fi
exec "${SCRIPTS:-/}start-setupEnvVariables" "$@"