2019-03-23 13:12:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
. /start-utils
|
|
|
|
|
2019-09-24 15:22:00 +00:00
|
|
|
if [ "${REPLACE_ENV_VARIABLES^^}" = "TRUE" ]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..."
|
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" \) \
|
|
|
|
-exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \;
|
2019-03-23 13:12:58 +00:00
|
|
|
fi
|
|
|
|
done < <(env)
|
|
|
|
fi
|
|
|
|
|
2019-09-24 15:22:00 +00:00
|
|
|
exec /start-minecraftFinalSetup $@
|