#!/usr/local/bin/perl
# $Header: /tempf/aem/makehosts/makehosts,v 1.1 90/10/06 16:14:52 aem Exp $

if ( $ENV{'USER'} )
{
	$whoami = $ENV{'USER'}; 
} else { 
	$whoami = `whoami`; chop ($whoami);
}

if ( $ENV{'HOSTNAME'} ) 
{
	$hostname = $ENV{'HOSTNAME'};
} else {
	$hostname = `hostname`; chop ($hostname);
}

$date = `date`;

print "\#\n\# This file created from nameserver tables\n";
print "\#\tby $whoami\n\#\tat $hostname\n\#\ton $date\#\n";

while (<>)
{
	( $one, $two, $three, $four, $five, $six ) = split;

	if ( $three eq "SOA" )
	{
		$one =~ s/\.$//; $one =~ tr/a-z/A-Z/;
		print "\#\n\# DOMAIN $one\n";
		$one =~ tr/A-Z/a-z/; $domain = $one;
		print "\#\n\# $domain server is $four\n";
		$five =~ s/\./@/;
		print "\#  and responsible person is $five\n\#\n";
		$soa_found++;
	}

	if ( $one eq "\$ORIGIN" )
	{
		$two =~ s/\.$//; $two =~ tr/A-Z/a-z/;
		$domain = $two; $origin++;
	}

	if ( $three eq "A" && $one ne "")
	{
		if ($one !~ m/\.$/ ) 
		{			 # one of our machines, add alias
			if ( $one eq "localhost" && $origin )
			{
				# do nothing
			} else {
				print "$four\t$one.$domain\t$one\n";
			}
		} else {
			# not one of ours. Notate as such
			$one =~ s/\.$//;
			print "$four\t$one\t\t\# not one of ours\n";
		}
	}
}
