add example client shell script
authorgregor herrmann <gregoa@debian.org>
Tue, 15 Apr 2014 21:25:49 +0000 (23:25 +0200)
committergregor herrmann <gregoa@debian.org>
Tue, 15 Apr 2014 21:26:11 +0000 (23:26 +0200)
bin/tdyndns_client [new file with mode: 0755]

diff --git a/bin/tdyndns_client b/bin/tdyndns_client
new file mode 100755 (executable)
index 0000000..20e299c
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+set -u
+
+# debug?
+
+if [ $# -gt 0 ] ; then
+       DOIT="echo "
+       set -x
+else
+       DOIT=""
+fi
+
+# functions
+
+die() {
+       echo "$1" >&2
+       exit 1
+}
+
+warn() {
+       echo "$1" >&2
+}
+
+# variables
+
+USERNAME=sue
+PASSWORD=hygCithOrs5
+HOSTNAME=$(hostname)
+ZONE=dyn.example.com
+FQDN=$HOSTNAME.$USERNAME.$ZONE
+NS=ns.example.com
+URL="http://dyndns.example.com/nic/update?hostname=$FQDN&myip="
+
+if [ -z "$HOSTNAME" ] ; then
+       die "No hostname found."
+fi
+
+# data
+
+NEWIPV4=$(wget -q -O- http://ipv4.wtfismyip.com/text)
+NEWIPV6=$(wget -q -O- http://ipv6.wtfismyip.com/text)
+
+if command -v dig >/dev/null ; then
+       OLDIPV4=$(dig -t a    +short $FQDN @$NS)
+       OLDIPV6=$(dig -t aaaa +short $FQDN @$NS)
+fi
+OLDIPV4=${OLDIPV4:-""}
+OLDIPV6=${OLDIPV6:-""}
+
+# actions
+
+# old ipv4 gone
+if [ -n "$OLDIPV4" -a -z "$NEWIPV4" ] ; then
+  $DOIT wget -q -O/dev/null --user=$USERNAME --password=$PASSWORD "${URL}${OLDIPV4}&offline=yes"
+  logger -t${0##*/} -perr -- "removing $FQDN / $OLDIPV4"
+fi
+
+# old ipv6 gone
+if [ -n "$OLDIPV6" -a -z "$NEWIPV6" ] ; then
+  $DOIT wget -q -O/dev/null --user=$USERNAME --password=$PASSWORD "${URL}${OLDIPV6}&offline=yes"
+  logger -t${0##*/} -perr -- "removing $FQDN / $OLDIPV6"
+fi
+
+# new ipv4
+if [ -n "$NEWIPV4" -a "$NEWIPV4" != "$OLDIPV4" ] ; then
+  $DOIT wget -q -O/dev/null --user=$USERNAME --password=$PASSWORD "${URL}${NEWIPV4}"
+  logger -t${0##*/} -perr -- "updating $FQDN to $NEWIPV4"
+fi
+
+# newipv6
+if [ -n "$NEWIPV6" -a "$NEWIPV6" != "$OLDIPV6" ] ; then
+  $DOIT wget -q -O/dev/null --user=$USERNAME --password=$PASSWORD "${URL}${NEWIPV6}"
+  logger -t${0##*/} -perr -- "updating $FQDN to $NEWIPV6"
+fi