Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/ddns-update
diff options
context:
space:
mode:
Diffstat (limited to 'ddns-update')
-rwxr-xr-xddns-update92
1 files changed, 92 insertions, 0 deletions
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