index : devops | |
Archlinux32 devs' convenience-scripts | gitolite user |
summaryrefslogtreecommitdiff |
-rwxr-xr-x | ddns-update | 47 |
diff --git a/ddns-update b/ddns-update index 0476242..d6785d6 100755 --- a/ddns-update +++ b/ddns-update @@ -28,6 +28,29 @@ if [ $# -eq 1 ]; then exit fi +mirrors=$( + curl -s 'https://packages.archlinux32.org/mirrors/status.php?tsv' +) + +url_column=$( + printf '%s\n' "${mirrors}" | \ + head -n1 | \ + tr '\t' '\n' | \ + grep -nxF 'url' | \ + cut -d: -f1 +) +recently_active_column=$( + printf '%s\n' "${mirrors}" | \ + head -n1 | \ + tr '\t' '\n' | \ + grep -nxF 'recently_active' | \ + cut -d: -f1 +) +if [ -z "${url_column}" ] || [ -z "${recently_active_column}" ]; then + # https://packages.archlinux32.org/mirrors/status.php?tsv gave bogus content + exit +fi + { for type in 'A' 'AAAA'; do printf '%s\n' \ @@ -37,25 +60,11 @@ fi '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}"' - }' - } | \ + printf '%s\n' "${mirrors}" | \ + sed '1d' | \ + awk '{ + print $'"${recently_active_column}"' "\t" $'"${url_column}"' + }' | \ sed -n ' s/^1\t// T |