#!/bin/sh set -eu DOMAIN="jan.systems" HOSTNAME="pursotin" AUTH_FILE="/usr/local/etc/do_dyndns_auth" IF4="$(jexec ingress ifconfig epw1b)" # END OF CONFIG info() { echo "$(date) [INFO]" $@ } err() { >&2 echo "$(date) [ERROR]" $@ } if [ ! -r "$AUTH_FILE" ]; then err "Auth file '$AUTH_FILE' not readable" exit 1 fi IP4=$(echo "$IF4" | awk '/inet / { print $2 }' | head -n1) DIGITALOCEAN_TOKEN=$(awk '{$1=$1; print}' "$AUTH_FILE") info "Updating A record for hostname $HOSTNAME in domain $DOMAIN → $IP4" RECORD_ID=$(curl -s -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ "https://api.digitalocean.com/v2/domains/$DOMAIN/records?per_page=999999" | jq -r ".domain_records[] | select(.type==\"A\" and .name==\"$HOSTNAME\") | .id") if [ -n "$RECORD_ID" ]; then curl -s -X PUT \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"data\":\"$IP4\"}" \ "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID" > /dev/null info "Record $RECORD_ID updated" else err "No A record found for hostname \"$HOSTNAME\" in domain \"$DOMAIN\". Skipping." fi