various updates, add bind
[distro-setup] / dynamic-ip-update.sh
index a2da871b722f8b1f408ced0bed04aa71f39f0722..923da11464a95fbbbbcdf96493baa88510e38022 100755 (executable)
@@ -1,32 +1,39 @@
-#!/bin/bash -l
-
-
-# note: in practice, I've not seen my ip address change under comcast
-# for over a year. If the internet hadn't mislead me, I wouldn't have
-# bothered.
-
-
-
-
-# based on: https://www.namecheap.com/support/knowledgebase/article.aspx/36/11/how-do-i-start-using-dynamic-dns
-
-# go to advanced dns, enable the little slider checkbox for dynamic dns,
-# add dnynamic dns records for @ and * (not sure * will work, but eh),
-# with the initial ip you want. remove any other host records, for example
-# the initial default ones. copy the dynamic dns password to /p/dynamic-ip-pass.
-
-# other articles I found usefull previously, but not the last time
-#  http://mwholt.blogspot.com/2013/09/how-to-set-up-dynamic-dns-in-5-minutes.html
-# https://www.namecheap.com/support/knowledgebase/article.aspx/583/11/how-do-i-configure-ddclient
-
-ip=`curl -s4 echoip.com`
-curl -sS "https://dynamicdns.park-your-domain.com/update?host=@&domain=$HOME_DOMAIN&password=$(cat /p/dynamic-ip-pass)&ip=$ip" > /dev/null
-
-# an alternative, putting my ip on some known server,
-# allows ssh to home if I can access that server:
-# ssh -o "ProxyCommand ssh someserver -W desktop:22" desktop
-
-# ssh root@some_server bash <<'EOF' | log-once dynamic-ip
-# sed -i --follow-symlinks '/desktop$/d' /etc/hosts
-# echo "${SSH_CLIENT%% *} desktop" >> /etc/hosts
+#!/bin/bash
+
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+
+cur="$(host -4 iank.pw iankelling.org | sed -rn 's/.*has address (.*)/\1/p;T;q')"
+ip=$(curl -s4 https://iankelling.org/cgi/pubip)
+
+# note, a simpler way to do this would be to ssh and use
+# "${SSH_CLIENT%% *}
+# to update bind if needed.
+
+if [[ $cur != $ip ]]; then
+    nsupdate -k /p/c/machine_specific/li/filesystem/etc/bind/Kiank.pw.*.private <<EOF
+server iankelling.org
+zone iank.pw
+update delete iank.pw. A
+update add iank.pw. 300 A $ip
+update delete *.iank.pw. A
+update add *.iank.pw. 300 A $ip
+show
+send
+EOF
+fi
+
+# persistent initial setup for this:
+# mkc /p/c/machine_specific/li/filesystem/etc/bind
+# s dnssec-keygen -a HMAC-MD5 -b 512 -n HOST iank.pw
+# s chown ian:ian *
+
+# f=key.iank.pw
+# cat >$f <<EOF
+# key iank.pw. {
+# algorithm HMAC-MD5;
+# secret "$(awk '$1 == "Key:" {print $2}' Kiank.pw.*.private)";
+# };
 # EOF
+# chmod 640 $f