Final cleanup of ips_to_peers_rxfr

master
Keith Irwin 2022-10-03 12:14:25 -06:00
parent fd9d2201b1
commit 4df5874077
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
1 changed files with 9 additions and 1 deletions

View File

@ -27,6 +27,7 @@ format="${1}"
res="$("${LIB_DIR:?}/ns_lookup_rxfr")" || exit 4
# This should read from stdin
# TODO: Run this loop in parallel
while IFS= read -r line; do
printf 'Checking line %s.\n' "${line}"
pubkey="$(<<<"${line}" cut -d ' ' -f1)"
@ -35,5 +36,12 @@ while IFS= read -r line; do
ipv6="$(<<<"${ips}" grep ':')"
ipv4="${ipv4%%/*}"
ipv6="${ipv6%%/*}"
<<<"${res}" grep -B1 " ${ipv4}\| ${ipv6}" | sed '/--/d' | awk '{print $2}' | paste -d " " - - >>"${LOGFILE}"
domain=$(<<<"${res}" grep -B1 " ${ipv4}" | sed '/--/d' | awk '{print $2}' | paste -d " " - - | awk '{print $1}')
case "${format}" in
'json') printf '{"domain":"%s","ipv4":"%s","ipv6":"%s","pubkey":"%s"},' \
"${domain}" "${ipv4}" "${ipv6}" "${pubkey}";;
'tsv') printf '%s\t%s\t%s\t%s\n' "${domain}" "${ipv4}" "${ipv6}" "${pubkey}";;
*) printf 'ERROR! Invalid format for %s: %s\n' "${0}" "${format}" >>"${LOGFILE}"
exit 5;
esac
done