Updated the Cloudflare script in Export_DNS so it can now search for multiple sites is different env files.

This commit is contained in:
Phil 2025-10-07 08:30:46 +01:00
parent ffeb767822
commit 0a90e4c305
2 changed files with 47 additions and 23 deletions

View File

@ -1,2 +1,3 @@
# Cloudflare API Token (must have Zone:Read + DNS:Read permissions)
# Example env file (envs/site1.env)
CLOUDFLARE_API_TOKEN=your_api_token_here

View File

@ -1,12 +1,31 @@
#!/bin/bash
set -euo pipefail
# Load config
source config.conf
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 \
@ -34,5 +53,9 @@ for ((i=0; i<zone_count; i++)); do
echo " -> Saved to $OUTPUT_FILE"
done
echo "✅ All exports complete. Files are in the '$EXPORT_FOLDER' folder."
echo "✅ Export complete for $env_file"
echo ""
done
echo "🎉 All exports finished. Files are in the '$EXPORT_FOLDER' folder."