diff --git a/Export_DNS/Cloudflare/export_dns_cloudflare.sh b/Export_DNS/Cloudflare/export_dns_cloudflare.sh index 8c570ef..b86e4d6 100755 --- a/Export_DNS/Cloudflare/export_dns_cloudflare.sh +++ b/Export_DNS/Cloudflare/export_dns_cloudflare.sh @@ -1,28 +1,36 @@ #!/bin/bash set -euo pipefail -ENV_DIR="./envs" -EXPORT_FOLDER="export" +# Get the directory where the script is located +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +ENV_DIR="$SCRIPT_DIR/envs" +EXPORT_FOLDER="$SCRIPT_DIR/export" + +# Create export folder and a dated subfolder with time (YYYY-MM-DD_HH-MM-SS) mkdir -p "$EXPORT_FOLDER" +DATE_DIR="$(date +"%Y-%m-%d_%H-%M-%S")" +OUTPUT_DIR="$EXPORT_FOLDER/$DATE_DIR" +mkdir -p "$OUTPUT_DIR" # 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" + echo "No .env files found in $ENV_DIR" exit 1 fi for env_file in "${env_files[@]}"; do - echo "🔄 Processing environment file: $env_file" - + 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." + echo "CLOUDFLARE_API_TOKEN not set in $env_file. Skipping." continue fi @@ -42,7 +50,7 @@ for env_file in "${env_files[@]}"; do SITE_NAME=$(echo "$zones_json" | jq -r ".result[$i].name") TIMESTAMP=$(date +"%Y%m%d_%H%M%S") - OUTPUT_FILE="$EXPORT_FOLDER/${SITE_NAME}_$TIMESTAMP.txt" + OUTPUT_FILE="$OUTPUT_DIR/${SITE_NAME}_$TIMESTAMP.txt" echo "Exporting DNS records for $SITE_NAME..." @@ -53,9 +61,9 @@ for env_file in "${env_files[@]}"; do echo " -> Saved to $OUTPUT_FILE" done - echo "✅ Export complete for $env_file" + echo "Export complete for $env_file" echo "" done -echo "🎉 All exports finished. Files are in the '$EXPORT_FOLDER' folder." +echo "All exports finished. Files are in the '$OUTPUT_DIR' folder."