Improved handling of ENV_VARIABLE_PREFIX

#718
This commit is contained in:
Geoff Bourne 2021-02-20 17:30:50 -06:00
parent 92a15ea85d
commit c056b9d2dd

View File

@ -22,16 +22,15 @@ 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)
if [[ $name = *"_FILE" ]]; then
value=$(<${!name})
name="${name%_FILE}"
else
value=${!name}
fi
log "Replacing $name with $value ..."
@ -42,8 +41,8 @@ if isTrue "${REPLACE_ENV_VARIABLES}"; then
-or -name "*.conf" -or -name "*.properties" \) \
$fileExcludes \
-exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \;
fi
done < <(env)
done
fi
exec ${SCRIPTS:-/}start-minecraftFinalSetup $@
#DO NOT COMMIT
#exec ${SCRIPTS:-/}start-minecraftFinalSetup $@