From b67580af2c681a2177e9b7d044827f0df27d91e1 Mon Sep 17 00:00:00 2001 From: Pavel Andreyev Date: Tue, 24 Sep 2019 19:22:00 +0400 Subject: [PATCH] Support .conf extension for config files (#388) * Support .conf extension for config files * Update the docs for env variables --- README.md | 3 +++ start-finalSetup05EnvVariables | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4c7b762e..bb95f1f1 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,9 @@ There are some limitations to what characters you can use. | Name | `0-9a-zA-Z_-` | | Value | `0-9a-zA-Z_-:/=?.+` | +Variables will be replaced in files with the following extensions: +`.yml`, `.yaml`, `.txt`, `.cfg`, `.conf`, `.properties`. + Here is a full example where we want to replace values inside a `database.yml`. ```yml diff --git a/start-finalSetup05EnvVariables b/start-finalSetup05EnvVariables index d1c44f49..532e28e4 100644 --- a/start-finalSetup05EnvVariables +++ b/start-finalSetup05EnvVariables @@ -1,15 +1,20 @@ #!/bin/bash -if [ "$REPLACE_ENV_VARIABLES" = "TRUE" ]; then +if [ "${REPLACE_ENV_VARIABLES^^}" = "TRUE" ]; then echo "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..." while IFS='=' read -r name value ; 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 - echo "Replacing $name with $value ..." - find /data/ -type f \( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" -or -name "*.properties" \) -exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \; + if [[ "$name" = $ENV_VARIABLE_PREFIX* ]] \ + && [[ $value =~ ^[0-9a-zA-Z_:/=?.+\-]*$ ]] \ + && [[ $name =~ ^[0-9a-zA-Z_\-]*$ ]]; then + echo "Replacing $name with $value ..." + 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' {} \; fi done < <(env) fi -exec /start-minecraftFinalSetup $@ \ No newline at end of file +exec /start-minecraftFinalSetup $@