#!/bin/bash

#  hint:
# 	cd /etc/lib/dyndns.d
#       fqdn=whatever
#       dnssec-keygen -a HMAC-MD5 -b 512 -n host $fqdn
#       # writes  K${fqdn}.+157+11798.key
#       # and     K${fqdn}.+157+11798.private

# for the whole domain:
#       cd /etc/lib/dyndns.d
#       domain=whatever
#	dnssec-keygen -a HMAC-MD5 -b 512 -n host ___.$domain

#   Then, in either case:
#	cd /etc/lib
#       make dyndns.keys
#       scp dyndns.d/K${fqdn}.+157+*.* ${fqdn}:/etc/lib/dyndns.d/
# ...or...
#      scp dyndns.d/K___.${domain}.+157+*.* ${fqdn}:/etc/lib/dyndns.d/
#       # make sure named.conf.local is configured to grant
#       #  authority to that key.
#
#   Then, to install the key
#	scp dyndns.d/K${fqdn}.+157+11798.* ${fqdn}:/etc/lib/dyndns.d/
#
#   On the other host:
#       /etc/init.d/bind9 reload # to reread the dyndns.keys
#	on the other host: /etc/network/update-ns
#       or perhaps: /etc/network/if-up.d/dns-update

#       #xx "zone" does not work easily;  use ___.$domain instead
#	#xx dnssec-keygen -a HMAC-MD5 -b 512 -n zone ___.$domain

for file in "$@" ; do

cat  $file | while read host j2 j3 j4 j5 j6 sec1 sec2 ; do

cat <<EoF
key "$host" {
  algorithm hmac-md5;
  secret "$sec1$sec2";
};

EoF

done

done
