From 0fd2f54b5413a5cabb2e3f369a1c6dd196f1f94e Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 10 Jul 2018 09:39:23 +0200 Subject: ddns-update new --- ddns-update | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 ddns-update (limited to 'ddns-update') diff --git a/ddns-update b/ddns-update new file mode 100755 index 0000000..7bfabf9 --- /dev/null +++ b/ddns-update @@ -0,0 +1,92 @@ +#!/bin/bash + +# update dns records of +# pool.mirror.archlinux32.org = CNAME pool32.ddns.eckner.net + +# either called with 1 argument (the ip to check and add) or without +# arguments (all known mirrors will be checked in parallel) + +set -e + +if [ $# -eq 1 ]; then + if [ "${1%.*}" != "$1" ]; then + ipver='A' + lft='' + rt='' + elif [ "${1%:*}" != "$1" ]; then + ipver='AAAA' + lft='[' + rt=']' + else + exit + fi + + if [ "$(curl \ + -w '%{http_code}' \ + -L \ + -o /dev/null \ + --connect-timeout 10 \ + --resolve "pool.mirror.archlinux32.org:80:${lft}$1${rt}" \ + -s 'http://pool.mirror.archlinux32.org/i686/')" != '200' ]; then + exit + fi + + printf '%s %s\n' "${ipver}" "$1" + exit +fi + +{ + for type in 'A' 'AAAA'; do + printf '%s\n' \ + 'zone ddns.eckner.net.' \ + 'prereq yxrrset pool32.ddns.eckner.net IN '"${type}" \ + 'update delete pool32.ddns.eckner.net IN '"${type}" \ + 'send' + done + printf 'zone ddns.eckner.net.\n' + curl -s 'https://packages.archlinux32.org/mirrors/status.php?tsv' | \ + { + read -r headers + url_column=$( + printf '%s\n' "${headers}" | \ + tr '\t' '\n' | \ + grep -nxF 'url' | \ + cut -d: -f1 + ) + recently_active_column=$( + printf '%s\n' "${headers}" | \ + tr '\t' '\n' | \ + grep -nxF 'recently_active' | \ + cut -d: -f1 + ) + awk '{ + print $'"${recently_active_column}"' "\t" $'"${url_column}"' + }' + } | \ + sed -n ' + s/^1\t// + T + \|//mirror\.archlinux32\.org/|d + s|[^:]\+://|| + T + s|/.*$|| + p + ' | \ + sort -u | \ + parallel -j0 getent ahosts | \ + sed -n ' + s/\s\+STREAM\(\s.*\)\?$// + T + p + ' | \ + sort -u | \ + parallel -j0 "$0" | \ + sed ' + s/^/update add pool32.ddns.eckner.net. 3600 IN / + ' + printf '%s\n' \ + 'send' +} | \ + nsupdate -l + +exit 0 -- cgit v1.2.3-70-g09d2