lots of fixes
[distro-setup] / dynamic-ip-update.sh
index 60c9dd9e79283bafab04d77edd784ae28922ae49..336aaf3583e16b42e527832d67ad1e414a45ac24 100755 (executable)
@@ -1,32 +1,47 @@
-#!/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 | /a/exe/log-once dynamic-ip
+#!/bin/bash
+
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+
+cur="$(host -4 b8.nz 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/Kb8.nz.*.private <<EOF
+server iankelling.org
+zone b8.nz
+update delete b8.nz. A
+update add b8.nz. 300 A $ip
+update delete *.b8.nz. A
+update add *.b8.nz. 300 A $ip
+show
+send
+EOF
+fi
+
+# # persistent initial setup for this:
+# # create files in /a/c/machine_specific/li/filesystem/etc/bind
+# # note, conflink also does some group ownership stuff.
+
+# mkc /p/c/machine_specific/li/filesystem/etc/bind
+# s dnssec-keygen -a HMAC-MD5 -b 512 -n HOST b8.nz
+# s chown $USER:$USER *
+
+# f=key.b8.nz
+# cat >$f <<EOF
+# key b8.nz. {
+# algorithm HMAC-MD5;
+# secret "$(awk '$1 == "Key:" {print $2}' Kb8.nz.*.private)";
+# };
+# EOF
 
-# 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
+# chmod 640 [kK]*
 
-# ssh root@some_server bash <<'EOF' | log-once dynamic-ip
-# sed -i --follow-symlinks '/desktop$/d' /etc/hosts
-# echo "${SSH_CLIENT%% *} desktop" >> /etc/hosts
-# EOF
+# myunison -ob li
+# ssh li conflink
+# ssh li ser restart bind9