demo / network-computer
Public
Copy of github.com/askrobots/network-computer (MIT): a desk you reach from anything. The original lives on GitHub.
GitStable demo
README: say this is a copy and where the original is
cde82c2
13 hours, 36 minutes ago
History
dns-point.sh · 1.4 KB · 27 lines
| 1 | #!/bin/sh |
| 2 | # Point <fqdn> at <ip> with an A record in DigitalOcean DNS (create or update). |
| 3 | # Needs the domain's DNS hosted on DigitalOcean and a doctl token with write |
| 4 | # access to domains. TTL is 60s because a droplet's IP changes on every rebuild. |
| 5 | # |
| 6 | # infra/dns-point.sh nc.example.com 203.0.113.5 |
| 7 | set -e |
| 8 | FQDN=${1:?usage: dns-point.sh <fqdn> <ip>}; IP=${2:?usage: dns-point.sh <fqdn> <ip>} |
| 9 | # the longest DigitalOcean zone that is a suffix of the name |
| 10 | ZONE=$(doctl compute domain list --format Domain --no-header | awk -v f="$FQDN" ' |
| 11 | { z=$1; n=length(z) |
| 12 | if (length(f) > n && substr(f, length(f)-n) == "." z && n > best) { best=n; zone=z } } |
| 13 | END { print zone }') |
| 14 | [ -n "$ZONE" ] || { |
| 15 | echo "no DigitalOcean DNS zone covers $FQDN." |
| 16 | echo "Either host the domain's DNS on DigitalOcean (see docs/DOMAIN.md), or create the" |
| 17 | echo "A record $FQDN -> $IP at your DNS provider yourself and re-run with NC_DOMAIN set." |
| 18 | exit 1 |
| 19 | } |
| 20 | REC=${FQDN%."$ZONE"} |
| 21 | ID=$(doctl compute domain records list "$ZONE" --format ID,Type,Name --no-header | awk -v n="$REC" '$2=="A" && $3==n{print $1; exit}') |
| 22 | if [ -n "$ID" ]; then |
| 23 | doctl compute domain records update "$ZONE" --record-id "$ID" --record-data "$IP" --record-ttl 60 >/dev/null |
| 24 | else |
| 25 | doctl compute domain records create "$ZONE" --record-type A --record-name "$REC" --record-data "$IP" --record-ttl 60 >/dev/null |
| 26 | fi |
| 27 | echo "$FQDN -> $IP (A record in $ZONE, ttl 60)" |