2019-03-23 13:12:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-06-19 16:05:32 +00:00
|
|
|
. ${SCRIPTS:-/}start-utils
|
2020-03-06 15:52:17 +00:00
|
|
|
|
2020-07-06 21:41:56 +00:00
|
|
|
: ${ENV_VARIABLE_PREFIX:=CFG_}
|
|
|
|
|
|
|
|
if isTrue "${REPLACE_ENV_VARIABLES}"; then
|
2021-02-20 23:30:50 +00:00
|
|
|
log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX ..."
|
2020-07-18 23:31:29 +00:00
|
|
|
|
|
|
|
# File excludes
|
2020-07-26 13:20:11 +00:00
|
|
|
fileExcludes=
|
2020-07-06 21:41:56 +00:00
|
|
|
for f in ${REPLACE_ENV_VARIABLES_EXCLUDES}; do
|
2020-07-26 13:20:11 +00:00
|
|
|
fileExcludes="${fileExcludes} -not -name $f"
|
2020-07-06 21:41:56 +00:00
|
|
|
done
|
2020-07-18 23:31:29 +00:00
|
|
|
|
|
|
|
# Directory excludes (recursive)
|
|
|
|
dirExcludes=$(join_by " -o -path " ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS})
|
|
|
|
if [[ $dirExcludes ]]; then
|
2020-07-26 13:20:11 +00:00
|
|
|
dirExcludes=" -type d ( -path ${dirExcludes} ) -prune -o"
|
2020-07-18 23:31:29 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-26 13:20:11 +00:00
|
|
|
isDebugging && echo "Using find file exclusions: $fileExcludes"
|
|
|
|
isDebugging && echo "Using find directory exclusions: $dirExcludes"
|
2020-07-06 21:41:56 +00:00
|
|
|
|
2021-02-20 23:30:50 +00:00
|
|
|
for name in $(compgen -v $ENV_VARIABLE_PREFIX); do
|
2019-03-23 13:12:58 +00:00
|
|
|
# check if name of env variable matches the prefix
|
|
|
|
# sanity check environment variables to avoid code injections
|
2021-02-20 23:30:50 +00:00
|
|
|
# Read content from file environment
|
|
|
|
if [[ $name = *"_FILE" ]]; then
|
|
|
|
value=$(<${!name})
|
|
|
|
name="${name%_FILE}"
|
|
|
|
else
|
|
|
|
value=${!name}
|
2019-03-23 13:12:58 +00:00
|
|
|
fi
|
2021-02-20 23:30:50 +00:00
|
|
|
|
|
|
|
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
|
2019-03-23 13:12:58 +00:00
|
|
|
fi
|
|
|
|
|
2021-02-20 23:35:26 +00:00
|
|
|
exec ${SCRIPTS:-/}start-minecraftFinalSetup $@
|