#!/bin/bash # # Copyright (C)2019 by Jason D. McCormick # Licensed under the Apache License 2.0. See LICENSE included # with the distribution bundle that contained this file. # PATH="/usr/bin:/bin:/usr/sbin:/sbin" ## KNOWLEDGE IS GOOD ## usage() { echo "Usage: $0 [-s SECRET] -d HOSTNAME[,HOSTNAME,...]" 1>&2; exit 1; } ## DO THE UPDATE FUNCTION ONCE FOR HAPPY EDITING ## doUpdate() { /usr/bin/curl -s$1 "https://$FQDN:$CODE@$DNSSITE/nic/update?hostname=$FQDN" > $tfile if ! egrep -q '(good|nochg)' $tfile; then echo -n "v$1 change: " cat $tfile echo retval=1 fi } ## MAIN ## while getopts "46hd:s:" arg; do case "${arg}" in 4) DO4=Y ;; 6) DO6=Y ;; d) FQDNS=${OPTARG} ;; s) CODE=${OPTARG} ;; *) usage ;; esac done if [ -z "${FQDNS}" ]; then usage fi if [ ! -f /etc/he-dns-secret ] && [ -z "${CODE}" ]; then usage fi if [ -z "${CODE}" ]; then . /etc/he-dns-secret if [ -z "${CODE}" ]; then echo "/etc/he-dns-secret does not contain a CODE= variable" exit 1 fi fi DNSSITE="dyn.dns.he.net"; retval=0 tfile=$(/bin/mktemp) for FQDN in $(echo $FQDNS | tr ',' ' ') do if [ ! -z ${DO4} ]; then doUpdate 4 fi if [ ! -z ${DO6} ]; then doUpdate 6 fi done rm $tfile exit $retval