From d495ace3e5a61bf49a53a5227d817c5f79a5f51b Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Wed, 12 Oct 2022 21:53:43 -0500 Subject: [PATCH] Only default MOTD and WHITELIST when first creating server.properties --- scripts/start-configuration | 3 +- scripts/start-setupServerProperties | 48 ++++++++++++++++------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/scripts/start-configuration b/scripts/start-configuration index 9f9ab7b98da..8fc00414402 100755 --- a/scripts/start-configuration +++ b/scripts/start-configuration @@ -16,9 +16,10 @@ IFS=$'\n\t' : "${RCON_CMDS_LAST_DISCONNECT:=}" : "${RCON_CMDS_PERIOD:=10}" : "${RCON_PASSWORD_FILE:=}" +: "${ENABLE_RCON:=true}" : "${RCON_PASSWORD:=minecraft}" : "${RCON_PORT:=25575}" -export RCON_PASSWORD RCON_PORT +export ENABLE_RCON RCON_PASSWORD RCON_PORT : "${MEMORY=1G}" : "${INIT_MEMORY=${MEMORY}}" diff --git a/scripts/start-setupServerProperties b/scripts/start-setupServerProperties index 427f7390b36..9e3310772c1 100755 --- a/scripts/start-setupServerProperties +++ b/scripts/start-setupServerProperties @@ -4,9 +4,9 @@ . "${SCRIPTS:-/}start-utils" : "${SERVER_PROPERTIES:=/data/server.properties}" -: "${ENABLE_RCON:=true}" : "${OVERRIDE_SERVER_PROPERTIES:=true}" : "${SKIP_SERVER_PROPERTIES:=false}" +: "${ENABLE_WHITELIST:=}" # FUNCTIONS function setServerPropValue { @@ -41,33 +41,18 @@ function setServerProp { } function customizeServerProps { + local firstSetup=$1 # Whitelist processing - if [ -n "$WHITELIST" ] || [ -n "$WHITELIST_FILE" ] || isTrue "${ENABLE_WHITELIST:-false}"; then + if [ -n "$WHITELIST" ] || [ -n "$WHITELIST_FILE" ] || isTrue "${ENABLE_WHITELIST}"; then log "Enabling whitelist functionality" setServerPropValue "white-list" "true" setServerPropValue "enforce-whitelist" "true" - else + elif isTrue "$firstSetup" || isFalse "${ENABLE_WHITELIST}"; then log "Disabling whitelist functionality" setServerPropValue "white-list" "false" setServerProp "enforce-whitelist" ENFORCE_WHITELIST fi - # 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 - # normalize MOTD if [[ ${TYPE^^} = LIMBO ]]; then if [[ $MOTD ]] && ! [[ $MOTD =~ ^{ ]]; then @@ -123,7 +108,9 @@ function customizeServerProps { setServerProp "simulation-distance" SIMULATION_DISTANCE setServerProp "previews-chat" PREVIEWS_CHAT setServerProp "enforce-secure-profile" ENFORCE_SECURE_PROFILE - setServerPropValue "motd" "$(echo "$MOTD" | mc-image-helper asciify)" + if [[ $MOTD ]]; then + setServerPropValue "motd" "$(echo "$MOTD" | mc-image-helper asciify)" + fi [[ $LEVEL_TYPE ]] && setServerPropValue "level-type" "${LEVEL_TYPE^^}" if [ -n "$DIFFICULTY" ]; then @@ -213,9 +200,26 @@ fi if ! isTrue "${SKIP_SERVER_PROPERTIES}"; then if [ ! -e "$SERVER_PROPERTIES" ]; then log "Creating server properties in ${SERVER_PROPERTIES}" - customizeServerProps + + # 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 + customizeServerProps false else log "server.properties already created and managed manually" fi