site-josuah

/usr/josuah
Log | Files | Refs

commit e3484eacfae94afa95ad2ecec866ced2ced3f8a2
parent 86414b79534abfaf87bd4db29e3efb20c326e51f
Author: Josuah Demangeon <me@josuah.net>
Date:   Sat, 18 Apr 2020 00:43:34 +0200

tinydns: import the awk script and add an entry in index.md

Diffstat:
M.githooks/post-update | 2++
Mindex.md | 6++++--
Awiki/tinydns/data.awk | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mwiki/tinydns/index.md | 4++--
4 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/.githooks/post-update b/.githooks/post-update @@ -10,3 +10,5 @@ notwiki-doc gph "/srv/gopher" * cp -r "ascii" "/srv/gopher/" cp -r "ascii" "/srv/www/htdocs/josuah" +cp -r "wiki" "/srv/gopher/" +cp -r "wiki" "/srv/www/htdocs/josuah" diff --git a/index.md b/index.md @@ -12,9 +12,11 @@ As well as documentation on other people's software: * Use of [[awk]], the command/language. * Use of [[jj]] with UCSPI and s6. + * Use of [[tinydns]] with an awk scripts for generating dns ./data. -[awk]: //josuah.net/wiki/awk/ -[jj]: //josuah.net/wiki/jj/ +[awk]: /wiki/awk/ +[jj]: /wiki/jj/ +[tinydns]: /wiki/tinydns/ And finally, [[ASCII]] Art. diff --git a/wiki/tinydns/data.awk b/wiki/tinydns/data.awk @@ -0,0 +1,59 @@ +#!/usr/bin/awk -f +# compose a tinydns-fromatted data file from multiple input files + +function ip6_hex(ip6, + hex, i, arr) +{ + sub("::", substr("::::::::", split(ip6, arr, ":") - 1), ip6) + split(ip6, arr, ":") + for (i = 1; i <= 8; i++) + hex = hex substr("0000" arr[i], length(arr[i]) + 1) + return hex +} + +/^$/ { next } + +FILENAME != "rr.soa" { + print(FNR > 1 ? "" : "\n# " FILENAME "\n") +} + +FILENAME == "rr.soa" { + domain[++i] = $1 +} + +FILENAME == "rr.host" { + for (i = 2; i <= NF; i++) { + if (index($i, ":") == 0) { + host4[$1] = $i + print("=" $1 "." domain[1] ":" host4[$1]) + } else { + host6[$1] = ip6_hex($i) + print("6" $1 "." domain[1] ":" host6[$1]) + } + } +} + +FILENAME == "rr.alias" { + for (i = 2; i <= NF; i++) { + if (host4[$1]) print("+" $i ":" host4[$1]) + if (host6[$1]) print("3" $i ":" host6[$1]) + } +} + +FILENAME == "rr.ns" { + if (host4[$1]) print("+" $2 "." domain[1] ":" host4[$1]) + if (host6[$1]) print("3" $2 "." domain[1] ":" host6[$1]) + for (i in domain) { + print("." domain[i] "::" $2 "." domain[1]) + } +} + +FILENAME == "rr.mx" { + for (i in domain) { + print("@" domain[i] "::" $1 "." domain[1]) + } +} + +END { + print("") +} diff --git a/wiki/tinydns/index.md b/wiki/tinydns/index.md @@ -20,9 +20,9 @@ information: entries on some of these IPs. To achieve this, I use these *input files*, that get converted into ./data by -an awk [[script]]: +an awk script /etc/tinydns/[[data.awk]]: -[script]: /wiki/tinydns/data.awk +[data.awk]: /wiki/tinydns/data.awk /etc/dns/rr.domain