index : devops | |
Archlinux32 devs' convenience-scripts | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2018-07-10 09:39:23 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-07-10 09:39:23 +0200 |
commit | 0fd2f54b5413a5cabb2e3f369a1c6dd196f1f94e (patch) | |
tree | d89c94c62659d064d61ba0d1db353e5932e6459c | |
parent | 261e6385c50f8d017460e3fb24f2c3fc22fdb3d6 (diff) |
-rwxr-xr-x | ddns-update | 92 |
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 |