#!/bin/bash echo "🔁 Merging new entries into: $ORIGINAL_FILE" TEMP_FILE=$(mktemp) cp "$ORIGINAL_FILE" "$TEMP_FILE" yq eval '.ingress' "$GENERATED_FILE" | yq -o=json | jq -c '.[]' | while read -r new_entry; do hostname=$(echo "$new_entry" | jq -r '.hostname') service=$(echo "$new_entry" | jq -r '.service') exists=$(yq e ".cloudflare.ingress[] | select(.hostname == \"$hostname\")" "$TEMP_FILE") if [ -z "$exists" ]; then echo "➕ Adding $hostname → $service" yq eval ".cloudflare.ingress += [{\"hostname\": \"$hostname\", \"service\": \"$service\"}]" -i "$TEMP_FILE" else echo "⚠️ $hostname already exists, skipping" fi done cp "$TEMP_FILE" "$MERGED_FILE"