[alt.sources] quick hack for yp<->dns

abbadon@nuchat.UUCP (David Neal) (03/20/90)

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  emithosts filter.awk ns.doc
# Wrapped by abbadon@nuchat on Tue Mar 20 09:32:00 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f emithosts -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"emithosts\"
else
echo shar: Extracting \"emithosts\" \(5559 characters\)
sed "s/^X//" >emithosts <<'END_OF_emithosts'
X#!/bin/csh
X# This is a c-shell script to eat your hosts file and
X# spit out several files that let you run a domain-name resolver.
X# Hopefully the comments explain well enough what's happening
X# during the course of the program.
X#
X# (C) Copyright 1990 David A. Neal. All Rights Reserved.
X# May not be copyrighted under GNU protections.
X#
X# Step one reads the hosts table from /etc/hosts and strips
X# all the comments. You must run this command on the host
X# that is normally your yp master. I.E. The machine you generate
X# your YP (OOPS, NIS) maps from.
X#
Xegrep -v '#' < /etc/hosts > hosts.1
X#
X# Step two strips the ip address and the last hostname.
X# If you have something like:
X# 192.1.1.3 fred foo fred.brc.shell.com
X# the hostname foo will be dropped. If you really need
X# multiple hostnames, hack the script.
X#
Xawk -f filter.awk < hosts.1 > hosts.2
X#
X# Next, we strip things like 'loghost', 'timehost', etc,
X# just in case they somehow filter through.
X#
Xegrep -v 'loghost' < hosts.2 | \
Xegrep -v 'mailhost' | \
Xegrep -v 'timehost' | \
Xsed 's/shell\.com//' > hosts.3
X#
X# Now, we sort by the domain name.
X#
Xsort -t'.' +1 < hosts.3 > hosts.4
X#
X# Finally, we collect the domains.
X#
Xset domains = (`cat hosts.4 | cut -f2 -d. | sort | uniq `)
X#
X# Sort out the supported domains.
X#
Xset supdomains = ""
Xset unsupdomains = ""
X
Xforeach i ( $domains )
X
X	set unsp = "n"
X
X	switch ($i)
X
X	case ic:
X		breaksw
X	case brc:
X		breaksw
X	default:
X		set unsp="y"
X		breaksw
X	endsw
X
X	if ( $unsp == "n" ) then
X		set supdomains = ( $supdomains $i )
X	else
X		set unsupdomains = ( $unsupdomains $i )
X	endif	
Xend
X
Xecho "Unsupported domains: $unsupdomains"
X
X#
X# Create the new distfile, so we can rdist the named.*
X# files to our nameservers.
X#
X
Xcat >distfile<<FOODIST
XNAMEDFILES = ( named.boot named.ca named.hosts named.local named.rev named.pri)
X
XFOODIST
X
X
X# Now loop through each domain, and create all the 
X# necessary support files.
X#
X
Xset servers = ""
X
Xforeach i ( $supdomains )
X
X# Knock the domainname name to upper case --
X# we use upper case domainnames for NIS
X# here, and this helps keep things straight.
X# Comment it out if you don't need it.
X
X	set D = `echo $i | tr a-z A-Z `
X
X	if ( -f $D ) then 
X		echo "Can't create directory for $i, flat file exists with"
X		echo "that name!"
X		break
X	endif
X
X	if ( ! -d $D ) then
X		mkdir $D
X	endif
X
X# Strip excess, since we only resolve one level
X# deep, we want REDWOOD.ic.shell.com to become
X# REDWOOD.ic. And create a host table for
X# each domain with the resulting entries.
X
X	grep "^.*\.$i\." < hosts.4 > $D/named.hosts
X
X
X# Next, create the bootfile for the domain.
X#
X# phost 	= the primary host (top level host for the domain)
X# postmaster 	= the postmaster for the domain
X# phostip	= the ip address for the top level host
X
X	set unsp = "n"
X
X	switch ($D)
X	case IC:
X		set phost = redwood
X		set postmaster = "david"
X		set phostip = "134.163.28.1"
X		set mailto = "$postmaster.$phost.$i."
X		breaksw
X	case BRC:
X		set phost = murex
X		set postmaster = "david"
X		set phostip = "88.3.0.58"
X		set mailto = "$postmaster.$phost.$i."
X		breaksw
X	default:
X		echo "Can't get master server info for: $D domain!"
X		set phost = "unknown"
X		set postmaster = "unknown"
X		set phostip = "0.0.0.0"
X		set mailto = "$postmaster.$phost.$i."
X		set unsp="y"
X		breaksw
X	endsw
X
X# Cache servers that are supported for our rdist file
X# we are in the process of creating. 
X
X	if ( $unsp == "n" ) set servers = ($servers $phost )
X
X# Next create a named.boot for each domain.
X# Tack on the domainname for now to keep
X# them straight.
X
X	set revip=( `echo $phostip | tr . '\040'` )
X	set revphostip = "$revip[3].$revip[2].$revip[1].in-addr-arpa"
X
X	cat > $D/named.boot <<FOOBOOT
Xdomain	$D
Xprimary	$D	/etc/named.pri
Xprimary	$revphostip	/etc/named.rev
Xprimary 	0.0.127.in-addr.arpa	/etc/named.local
Xcache	.	/etc/named.ca
XFOOBOOT
X
X# Create the subsidiary file mentioned in named.boot
X# that actually contains all the hosts.
X
X	cat > $D/named.pri <<FOOBOOT
X;
X; ***DOMAIN $D
X;
X;\$ORIGIN $D
X@	IN 	SOA 	$phost.$i.	$mailto (
X			45;
X			3600;
X			600;
X			360;
X			300 )
X;
X		IN	NS	$phost.$i.
Xlocalhost	IN	A	127.0.0.1
X$phost		IN	A	$phostip
X;
X\$INCLUDE "/etc/named.hosts"
X;
X;
XFOOBOOT
X#
X# We also need a file for reverse address resolution.
X# As far as my meager knowledge goes, this is only
X# needed for the nameserver. If someone out there
X# in netland needs more, this is the place to put it!
X	cat >$D/named.rev <<FOOBOOT
X@	IN	SOA	$phost.$i.	$mailto (
X								1
X								3600
X								300
X								3600000
X								3600 )
X	IN	NS	$phost.$i.
X$revip[4].$revip[3]	IN	PTR	localhost.
XFOOBOOT
X
X#
X# Finally, we create the local file that points
X# back to host for 127.0.0.1 resolution.
X# In the likely event you know a better way to
X# do this, feel free.
Xcat > $D/named.local <<FOOBOOT
X;name	ttl	addr-class	entry-type	origin	person
X@		IN		SOA		$phost.$i.	$mailto	(
X								1
X								3600
X								300
X								3600000
X								3600 )
X		IN		NS		$phost.$i.
X	1	IN		PTR		localhost.
X;
XFOOBOOT
X#
X# We also need a cache file.
X#
Xcat >$D/named.ca<<FOOBOOT
X;domain		ttl		addr-class	entry-type	server
X.		99999999	IN		NS		$phost.$i.
X$phost.$i.	99999999	IN		A		$phostip
XFOOBOOT
X#
Xend
X#
X#
Xset supdomains = ( `echo $supdomains | tr a-z A-Z` )
X
Xcat >>distfile <<FOODIST
XDOMAINS = ( $supdomains )
XFOODIST
X
X# 
X#
X#
X
Xset q = 1
X
Xwhile ( $q <= $#supdomains )
X
X	echo -n "$supdomains[$q]" >> distfile
X	echo ":" >> distfile
X	echo -n "$supdomains[$q]" >> distfile
X	echo -n '/${NAMEDFILES}' >> distfile
X	echo " -> $servers[$q]" >> distfile
X	echo "	install /etc;" >> distfile
X
X@ q = $q + 1;
X
Xend
X#
X# Cleanup
X#
Xrm hosts.[1-4]
X#
X#
X#
END_OF_emithosts
if test 5559 -ne `wc -c <emithosts`; then
    echo shar: \"emithosts\" unpacked with wrong size!
fi
chmod +x emithosts
# end of overwriting check
fi
if test -f filter.awk -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"filter.awk\"
else
echo shar: Extracting \"filter.awk\" \(198 characters\)
sed "s/^X//" >filter.awk <<'END_OF_filter.awk'
X NF == 3 { print $3 "\tA\t" $1 }
X NF == 4 { print $4 "\tA\t" $1 }
X NF == 5 { print $5 "\tA\t" $1 }
X NF == 6 { print $6 "\tA\t" $1 }
X NF == 7 { print $7 "\tA\t" $1 }
X NF == 8 { print $8 "\tA\t" $1 }
END_OF_filter.awk
if test 198 -ne `wc -c <filter.awk`; then
    echo shar: \"filter.awk\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f ns.doc -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"ns.doc\"
else
echo shar: Extracting \"ns.doc\" \(1030 characters\)
sed "s/^X//" >ns.doc <<'END_OF_ns.doc'
X03/19/90
X
XThis is a very small package for taking yp based systems and 
Xconverting them to dns.
X
XIt assumes you have hostnames of the type 'host.locald.subd.domain'
Xi.e. 'redwood.ic.shell.com'.
X
XIt also assumes you want to serve your hosts as 'redwood.ic' and
Xnot 'redwood.ic.shell.com'. You may have to hack if you want to 
Xchange this.
X
XYou have to add your domain names by hand to the script file
X'emithosts'.
X
XIt assumes you only have one 'master' server for each domain.
XIt does not add the cross links for different domains, or even
Xlinks for slave servers, cache servers, or forwarders.
X
XIf you decide to hackup this stuff, don't bother adding a
Xslick graphic interface; these programs should by run by cron
Xat night to keep files evergreen. (Up to date.) Add things
Xlike configurability, or error handling.
X
XThis is totally unsupported. 
X
XThis material is Copyrighted 1990 David A. Neal.
XIt may be freely redistributed in any way except under
Xrestrictons of the GNU License. Piss off GNU.
X
XDavid Neal
Xabbadon@nuchat.uucp
X
END_OF_ns.doc
if test 1030 -ne `wc -c <ns.doc`; then
    echo shar: \"ns.doc\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0