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
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..."
|
2020-07-06 21:41:56 +00:00
|
|
|
|
|
|
|
findExcludes=
|
|
|
|
for f in ${REPLACE_ENV_VARIABLES_EXCLUDES}; do
|
|
|
|
findExcludes="${findExcludes} -not -name $f"
|
|
|
|
done
|
2020-07-10 02:05:17 +00:00
|
|
|
for p in ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}; do
|
|
|
|
findExcludes="${findExcludes} -not -path \"*$p*\""
|
|
|
|
done
|
2020-07-06 21:41:56 +00:00
|
|
|
isDebugging && echo "Using find exclusion: $findExcludes"
|
|
|
|
|
2019-03-23 13:12:58 +00:00
|
|
|
while IFS='=' read -r name value ; do
|
|
|
|
# check if name of env variable matches the prefix
|
|
|
|
# sanity check environment variables to avoid code injections
|
2019-09-24 15:22:00 +00:00
|
|
|
if [[ "$name" = $ENV_VARIABLE_PREFIX* ]] \
|
|
|
|
&& [[ $value =~ ^[0-9a-zA-Z_:/=?.+\-]*$ ]] \
|
|
|
|
&& [[ $name =~ ^[0-9a-zA-Z_\-]*$ ]]; then
|
2020-04-29 00:07:45 +00:00
|
|
|
# Read content from file environment
|
|
|
|
if [[ $name = *"_FILE" ]] && [[ -f $value ]]; then
|
|
|
|
name="${name/_FILE/}"
|
|
|
|
value=$(<$value)
|
|
|
|
fi
|
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Replacing $name with $value ..."
|
2019-09-24 15:22:00 +00:00
|
|
|
find /data/ -type f \
|
|
|
|
\( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \
|
|
|
|
-or -name "*.conf" -or -name "*.properties" \) \
|
2020-07-06 21:41:56 +00:00
|
|
|
$findExcludes \
|
2019-09-24 15:22:00 +00:00
|
|
|
-exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \;
|
2019-03-23 13:12:58 +00:00
|
|
|
fi
|
|
|
|
done < <(env)
|
|
|
|
fi
|
|
|
|
|
2020-06-19 16:05:32 +00:00
|
|
|
exec ${SCRIPTS:-/}start-minecraftFinalSetup $@
|