Add missing server.properties when needed

#776
This commit is contained in:
Geoff Bourne 2021-02-21 14:32:41 -06:00
parent 0cbfb81b4c
commit fa53abdfb7
2 changed files with 9 additions and 3 deletions

View file

@ -61,7 +61,6 @@ if [[ $RCON_PASSWORD_FILE ]]; then
log ""
fi
export SERVER_PROPERTIES=/data/server.properties
export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json
case "X$VERSION" in

View file

@ -2,6 +2,8 @@
. ${SCRIPTS:-/}start-utils
: ${SERVER_PROPERTIES:=/data/server.properties}
# FUNCTIONS
function setServerProp {
local prop=$1
@ -12,8 +14,13 @@ function setServerProp {
TRUE|FALSE)
var=${var,,} ;;
esac
log "Setting ${prop} to '${var}' in ${SERVER_PROPERTIES}"
sed -i "/^${prop}\s*=/ c ${prop}=${var//\\/\\\\}" "$SERVER_PROPERTIES"
if grep "${prop}" "$SERVER_PROPERTIES" > /dev/null; then
log "Setting ${prop} to '${var}' in ${SERVER_PROPERTIES}"
sed -i "/^${prop}\s*=/ c ${prop}=${var//\\/\\\\}" "$SERVER_PROPERTIES"
else
log "Adding ${prop} with '${var}' in ${SERVER_PROPERTIES}"
echo "${prop}=${var//\\/\\\\}" >> "$SERVER_PROPERTIES"
fi
else
log "Skip setting ${prop}"
fi