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