summaryrefslogtreecommitdiff
path: root/he-dyndns-bash
diff options
context:
space:
mode:
authorJason D. McCormick <jason@mfamily.org>2022-11-26 12:02:30 -0500
committerJason D. McCormick <jason@mfamily.org>2022-11-26 12:02:30 -0500
commit8c81c35db4c4f5fc42c70c02f0750eaccb868b84 (patch)
treedda0aaad1e0f7c39f1760328a7682650363b00bd /he-dyndns-bash
parent9212ef438c3a18d176e856c738b017929b9e75eb (diff)
New, full-fledged python implementation
Diffstat (limited to 'he-dyndns-bash')
-rwxr-xr-xhe-dyndns-bash91
1 files changed, 91 insertions, 0 deletions
diff --git a/he-dyndns-bash b/he-dyndns-bash
new file mode 100755
index 0000000..0ce3730
--- /dev/null
+++ b/he-dyndns-bash
@@ -0,0 +1,91 @@
+#!/bin/bash
+#
+# Copyright (C)2019 by Jason D. McCormick <jason@mfamily.org>
+# 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() {
+
+ if [ ! -z $2 ]; then
+ myip="&myip=$2"
+ fi
+
+ /usr/bin/curl -s$1 "https://$FQDN:$CODE@$DNSSITE/nic/update?hostname=$FQDN$myip" > $tfile
+ if ! egrep -q '(good|nochg)' $tfile; then
+ echo -n "v$1 change: "
+ cat $tfile
+ echo
+ retval=1
+ fi
+}
+
+## MAIN ##
+while getopts "46a:A:hd:s:" arg; do
+ case "${arg}" in
+ 4)
+ DO4=Y
+ ;;
+ 6)
+ DO6=Y
+ ;;
+ a)
+ ADDR4=${OPTARG}
+ ;;
+ A)
+ ADDR6=${OPTARG}
+ ;;
+ 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 ${ADDR4}
+ fi
+
+ if [ ! -z ${DO6} ]; then
+ doUpdate 6 ${ADDR6}
+ fi
+done
+
+rm $tfile
+
+exit $retval
+