update readme
[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 b8.nz 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/Kb8.nz.*.private <<EOF
16 server iankelling.org
17 zone b8.nz
18 update delete b8.nz. A
19 update add b8.nz. 300 A $ip
20 update delete *.b8.nz. A
21 update add *.b8.nz. 300 A $ip
22 show
23 send
24 EOF
25 fi
26
27 # # persistent initial setup for this:
28 # # create files in /a/c/machine_specific/li/filesystem/etc/bind
29 # # note, conflink also does some group ownership stuff.
30
31 # mkc /p/c/machine_specific/li/filesystem/etc/bind
32 # s dnssec-keygen -a HMAC-MD5 -b 512 -n HOST b8.nz
33 # s chown $USER:$USER *
34
35 # f=key.b8.nz
36 # cat >$f <<EOF
37 # key b8.nz. {
38 # algorithm HMAC-MD5;
39 # secret "$(awk '$1 == "Key:" {print $2}' Kb8.nz.*.private)";
40 # };
41 # EOF
42
43 # chmod 640 [kK]*
44
45 # myunison -ob li
46 # ssh li conflink
47 # ssh li ser restart bind9