diff --git a/start-finalSetupEnvVariables b/start-finalSetupEnvVariables index ab8d13c8..cfb36413 100644 --- a/start-finalSetupEnvVariables +++ b/start-finalSetupEnvVariables @@ -5,7 +5,7 @@ : ${ENV_VARIABLE_PREFIX:=CFG_} if isTrue "${REPLACE_ENV_VARIABLES}"; then - log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..." + log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX ..." # File excludes fileExcludes= @@ -22,28 +22,27 @@ if isTrue "${REPLACE_ENV_VARIABLES}"; then isDebugging && echo "Using find file exclusions: $fileExcludes" isDebugging && echo "Using find directory exclusions: $dirExcludes" - while IFS='=' read -r name value ; do + for name in $(compgen -v $ENV_VARIABLE_PREFIX); do # check if name of env variable matches the prefix # sanity check environment variables to avoid code injections - if [[ "$name" = $ENV_VARIABLE_PREFIX* ]] \ - && [[ $value =~ ^[0-9a-zA-Z_:/=?.+\-]*$ ]] \ - && [[ $name =~ ^[0-9a-zA-Z_\-]*$ ]]; then - # Read content from file environment - if [[ $name = *"_FILE" ]] && [[ -f $value ]]; then - name="${name/_FILE/}" - value=$(<$value) - fi - - log "Replacing $name with $value ..." - find /data/ \ - $dirExcludes \ - -type f \ - \( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \ - -or -name "*.conf" -or -name "*.properties" \) \ - $fileExcludes \ - -exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \; + # Read content from file environment + if [[ $name = *"_FILE" ]]; then + value=$(<${!name}) + name="${name%_FILE}" + else + value=${!name} fi - done < <(env) + + log "Replacing $name with $value ..." + find /data/ \ + $dirExcludes \ + -type f \ + \( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \ + -or -name "*.conf" -or -name "*.properties" \) \ + $fileExcludes \ + -exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \; + done fi -exec ${SCRIPTS:-/}start-minecraftFinalSetup $@ +#DO NOT COMMIT +#exec ${SCRIPTS:-/}start-minecraftFinalSetup $@