← back to Coming Soon Template

add_domains.sh

64 lines

#!/usr/bin/env bash
# User explicitly authorized 2026-05-18: attach 19 .com domains to their Pages
# projects on Cloudflare. Cloudflare accepts the association even if DNS isn't
# yet pointing at .pages.dev — the domain sits in "pending verification" until
# DNS lands. Zero impact until DNS flips.
set -uo pipefail
cd "$(dirname "$0")"

source .env
TOKEN="${CLOUDFLARE_PAGES_TOKEN:?CLOUDFLARE_PAGES_TOKEN not set}"
ACCT="${CLOUDFLARE_ACCOUNT_ID:?CLOUDFLARE_ACCOUNT_ID not set}"

declare -a domains=(
  "abramsatlas.com:abramsatlas"
  "abramscivic.com:abramscivic"
  "abramsdirectory.com:abramsdirectory"
  "abramsguide.com:abramsguide"
  "abramsindex.com:abramsindex"
  "abramsindustries.com:abramsindustries"
  "abramsintel.com:abramsintel"
  "abramsintelligence.com:abramsintelligence"
  "abramslive.com:abramslive"
  "abramslocal.com:abramslocal"
  "abramsmaps.com:abramsmaps"
  "abramsmarkets.com:abramsmarkets"
  "abramsos.com:abramsos"
  "abramsprotection.com:abramsprotection"
  "abramsspace.com:abramsspace"
  "abramsterminal.com:abramsterminal"
  "abramsvc.com:abramsvc"
  "818butler.com:818butler"
  "beverlyhillsbutler.com:beverlyhillsbutler"
)

ok=0; skip=0; fail=0
for pair in "${domains[@]}"; do
  domain="${pair%%:*}"
  project="${pair##*:}"
  resp=$(curl -s -X POST \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    --data "{\"name\":\"$domain\"}" \
    "https://api.cloudflare.com/client/v4/accounts/$ACCT/pages/projects/$project/domains")
  if echo "$resp" | grep -q '"success":true'; then
    printf "  + %-30s -> attached to %s (pending DNS)\n" "$domain" "$project"
    ok=$((ok+1))
  elif echo "$resp" | grep -qE 'already exists|already been added|already in use'; then
    printf "  ~ %-30s -> already attached (no-op)\n" "$domain"
    skip=$((skip+1))
  else
    err=$(echo "$resp" | python3 -c "import sys,json
try:
  d=json.load(sys.stdin)
  errs=d.get('errors',[])
  print(errs[0].get('message','unknown') if errs else d)
except: print('parse error')" 2>/dev/null)
    printf "  x %-30s -> %s\n" "$domain" "$err"
    fail=$((fail+1))
  fi
done

echo
echo "summary: $ok attached, $skip already attached, $fail failed"