#!/bin/bash set -euo pipefail ENV_DIR="./envs" EXPORT_FOLDER="export" mkdir -p "$EXPORT_FOLDER" # Find all .env files in the ENV_DIR env_files=("$ENV_DIR"/*.env) if [ ${#env_files[@]} -eq 0 ]; then echo "❌ No .env files found in $ENV_DIR" exit 1 fi for env_file in "${env_files[@]}"; do echo "🔄 Processing environment file: $env_file" # Load environment variables from .env file set -o allexport source "$env_file" set +o allexport if [[ -z "${CLOUDFLARE_API_TOKEN:-}" ]]; then echo "⚠️ CLOUDFLARE_API_TOKEN not set in $env_file. Skipping." continue fi # Step 1: Fetch all zones from Cloudflare echo "Fetching zone list from Cloudflare..." zones_json=$(curl -s https://api.cloudflare.com/client/v4/zones \ -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ -H "Content-Type: application/json") # Step 2: Parse zones (needs jq) zone_count=$(echo "$zones_json" | jq '.result | length') echo "Found $zone_count zones." # Step 3: Loop through zones for ((i=0; i Saved to $OUTPUT_FILE" done echo "✅ Export complete for $env_file" echo "" done echo "🎉 All exports finished. Files are in the '$EXPORT_FOLDER' folder."