X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=dynamic-ip-update;h=db139d4f5347aaa5ec7ba782c776f5f9f77a8b47;hp=c725682b5e02b63eda4d9d80305cc97b28d81b84;hb=HEAD;hpb=e72acaee4cf7c394ca0e35b84d3afbd8ef5a4b32 diff --git a/dynamic-ip-update b/dynamic-ip-update index c725682..12726ae 100755 --- a/dynamic-ip-update +++ b/dynamic-ip-update @@ -1,4 +1,25 @@ #!/bin/bash +# I, Ian Kelling, follow the GNU license recommendations at +# https://www.gnu.org/licenses/license-recommendations.en.html. They +# recommend that small programs, < 300 lines, be licensed under the +# Apache License 2.0. This file contains or is part of one or more small +# programs. If a small program grows beyond 300 lines, I plan to switch +# its license to GPL. + +# Copyright 2024 Ian Kelling + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + set -e; . /usr/local/lib/bash-bear; set +e [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" @@ -67,7 +88,6 @@ main() { case $gateway in 10.2.0.1) dyndomain=b8.nz - dynhost=i.b8.nz ;; *) return 0 @@ -95,14 +115,14 @@ main() { if $athome; then - if ! cur4="$(dig +short $dynhost @iankelling.org | tail -1)"; then + if ! cur4="$(dig +short $dyndomain @iankelling.org | tail -1)"; then if [[ ! $INVOCATION_ID ]]; then echo "$0: dig failed. internet looks down. giving up" fi return 0 fi if ip4=$(curl --connect-timeout 10 -s4 https://iankelling.org/cgi/pubip); then - if $force || [[ $cur4 && $ip4 && $cur4 != $ip4 ]]; then + if $force || [[ $cur4 && $ip4 && $cur4 != "$ip4" ]]; then up4=true # update ipv4 fi fi @@ -120,7 +140,7 @@ main() { # we use slaac with privacy extension, so get our less private more permanent address mac=$(cat /sys/class/net/$dev/address) - IFS=: read -a f <<<$mac; set -- ${f[@]} + IFS=: read -ra f <<<$mac; set -- ${f[@]} ip6=${out6%:*:*:*:*}:$(printf %x $((0x$1 + 2)))$2:$3'ff:fe'$4:$5$6 # in case we aren't using slaac if ! ip a | grep "^ *inet6 $ip6/" &>/dev/null; then @@ -128,7 +148,7 @@ main() { fi fi - if $force || [[ $cur6 != $ip6 ]]; then + if $force || [[ $cur6 != "$ip6" ]]; then up6=true fi @@ -146,16 +166,14 @@ main() { # "${SSH_CLIENT%% *} # to update bind if needed. - f=$(mktemp) - cat >>$f <>$tmpf <>$f <>$tmpf <>$f <>$tmpf <>$f <>$tmpf <>$f <>$tmpf < nsupdate_fail_limit )); then echo error: nsupdate is persistently failing >&2 exit 1 fi + rm -f $tmpf } loop-main() { @@ -219,7 +238,7 @@ exit 0 # f=key.b8.nz -# cat >$f <$tmpf <