From 5b5df8960b8b89bc89d53e175296e34e168ca5d7 Mon Sep 17 00:00:00 2001 From: Kelin Date: Mon, 2 Feb 2026 17:30:24 -0500 Subject: [PATCH] Fix variable replacement logic for nested variables and remove repo file modification - Remove localize_deployment call from main flow to avoid modifying repo files - Enhance localize_yml_file to recursively expand nested variables using envsubst - Ensure config files contain actual values, not variable names --- scripts/ez-homelab.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/ez-homelab.sh b/scripts/ez-homelab.sh index c06d80b..a499f4b 100755 --- a/scripts/ez-homelab.sh +++ b/scripts/ez-homelab.sh @@ -129,13 +129,24 @@ localize_yml_file() { debug_log "Backed up $file_path" fi - # Use envsubst to replace all ${VAR} with environment values + # Use envsubst to replace all ${VAR} with environment values, handling nested variables if command -v envsubst >/dev/null 2>&1; then log_info "DEBUG: DEFAULT_EMAIL=$DEFAULT_EMAIL" - envsubst < "$file_path" > "$file_path.tmp" && mv "$file_path.tmp" "$file_path" - debug_log "Replaced variables in $file_path using envsubst" + temp_file="$file_path.tmp" + cp "$file_path" "$temp_file" + changed=true + while [ "$changed" = true ]; do + changed=false + new_content=$(envsubst < "$temp_file") + if [ "$new_content" != "$(cat "$temp_file")" ]; then + changed=true + echo "$new_content" > "$temp_file" + fi + done + mv "$temp_file" "$file_path" + debug_log "Replaced variables in $file_path using envsubst with nested expansion" replaced_count=$(grep -o '\${[^}]*}' "$file_path" | wc -l) - replaced_count=$((replaced_count / 2)) # Approximate, since envsubst replaces all + replaced_count=$((replaced_count / 2)) # Approximate else log_warning "envsubst not available, cannot localize $file_path" if [ "$fail_on_missing" = true ]; then @@ -1649,9 +1660,6 @@ main() { # Save configuration save_env_file - # Perform enhanced placeholder replacement across all config files - localize_deployment - # Validate secrets for core deployment validate_secrets