Skip to content

Instantly share code, notes, and snippets.

@mz0
Last active February 3, 2020 22:03
Show Gist options
  • Save mz0/ce3130b5aff5a476c1e85a79b50f53c6 to your computer and use it in GitHub Desktop.
Save mz0/ce3130b5aff5a476c1e85a79b50f53c6 to your computer and use it in GitHub Desktop.
NetwokManager HE-dDNS hook
#!/bin/sh
#/etc/NetworkManager/dispatcher.d/ddns
arg1=$1
arg2=$2
DUMPS="/tmp/my Dispatch"
IF=enp5s0
name=host1.example.net
. /home/mz0/.ssh/ddns-key # key=6KigGftdvYqEvTW
update() {
updateURL="https://dyn.dns.he.net/nic/update?hostname=${name}&password=${key}&myip=${1}"
curl -s -o /tmp/ddns-update.re -X GET $updateURL
cat /tmp/ddns-update.re >> $2 # TODO log file timestamp
echo >> ${2}
}
dumpvars() {
echo "arg1=$arg1" >> ${1}
echo "arg2=$arg2" >> ${1}
/usr/bin/env >> "$1"
}
echo '=========================================' >> $DUMPS
echo "$0 log" >> $DUMPS
echo -n "start " >> $DUMPS
date >> $DUMPS
dumpvars "$DUMPS"
if [ $DEVICE_IFACE = $IF ] && [ -n $DHCP4_IP_ADDRESS ] \
&& [ NM_DISPATCHER_ACTION != dhcp6-change ]
then
# takes ca. 2 seconds; TODO spaw a sub-shell to not delay NM
update $DHCP4_IP_ADDRESS "$DUMPS"
fi
echo -n "finish " >> $DUMPS
date >> $DUMPS
@mz0
Copy link
Author

mz0 commented Feb 3, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment