From db086f23c4ab9c5cd0001d3211a6d5afb19ed24b Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Thu, 15 Feb 2024 21:05:43 -0600 Subject: [PATCH] WIP: Adjust runtime envsubst --- .../scripts/apply-runtime-env.sh | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/apply-runtime-env.sh b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/apply-runtime-env.sh index d3ea1d34..b52f5ce5 100755 --- a/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/apply-runtime-env.sh +++ b/stack_orchestrator/data/container-build/cerc-webapp-base/scripts/apply-runtime-env.sh @@ -18,8 +18,9 @@ if [ -f ".env" ]; then rm -f $TMP_ENV fi -for f in $(find . -regex ".*.[tj]sx?$" -type f | grep -v 'node_modules'); do - for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '[{},();]' '\n' | egrep -o -e '^"CERC_RUNTIME_ENV_[^\"]+"' -e '^"LACONIC_HOSTED_CONFIG_[^\"]+"'); do + +for f in $(find . -type f \( -name '*.html' -or -regex ".*.[tj]s\(x\|on\)?$" \) | grep -v 'node_modules' | grep -v '.git'); do + for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '[\\/{},();"]' '\n' | egrep -o -e '^CERC_RUNTIME_ENV_.+'); do orig_name=$(echo -n "${e}" | sed 's/"//g') cur_name=$(echo -n "${orig_name}" | sed 's/CERC_RUNTIME_ENV_//g') cur_val=$(echo -n "\$${cur_name}" | envsubst) @@ -31,3 +32,19 @@ for f in $(find . -regex ".*.[tj]sx?$" -type f | grep -v 'node_modules'); do sed -i "s/$orig_name/$esc_val/g" $f done done + +for f in $(find . -type f \( -name '*.html' -or -regex ".*.[tj]s\(x\|on\)?$" \) | grep -v 'node_modules' | grep -v '.git'); do + for cur_name in `env | egrep -o -e '^LACONIC_HOSTED_CONFIG_.+' | cut -d"=" -f1 | sort -u`; do + grep "$e" $f >/dev/null + if [ $? -ne 0 ]; then + continue + fi + cur_val=$(echo -n "\$${cur_name}" | envsubst) + if [ "$CERC_RETAIN_ENV_QUOTES" != "true" ]; then + cur_val=$(sed "s/^[\"']//" <<< "$cur_val" | sed "s/[\"']//") + fi + esc_val=$(sed 's/[&/\]/\\&/g' <<< "$cur_val") + echo "$f: $cur_name=$cur_val" + sed -i "s/$cur_name/$esc_val/g" $f + done +done