← back to Japan Enrich
scripts/create-distributor-dns.sh
26 lines
#!/usr/bin/env bash
# Create the 19 distributor microsite subdomains in Cloudflare (dns-only A → Kamatera),
# matching the existing DW vendor-subdomain pattern. Idempotent (skips existing).
# GATED: run under Steve (DNS on the live designerwallcoverings.com zone).
# bash scripts/create-distributor-dns.sh
set -uo pipefail
CF=$(grep -m1 -hoE "CLOUDFLARE_API_TOKEN=.*" ~/Projects/secrets-manager/.env | cut -d= -f2- | tr -d '"'"'"'')
ZID="e4b88c70e4c949f4556cc693133c2f42" # designerwallcoverings.com
IP="45.61.58.125"
# 16 free slugs (plain) + 3 colliders as <slug>-sg (koroseal/harlequin/cole-son already own the plain subdomain)
SUBS="j-josephson eijffinger omexco goodrich p3tec vahallan la-scala-milano zambaiti-parati \
carlise-co zintra versa-design-surfaces sangetsu greenland texam texdecor zambaiti \
koroseal-sg harlequin-sg cole-son-sg"
created=0; skipped=0; failed=0
for s in $SUBS; do
name="$s.designerwallcoverings.com"
exists=$(curl -s -H "Authorization: Bearer $CF" "https://api.cloudflare.com/client/v4/zones/$ZID/dns_records?name=$name&type=A" | python3 -c "import sys,json;print(len(json.load(sys.stdin).get('result',[])))")
if [ "$exists" != "0" ]; then echo " skip (exists): $name"; skipped=$((skipped+1)); continue; fi
ok=$(curl -s -X POST -H "Authorization: Bearer $CF" -H "Content-Type: application/json" \
"https://api.cloudflare.com/client/v4/zones/$ZID/dns_records" \
-d "{\"type\":\"A\",\"name\":\"$name\",\"content\":\"$IP\",\"ttl\":1,\"proxied\":false}" \
| python3 -c "import sys,json;print(json.load(sys.stdin).get('success'))")
[ "$ok" = "True" ] && { echo " ✓ created: $name"; created=$((created+1)); } || { echo " ✗ FAILED: $name"; failed=$((failed+1)); }
done
echo "created=$created skipped=$skipped failed=$failed"