#!/usr/bin/perl -w
$|=1;

$boot = `cat /etc/named.boot`;
$boot =~ /\n\S*directory (\W*?)/;

$basedir = "/var/named";
chdir ($basedir);

sub include ($)
{
    my $result = "$_[0]";
    print ("Reading $result ... \n");
    my $data = `cat $result`;
    return "\n; (autoincluded from $result)\n\n$data\n\n";
}

while ($boot =~ /\n\s*include /)
{
    $boot =~ s/\n\s*include\s*(\S*).*?\n/include ($1)/se;
}

open (CONV, "|named-bootconf.pl > /tmp/named.bootconf.$$")
    || die;
print CONV "$boot";
close (CONV);

system ("savelog -c 100 /etc/named.conf 2> /dev/null");
system ("mv -b /tmp/named.bootconf.$$ /etc/named.conf");
