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
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
# FUNCTIONS
|
2021-11-13 03:17:21 +00:00
|
|
|
function setServerPropValue {
|
2017-11-01 05:42:44 +00:00
|
|
|
local prop=$1
|
2021-11-13 03:17:21 +00:00
|
|
|
local value=$2
|
|
|
|
# normalize booleans
|
|
|
|
case ${value^^} in
|
|
|
|
TRUE|FALSE)
|
|
|
|
value=${value,,} ;;
|
|
|
|
esac
|
2022-08-14 19:14:57 +00:00
|
|
|
if [[ $prop =~ password ]]; then
|
|
|
|
showValue="*****"
|
|
|
|
else
|
|
|
|
showValue="$value"
|
|
|
|
fi
|
2022-09-03 21:48:14 +00:00
|
|
|
if [ -f "$SERVER_PROPERTIES" ] && grep "${prop}" "$SERVER_PROPERTIES" > /dev/null; then
|
2022-08-14 19:14:57 +00:00
|
|
|
debug "Setting ${prop} to '${showValue}' in ${SERVER_PROPERTIES}"
|
2021-11-13 03:17:21 +00:00
|
|
|
sed -i "/^${prop}\s*=/ c ${prop}=${value//\\/\\\\}" "$SERVER_PROPERTIES"
|
2018-01-28 12:16:45 +00:00
|
|
|
else
|
2022-08-14 19:14:57 +00:00
|
|
|
debug "Adding ${prop} with '${showValue}' in ${SERVER_PROPERTIES}"
|
2021-11-13 03:17:21 +00:00
|
|
|
echo "${prop}=${value}" >> "$SERVER_PROPERTIES"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function setServerProp {
|
|
|
|
local prop=$1
|
|
|
|
local varName=$2
|
|
|
|
|
|
|
|
if [ -v $varName ]; then
|
|
|
|
setServerPropValue "$prop" "${!varName}"
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
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"
|
2021-11-13 03:17:21 +00:00
|
|
|
setServerPropValue "white-list" "true"
|
2022-09-03 21:48:14 +00:00
|
|
|
setServerPropValue "enforce-whitelist" "true"
|
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"
|
2021-11-13 03:17:21 +00:00
|
|
|
setServerPropValue "white-list" "false"
|
2022-09-03 21:48:14 +00:00
|
|
|
setServerProp "enforce-whitelist" ENFORCE_WHITELIST
|
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
|
|
|
|
MOTD="{\"text\":\"${MOTD}\"}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-11-13 03:17:21 +00:00
|
|
|
setServerProp "server-name" SERVER_NAME
|
|
|
|
setServerProp "server-ip" SERVER_IP
|
|
|
|
setServerProp "server-port" SERVER_PORT
|
|
|
|
setServerProp "allow-nether" ALLOW_NETHER
|
|
|
|
setServerProp "announce-player-achievements" ANNOUNCE_PLAYER_ACHIEVEMENTS
|
|
|
|
setServerProp "enable-command-block" ENABLE_COMMAND_BLOCK
|
|
|
|
setServerProp "spawn-animals" SPAWN_ANIMALS
|
|
|
|
setServerProp "spawn-monsters" SPAWN_MONSTERS
|
|
|
|
setServerProp "spawn-npcs" SPAWN_NPCS
|
|
|
|
setServerProp "spawn-protection" SPAWN_PROTECTION
|
|
|
|
setServerProp "generate-structures" GENERATE_STRUCTURES
|
|
|
|
setServerProp "view-distance" VIEW_DISTANCE
|
|
|
|
setServerProp "hardcore" HARDCORE
|
|
|
|
setServerProp "snooper-enabled" SNOOPER_ENABLED
|
|
|
|
setServerProp "max-build-height" MAX_BUILD_HEIGHT
|
|
|
|
setServerProp "force-gamemode" FORCE_GAMEMODE
|
|
|
|
setServerProp "max-tick-time" MAX_TICK_TIME
|
|
|
|
setServerProp "enable-query" ENABLE_QUERY
|
|
|
|
setServerProp "query.port" QUERY_PORT
|
|
|
|
setServerProp "enable-rcon" ENABLE_RCON
|
|
|
|
setServerProp "rcon.password" RCON_PASSWORD
|
|
|
|
setServerProp "rcon.port" RCON_PORT
|
|
|
|
setServerProp "max-players" MAX_PLAYERS
|
|
|
|
setServerProp "max-world-size" MAX_WORLD_SIZE
|
|
|
|
setServerProp "level-name" LEVEL
|
|
|
|
setServerProp "level-seed" SEED
|
|
|
|
setServerProp "pvp" PVP
|
|
|
|
setServerProp "generator-settings" GENERATOR_SETTINGS
|
|
|
|
setServerProp "online-mode" ONLINE_MODE
|
|
|
|
setServerProp "allow-flight" ALLOW_FLIGHT
|
|
|
|
setServerProp "resource-pack" RESOURCE_PACK
|
|
|
|
setServerProp "resource-pack-sha1" RESOURCE_PACK_SHA1
|
2021-12-03 01:27:55 +00:00
|
|
|
setServerProp "require-resource-pack" RESOURCE_PACK_ENFORCE
|
2021-11-13 03:17:21 +00:00
|
|
|
setServerProp "player-idle-timeout" PLAYER_IDLE_TIMEOUT
|
|
|
|
setServerProp "broadcast-console-to-ops" BROADCAST_CONSOLE_TO_OPS
|
|
|
|
setServerProp "broadcast-rcon-to-ops" BROADCAST_RCON_TO_OPS
|
|
|
|
setServerProp "enable-jmx-monitoring" ENABLE_JMX
|
|
|
|
setServerProp "sync-chunk-writes" SYNC_CHUNK_WRITES
|
|
|
|
setServerProp "enable-status" ENABLE_STATUS
|
|
|
|
setServerProp "entity-broadcast-range-percentage" ENTITY_BROADCAST_RANGE_PERCENTAGE
|
|
|
|
setServerProp "function-permission-level" FUNCTION_PERMISSION_LEVEL
|
|
|
|
setServerProp "network-compression-threshold" NETWORK_COMPRESSION_THRESHOLD
|
|
|
|
setServerProp "op-permission-level" OP_PERMISSION_LEVEL
|
|
|
|
setServerProp "prevent-proxy-connections" PREVENT_PROXY_CONNECTIONS
|
|
|
|
setServerProp "use-native-transport" USE_NATIVE_TRANSPORT
|
|
|
|
setServerProp "simulation-distance" SIMULATION_DISTANCE
|
2022-06-12 00:31:26 +00:00
|
|
|
setServerProp "previews-chat" PREVIEWS_CHAT
|
|
|
|
setServerProp "enforce-secure-profile" ENFORCE_SECURE_PROFILE
|
2022-10-22 20:30:08 +00:00
|
|
|
setServerProp "initial-enabled-packs" INITIAL_ENABLED_PACKS
|
|
|
|
setServerProp "initial-disabled-packs" INITIAL_DISABLED_PACKS
|
2022-10-13 03:09:56 +00:00
|
|
|
if [[ $MOTD ]]; then
|
|
|
|
setServerPropValue "motd" "$(echo "$MOTD" | mc-image-helper asciify)"
|
|
|
|
fi
|
2021-11-13 03:17:21 +00:00
|
|
|
[[ $LEVEL_TYPE ]] && setServerPropValue "level-type" "${LEVEL_TYPE^^}"
|
2017-11-01 05:42:44 +00:00
|
|
|
|
|
|
|
if [ -n "$DIFFICULTY" ]; then
|
2021-11-13 03:20:53 +00:00
|
|
|
case ${DIFFICULTY,,} in
|
2017-11-01 05:42:44 +00:00
|
|
|
peaceful|0)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
|
|
|
DIFFICULTY=0
|
|
|
|
else
|
|
|
|
DIFFICULTY=peaceful
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
easy|1)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
|
|
|
DIFFICULTY=1
|
|
|
|
else
|
|
|
|
DIFFICULTY=easy
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
normal|2)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
|
|
|
DIFFICULTY=2
|
|
|
|
else
|
|
|
|
DIFFICULTY=normal
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
hard|3)
|
2020-04-22 12:06:57 +00:00
|
|
|
if versionLessThan 1.13; then
|
|
|
|
DIFFICULTY=3
|
|
|
|
else
|
|
|
|
DIFFICULTY=hard
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
*)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "DIFFICULTY must be peaceful, easy, normal, or hard."
|
2017-11-01 05:42:44 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2021-11-13 03:17:21 +00:00
|
|
|
setServerPropValue "difficulty" "$DIFFICULTY"
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$MODE" ]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Setting mode"
|
2021-11-13 03:20:53 +00:00
|
|
|
case ${MODE,,} in
|
2020-04-22 12:06:57 +00:00
|
|
|
su*|0)
|
|
|
|
if versionLessThan 1.13; then
|
|
|
|
MODE=0
|
|
|
|
else
|
|
|
|
MODE=survival
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2020-04-22 12:06:57 +00:00
|
|
|
c*|1)
|
|
|
|
if versionLessThan 1.13; then
|
|
|
|
MODE=1
|
|
|
|
else
|
|
|
|
MODE=creative
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2020-04-22 12:06:57 +00:00
|
|
|
a*|2)
|
|
|
|
if versionLessThan 1.13; then
|
|
|
|
MODE=2
|
|
|
|
else
|
|
|
|
MODE=adventure
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
2020-04-22 12:06:57 +00:00
|
|
|
sp*|3)
|
|
|
|
if versionLessThan 1.13; then
|
|
|
|
MODE=3
|
|
|
|
else
|
|
|
|
MODE=spectator
|
|
|
|
fi
|
2017-11-01 05:42:44 +00:00
|
|
|
;;
|
|
|
|
*)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "ERROR: Invalid game mode: $MODE"
|
2017-11-01 05:42:44 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2021-11-13 03:17:21 +00:00
|
|
|
setServerPropValue "gamemode" "$MODE"
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
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
|
|
|
|
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
|
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" "$@"
|