various 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 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.life
30 #s chown ian:ian *
31
32 f=key.iank.life
33 cat >$f <<EOF
34 key iank.life. {
35 algorithm HMAC-MD5;
36 secret "$(awk '$1 == "Key:" {print $2}' Kiank.life.*.private)";
37 };
38 EOF
39
40 chmod 640 $f