From: gregor herrmann Date: Thu, 6 Aug 2015 22:42:35 +0000 (+0200) Subject: move client examples to bin/client X-Git-Url: https://git.toastfreeware.priv.at/toast/tdyndns.git/commitdiff_plain/b58aebb1854c02e253bdad0168a48c7198b91b18 move client examples to bin/client --- diff --git a/bin/client/tdyndns_client b/bin/client/tdyndns_client new file mode 100755 index 0000000..7d4e9e0 --- /dev/null +++ b/bin/client/tdyndns_client @@ -0,0 +1,76 @@ +#!/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 + +# alternative: -4 icanhazip.com, -6 icanhazip.com or ipv{4,6}.icanhazip.com +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 diff --git a/bin/client/tdyndns_ifupdown b/bin/client/tdyndns_ifupdown new file mode 100755 index 0000000..2c4cf90 --- /dev/null +++ b/bin/client/tdyndns_ifupdown @@ -0,0 +1,31 @@ +#!/bin/sh + +# save as /etc/network/if-up.d/tdyndns + +# man 5 interfaces: +# IFACE physical name of the interface being processed +# LOGICAL logical name of the interface being processed +# ADDRFAM address family of the interface +# METHOD method of the interface (e.g., static) +# MODE start if run from ifup, stop if run from ifdown +# PHASE as per MODE, but with finer granularity, distinguishing the pre-up, post-up, pre-down and post-down phases. +# VERBOSITY indicates whether --verbose was used; set to 1 if so, 0 if not. +# PATH the command search path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +set -e + +[ -n "$IFACE" ] +[ -n "$MODE" ] +[ "$MODE" = "start" ] || exit 0 +[ -x /usr/local/bin/tdyndns ] || exit 0 + +case "$IFACE" in + eth*|ath*|wlan*|ppp*|wwan*) + [ "$VERBOSITY" = "1" ] && echo "Interface $IFACE started, calling tdyndns." + /usr/local/bin/tdyndns & + ;; + *) + ;; +esac + +exit 0 diff --git a/bin/tdyndns-ifupdown b/bin/tdyndns-ifupdown deleted file mode 100755 index 2c4cf90..0000000 --- a/bin/tdyndns-ifupdown +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -# save as /etc/network/if-up.d/tdyndns - -# man 5 interfaces: -# IFACE physical name of the interface being processed -# LOGICAL logical name of the interface being processed -# ADDRFAM address family of the interface -# METHOD method of the interface (e.g., static) -# MODE start if run from ifup, stop if run from ifdown -# PHASE as per MODE, but with finer granularity, distinguishing the pre-up, post-up, pre-down and post-down phases. -# VERBOSITY indicates whether --verbose was used; set to 1 if so, 0 if not. -# PATH the command search path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - -set -e - -[ -n "$IFACE" ] -[ -n "$MODE" ] -[ "$MODE" = "start" ] || exit 0 -[ -x /usr/local/bin/tdyndns ] || exit 0 - -case "$IFACE" in - eth*|ath*|wlan*|ppp*|wwan*) - [ "$VERBOSITY" = "1" ] && echo "Interface $IFACE started, calling tdyndns." - /usr/local/bin/tdyndns & - ;; - *) - ;; -esac - -exit 0 diff --git a/bin/tdyndns_client b/bin/tdyndns_client deleted file mode 100755 index 7d4e9e0..0000000 --- a/bin/tdyndns_client +++ /dev/null @@ -1,76 +0,0 @@ -#!/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 - -# alternative: -4 icanhazip.com, -6 icanhazip.com or ipv{4,6}.icanhazip.com -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