#!/bin/bash

. ${TOOLKIT}-functions.sh

# populate from kl-djbdns package example files
#
src=/usr/share/doc/kl-djbdns/examples

for dir in dnscachex tinydns
do
	[ -d /var/djbdns/$dir/log ] && {
		echo " fixing $dir structure in /var/djbdns"
		file=$src/$dir.tar.gz
		[ -f $file ] || {
			echo "error, file $file not found"
			continue
		}
		(cd /var/djbdns ; tar xfpz $file) || exit $?
	}
done

$SOMETHING_CHANGED || exit 0

restart_service kl-daemontools

# usefull links
#
cd /etc
rm -f dns ; ln -s /var/djbdns/tinydns/root dns
cd /var/log
rm -f dnscachex ; ln -s /var/djbdns/dnscachex/log/main dnscachex
rm -f tinydns ; ln -s /var/djbdns/tinydns/log/main tinydns

# rebuild dns
#
cd /etc/dns
if [ -f hosts.src ]
then
	rm -f data data.cdb
	make
else
	putwarning "DJBDNS hosts.src" \
		"go to /etc/dns directory, fill your dns entries into the " \
		"file 'hosts.src' and type the command 'make' to rebuild the db"
fi

exit 0
