2017-11-01 05:42:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-11-13 03:17:21 +00:00
|
|
|
# shellcheck source=start-utils
|
|
|
|
. "${SCRIPTS:-/}start-utils"
|
2020-03-06 15:52:17 +00:00
|
|
|
|
2021-11-13 03:17:21 +00:00
|
|
|
: "${SERVER_PROPERTIES:=/data/server.properties}"
|
2022-10-08 23:11:43 +00:00
|
|
|
: "${OVERRIDE_SERVER_PROPERTIES:=true}"
|
|
|
|
: "${SKIP_SERVER_PROPERTIES:=false}"
|
2022-10-13 03:09:56 +00:00
|
|
|
: "${ENABLE_WHITELIST:=}"
|
2021-02-21 20:32:41 +00:00
|
|
|
|
2019-04-03 20:23:19 +00:00
|
|
|
function customizeServerProps {
|
2022-10-13 03:09:56 +00:00
|
|
|
local firstSetup=$1
|
2021-12-11 22:08:53 +00:00
|
|
|
# Whitelist processing
|
2022-10-13 03:09:56 +00:00
|
|
|
if [ -n "$WHITELIST" ] || [ -n "$WHITELIST_FILE" ] || isTrue "${ENABLE_WHITELIST}"; then
|
2021-12-11 22:08:53 +00:00
|
|
|
log "Enabling whitelist functionality"
|
2023-10-07 18:26:27 +00:00
|
|
|
WHITELIST_PROP=true
|
|
|
|
ENFORCE_WHITELIST=true
|
|
|
|
export WHITELIST_PROP ENFORCE_WHITELIST
|
2022-10-13 03:09:56 +00:00
|
|
|
elif isTrue "$firstSetup" || isFalse "${ENABLE_WHITELIST}"; then
|
2021-12-11 22:08:53 +00:00
|
|
|
log "Disabling whitelist functionality"
|
2023-10-07 18:26:27 +00:00
|
|
|
WHITELIST_PROP=false
|
|
|
|
export WHITELIST_PROP
|
2021-12-11 22:08:53 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2022-01-08 00:32:10 +00:00
|
|
|
# normalize MOTD
|
|
|
|
if [[ ${TYPE^^} = LIMBO ]]; then
|
|
|
|
if [[ $MOTD ]] && ! [[ $MOTD =~ ^{ ]]; then
|
2023-11-11 20:05:00 +00:00
|
|
|
# shellcheck disable=SC2089
|
2022-01-08 00:32:10 +00:00
|
|
|
MOTD="{\"text\":\"${MOTD}\"}"
|
|
|
|
fi
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2023-10-07 18:26:27 +00:00
|
|
|
if [[ -v MODE ]]; then
|
|
|
|
log "Setting mode"
|
|
|
|
case ${MODE,,} in
|
|
|
|
su*|0)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
2023-10-07 18:26:27 +00:00
|
|
|
MODE=0
|
2020-04-22 12:06:57 +00:00
|
|
|
else
|
2023-10-07 18:26:27 +00:00
|
|
|
MODE=survival
|
2020-04-22 12:06:57 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2023-10-07 18:26:27 +00:00
|
|
|
c*|1)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
2023-10-07 18:26:27 +00:00
|
|
|
MODE=1
|
2020-04-22 12:06:57 +00:00
|
|
|
else
|
2023-10-07 18:26:27 +00:00
|
|
|
MODE=creative
|
2020-04-22 12:06:57 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2023-10-07 18:26:27 +00:00
|
|
|
a*|2)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
2023-10-07 18:26:27 +00:00
|
|
|
MODE=2
|
2020-04-22 12:06:57 +00:00
|
|
|
else
|
2023-10-07 18:26:27 +00:00
|
|
|
MODE=adventure
|
2020-04-22 12:06:57 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2023-10-07 18:26:27 +00:00
|
|
|
sp*|3)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
2023-10-07 18:26:27 +00:00
|
|
|
MODE=3
|
2020-04-22 12:06:57 +00:00
|
|
|
else
|
2023-10-07 18:26:27 +00:00
|
|
|
MODE=spectator
|
2020-04-22 12:06:57 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
*)
|
2023-10-07 18:26:27 +00:00
|
|
|
log "ERROR: Invalid game mode: $MODE"
|
2017-11-01 05:42:44 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2023-10-07 18:26:27 +00:00
|
|
|
if [[ -v DIFFICULTY ]]; then
|
|
|
|
case ${DIFFICULTY,,} in
|
|
|
|
peaceful|0)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
2023-10-07 18:26:27 +00:00
|
|
|
DIFFICULTY=0
|
2020-04-22 12:06:57 +00:00
|
|
|
else
|
2023-10-07 18:26:27 +00:00
|
|
|
DIFFICULTY=peaceful
|
2020-04-22 12:06:57 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2023-10-07 18:26:27 +00:00
|
|
|
easy|1)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
2023-10-07 18:26:27 +00:00
|
|
|
DIFFICULTY=1
|
2020-04-22 12:06:57 +00:00
|
|
|
else
|
2023-10-07 18:26:27 +00:00
|
|
|
DIFFICULTY=easy
|
2020-04-22 12:06:57 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2023-10-07 18:26:27 +00:00
|
|
|
normal|2)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
2023-10-07 18:26:27 +00:00
|
|
|
DIFFICULTY=2
|
2020-04-22 12:06:57 +00:00
|
|
|
else
|
2023-10-07 18:26:27 +00:00
|
|
|
DIFFICULTY=normal
|
2020-04-22 12:06:57 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2023-10-07 18:26:27 +00:00
|
|
|
hard|3)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
2023-10-07 18:26:27 +00:00
|
|
|
DIFFICULTY=3
|
2020-04-22 12:06:57 +00:00
|
|
|
else
|
2023-10-07 18:26:27 +00:00
|
|
|
DIFFICULTY=hard
|
2020-04-22 12:06:57 +00:00
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
*)
|
2023-10-07 18:26:27 +00:00
|
|
|
log "DIFFICULTY must be peaceful, easy, normal, or hard."
|
2017-11-01 05:42:44 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2023-10-07 18:26:27 +00:00
|
|
|
|
|
|
|
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
|
2023-11-11 20:05:00 +00:00
|
|
|
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
|
2023-10-07 18:26:27 +00:00
|
|
|
|
2023-11-11 04:16:51 +00:00
|
|
|
handleDebugMode
|
2023-11-02 00:08:31 +00:00
|
|
|
if ! mc-image-helper set-properties "${setPropertiesArgs[@]}" "$SERVER_PROPERTIES"; then
|
|
|
|
log "ERROR: failed to update server.properties"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-10-07 18:26:27 +00:00
|
|
|
|
2019-04-03 20:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Deploy server.properties file
|
2021-04-26 13:19:50 +00:00
|
|
|
if [[ ${TYPE} == "CURSEFORGE" ]]; then
|
2021-04-24 02:01:50 +00:00
|
|
|
export SERVER_PROPERTIES="${FTB_DIR}/server.properties"
|
2020-03-06 15:52:17 +00:00
|
|
|
log "detected FTB, changing properties path to ${SERVER_PROPERTIES}"
|
2019-04-03 20:23:19 +00:00
|
|
|
fi
|
|
|
|
|
2022-10-08 23:11:43 +00:00
|
|
|
if ! isTrue "${SKIP_SERVER_PROPERTIES}"; then
|
2021-11-05 01:55:15 +00:00
|
|
|
if [ ! -e "$SERVER_PROPERTIES" ]; then
|
2022-08-14 19:14:57 +00:00
|
|
|
log "Creating server properties in ${SERVER_PROPERTIES}"
|
2022-10-13 03:09:56 +00:00
|
|
|
|
|
|
|
# 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
|
2023-11-12 22:10:03 +00:00
|
|
|
if [[ ${DECLARED_TYPE} == "VANILLA" && ${VERSION} == "SNAPSHOT" ]]; then
|
2022-10-13 03:09:56 +00:00
|
|
|
label=SNAPSHOT
|
|
|
|
else
|
2023-11-12 22:10:03 +00:00
|
|
|
label=${DECLARED_TYPE}
|
2022-10-13 03:09:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Convert label to title-case
|
|
|
|
label=${label,,}
|
|
|
|
label=${label^}
|
|
|
|
MOTD="A ${label} Minecraft Server powered by Docker"
|
|
|
|
fi
|
|
|
|
|
|
|
|
customizeServerProps true
|
2022-10-08 23:11:43 +00:00
|
|
|
elif isTrue "${OVERRIDE_SERVER_PROPERTIES}"; then
|
2022-10-13 03:09:56 +00:00
|
|
|
customizeServerProps false
|
2021-11-05 01:55:15 +00:00
|
|
|
else
|
2022-10-08 23:11:43 +00:00
|
|
|
log "server.properties already created and managed manually"
|
2021-11-05 01:55:15 +00:00
|
|
|
fi
|
2018-01-28 13:45:25 +00:00
|
|
|
else
|
2021-11-05 01:55:15 +00:00
|
|
|
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
|
2022-09-03 21:48:14 +00:00
|
|
|
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
|
|
|
|
|
2022-08-14 19:14:57 +00:00
|
|
|
if isTrue "${DUMP_SERVER_PROPERTIES:-false}"; then
|
2020-06-14 16:14:11 +00:00
|
|
|
log "DEBUG Dumping server.properties"
|
2021-04-24 02:01:50 +00:00
|
|
|
cat "${SERVER_PROPERTIES}"
|
2020-06-14 16:14:11 +00:00
|
|
|
fi
|
|
|
|
|
2021-11-05 02:49:03 +00:00
|
|
|
exec "${SCRIPTS:-/}start-setupEnvVariables" "$@"
|