-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-cloudflare.sh
More file actions
executable file
·49 lines (41 loc) · 1.49 KB
/
setup-cloudflare.sh
File metadata and controls
executable file
·49 lines (41 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Setup script for Cloudflare DNS and Email Routing
# This script needs a Cloudflare API token with Zone:Read and Email Routing:Edit permissions
set -e
DOMAIN="offloadmy.work"
WORKER_NAME="offload-email"
SUBDOMAIN="email"
echo "🔍 Finding zone ID for $DOMAIN..."
# You need to set CF_API_TOKEN environment variable
if [ -z "$CF_API_TOKEN" ]; then
echo "❌ Please set CF_API_TOKEN environment variable"
echo " Get it from: https://dash.cloudflare.com/profile/api-tokens"
echo " Required permissions: Zone:Read, DNS:Edit, Email Routing Workers:Edit"
exit 1
fi
# Get zone ID
ZONE_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$DOMAIN" \
-H "Authorization: Bearer $CF_API_TOKEN" \
-H "Content-Type: application/json" | \
grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
if [ -z "$ZONE_ID" ]; then
echo "❌ Could not find zone ID for $DOMAIN"
exit 1
fi
echo "✅ Zone ID: $ZONE_ID"
echo ""
echo "📝 Manual steps still required:"
echo "1. Go to: https://dash.cloudflare.com/$ZONE_ID/dns"
echo "2. Add DNS record:"
echo " - Type: CNAME"
echo " - Name: $SUBDOMAIN"
echo " - Target: $WORKER_NAME.<your-subdomain>.workers.dev"
echo " - Proxy: ON (orange cloud)"
echo ""
echo "3. Go to: https://dash.cloudflare.com/$ZONE_ID/email/routing/routes"
echo "4. Add email routing rule:"
echo " - Catch-all pattern: *@$DOMAIN"
echo " - Action: Send to Worker"
echo " - Worker: $WORKER_NAME"
echo ""
echo "Or use the Cloudflare dashboard to complete these steps."