diff --git a/Dockerfile b/Dockerfile index 8b0ec782..eddce74a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,7 +71,6 @@ ENV UID=1000 GID=1000 \ TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED SPONGEBRANCH=STABLE SPONGEVERSION= FABRICVERSION=LATEST LEVEL=world \ PVP=true DIFFICULTY=easy ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \ LEVEL_TYPE=DEFAULT SERVER_PORT=25565 ONLINE_MODE=TRUE SERVER_NAME="Dedicated Server" \ - REPLACE_ENV_VARIABLES="FALSE" ENV_VARIABLE_PREFIX="CFG_" \ ENABLE_AUTOPAUSE=false AUTOPAUSE_TIMEOUT_EST=3600 AUTOPAUSE_TIMEOUT_KN=120 AUTOPAUSE_TIMEOUT_INIT=600 AUTOPAUSE_PERIOD=10 COPY start* / diff --git a/README.md b/README.md index b17fcece..9ed143ac 100644 --- a/README.md +++ b/README.md @@ -306,7 +306,7 @@ defined environment variables. Variables that you want to replace need to be wra inside `${YOUR_VARIABLE}` curly brackets and prefixed with a dollar sign. This is the regular syntax for enviromment variables inside strings or config files. -Optionally you can also define a prefix to only match predefined enviroment variables. +Optionally you can also define a prefix to only match predefined environment variables. `ENV_VARIABLE_PREFIX="CFG_"` <-- this is the default prefix @@ -322,6 +322,8 @@ There are some limitations to what characters you can use. Variables will be replaced in files with the following extensions: `.yml`, `.yaml`, `.txt`, `.cfg`, `.conf`, `.properties`. +Specific files can be excluded by listing their name (without path) in the variable `REPLACE_ENV_VARIABLES_EXCLUDES`. + Here is a full example where we want to replace values inside a `database.yml`. ```yml diff --git a/start-finalSetup05EnvVariables b/start-finalSetup05EnvVariables index 3df6b5a2..4ec1b7ee 100644 --- a/start-finalSetup05EnvVariables +++ b/start-finalSetup05EnvVariables @@ -2,8 +2,17 @@ . ${SCRIPTS:-/}start-utils -if [ "${REPLACE_ENV_VARIABLES^^}" = "TRUE" ]; then +: ${ENV_VARIABLE_PREFIX:=CFG_} + +if isTrue "${REPLACE_ENV_VARIABLES}"; then log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..." + + findExcludes= + for f in ${REPLACE_ENV_VARIABLES_EXCLUDES}; do + findExcludes="${findExcludes} -not -name $f" + done + isDebugging && echo "Using find exclusion: $findExcludes" + while IFS='=' read -r name value ; do # check if name of env variable matches the prefix # sanity check environment variables to avoid code injections @@ -20,6 +29,7 @@ if [ "${REPLACE_ENV_VARIABLES^^}" = "TRUE" ]; then find /data/ -type f \ \( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \ -or -name "*.conf" -or -name "*.properties" \) \ + $findExcludes \ -exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \; fi done < <(env)