various updates, add bind
[distro-setup] / dynamic-ip-update.sh
1 #!/bin/bash
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5
6
7 cur="$(host -4 iank.pw iankelling.org | sed -rn 's/.*has address (.*)/\1/p;T;q')"
8 ip=$(curl -s4 https://iankelling.org/cgi/pubip)
9
10 # note, a simpler way to do this would be to ssh and use
11 # "${SSH_CLIENT%% *}
12 # to update bind if needed.
13
14 if [[ $cur != $ip ]]; then
15 nsupdate -k /p/c/machine_specific/li/filesystem/etc/bind/Kiank.pw.*.private <<EOF
16 server iankelling.org
17 zone iank.pw
18 update delete iank.pw. A
19 update add iank.pw. 300 A $ip
20 update delete *.iank.pw. A
21 update add *.iank.pw. 300 A $ip
22 show
23 send
24 EOF
25 fi
26
27 # persistent initial setup for this:
28 # mkc /p/c/machine_specific/li/filesystem/etc/bind
29 # s dnssec-keygen -a HMAC-MD5 -b 512 -n HOST iank.pw
30 # s chown ian:ian *
31
32 # f=key.iank.pw
33 # cat >$f <<EOF
34 # key iank.pw. {
35 # algorithm HMAC-MD5;
36 # secret "$(awk '$1 == "Key:" {print $2}' Kiank.pw.*.private)";
37 # };
38 # EOF
39 # chmod 640 $f