4b5983fbed4153e5c9b7a57d3203863b2093393f
10 hostnametmp
=${fqdn%%.*}
12 fqdn
=${hostnametmp}i.
${domaintmp}
16 if ! read -r _ _ gateway _ ifdev _
< <(ip
-4 route get
85.119.83.50 2>/dev
/null
); then
17 # if our internet is down, just give up, no need to have an error
18 if [[ ! $INVOCATION_ID ]]; then
19 echo $0: failed to get route
, giving up
34 if [[ -s /dev
/shm
/dynamic-ip-update-state
]]; then
35 oldbytes
=$
(cat /dev
/shm
/dynamic-ip-update-state
)
36 newbytes
=$
(awk '$1 == "'$ifdev':" {print $2 + $10}' /proc
/net
/dev
)
37 if [[ $oldbytes == [1-9]* ]] && (( newbytes
>= oldbytes
)); then
39 printf "%s\n" "$newbytes" >/dev
/shm
/dynamic-ip-update-state
42 if ! $athome && timeout
-s 9 5 ssh-keyscan
-p 2220 -t rsa
$gateway 2>/dev
/null |
grep -qFx "[$gateway]:2220 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCH+/h1dGEfKEusBblndU2e6QT4wLCm5+yqr/sqh/0X9YfjR7BfWWm8nNmuP55cYc+Wuf5ljB1H1acXEcsl1y8e0j3agHfF0V74FE1N1zz5nn2Ep8NHnmqgEhza38ZxMPh+4p3X7zklEKU7+3SzybKBi8sg0wLzlS2LM0JaUN80zR2sK11Kye3dURUXPk78u5wodOkgcEYRwSYaDMJlUzWP+poRXIDJwFaMQnwmxbl/c84yOyaU0x/d6hFwoRscWecihX+vvBNeSyxR4xr2HDOyUWwJkctyAgt2p7w3tfkXOKcCRzTAjGVIMQLTvo0sG/yJbcyHoEFdFybCsgDvfyYn"; then
44 awk '$1 == "'$ifdev':" {print $2 + $10}' /proc
/net
/dev
> /dev
/shm
/dynamic-ip-update-state
49 cur4
="$(dig +short $dynhost @iankelling.org | tail -1)"
50 if ip4
=$
(curl
-s4 https
://iankelling.org
/cgi
/pubip
); then
51 if [[ $cur4 && $ip4 && $cur4 != $ip4 ]]; then
52 up4
=true
# update ipv4
57 # may not be set yet so allow fail
58 cur6
="$(host -4 -t aaaa $fqdn iankelling.org | sed -rn 's/.*has IPv6 address (.*)/\1/p;T;q')" ||
:
62 out6
=$
(curl
-s6 https
://iankelling.org
/cgi
/pubip
) ||
: # failure allowed if we have no ipv6
65 dev
=$
(ip
-o a show to
$out6 |
awk '{print $2}')
66 # we use slaac with privacy extension, so get our less private more permanent address
67 mac
=$
(cat /sys
/class
/net
/$dev/address
)
69 IFS
=: read -a f
<<<$mac; set -- ${f[@]}
70 ip6
=${out6%:*:*:*:*}:$
(printf %x $
((0x
$1 + 2)))$2:$3'ff:fe'$4:$5$6
71 # in case we aren't using slaac
72 if ! ip a |
grep "^ *inet6 $ip6/" &>/dev
/null
; then
77 if [[ $cur6 != $ip6 ]]; then
81 if ! $up4 && ! $up6; then
85 # note, a simpler way to do this would be to ssh and use
87 # to update bind if needed.
97 update delete $dynhost. A
98 update add $dynhost. 300 A $ip4
105 update delete $fqdn. AAAA
106 update add $fqdn. 60 AAAA $ip6
110 update delete $fqdn. AAAA
122 nsupdate
-k /p
/c
/machine_specific
/vps
/filesystem
/etc
/bind
/Kb8.nz.
*.private
<$f
123 sed -i 's/^server .*/server bk.b8.nz/' $f
124 nsupdate
-k /p
/c
/machine_specific
/vps
/filesystem
/etc
/bind
/Kb8.nz.
*.private
<$f
129 if [[ $INVOCATION_ID ]]; then
130 # this is to prevent systemd from filling up the journal
131 for (( runcount
=0; runcount
< 100; runcount
++ )); do
146 # # # persistent initial setup for this:
147 # # # create files in /a/c/machine_specific/vps/filesystem/etc/bind
148 # # # note, conflink also does some group ownership stuff.
149 # mkc /p/c/machine_specific/vps/filesystem/etc/bind
150 # sudo dnssec-keygen -a HMAC-SHA512 -b 512 -n HOST b8.nz
152 # sudo chown $user:$user *
158 # algorithm HMAC-SHA512;
159 # secret "$(awk '$1 == "Key:" {print $2}' Kb8.nz.*.private)";
168 # ssh li.b8.nz systemctl reload bind9
171 # # b8.nz has address 65.96.178.16
172 # # b8.nz has IPv6 address 2601:197:600:6efb:82fa:5bff:fe1c:6ecf