home *** CD-ROM | disk | FTP | other *** search
- #!/bin/csh
- # This is a c-shell script to eat your hosts file and
- # spit out several files that let you run a domain-name resolver.
- # Hopefully the comments explain well enough what's happening
- # during the course of the program.
- #
- # (C) Copyright 1990 David A. Neal. All Rights Reserved.
- # May not be copyrighted under GNU protections.
- #
- # Step one reads the hosts table from /etc/hosts and strips
- # all the comments. You must run this command on the host
- # that is normally your yp master. I.E. The machine you generate
- # your YP (OOPS, NIS) maps from.
- #
- egrep -v '#' < /etc/hosts > hosts.1
- #
- # Step two strips the ip address and the last hostname.
- # If you have something like:
- # 192.1.1.3 fred foo fred.brc.shell.com
- # the hostname foo will be dropped. If you really need
- # multiple hostnames, hack the script.
- #
- awk -f filter.awk < hosts.1 > hosts.2
- #
- # Next, we strip things like 'loghost', 'timehost', etc,
- # just in case they somehow filter through.
- #
- egrep -v 'loghost' < hosts.2 | \
- egrep -v 'mailhost' | \
- egrep -v 'timehost' | \
- sed 's/shell\.com//' > hosts.3
- #
- # Now, we sort by the domain name.
- #
- sort -t'.' +1 < hosts.3 > hosts.4
- #
- # Finally, we collect the domains.
- #
- set domains = (`cat hosts.4 | cut -f2 -d. | sort | uniq `)
- #
- # Sort out the supported domains.
- #
- set supdomains = ""
- set unsupdomains = ""
-
- foreach i ( $domains )
-
- set unsp = "n"
-
- switch ($i)
-
- case ic:
- breaksw
- case brc:
- breaksw
- default:
- set unsp="y"
- breaksw
- endsw
-
- if ( $unsp == "n" ) then
- set supdomains = ( $supdomains $i )
- else
- set unsupdomains = ( $unsupdomains $i )
- endif
- end
-
- echo "Unsupported domains: $unsupdomains"
-
- #
- # Create the new distfile, so we can rdist the named.*
- # files to our nameservers.
- #
-
- cat >distfile<<FOODIST
- NAMEDFILES = ( named.boot named.ca named.hosts named.local named.rev named.pri)
-
- FOODIST
-
-
- # Now loop through each domain, and create all the
- # necessary support files.
- #
-
- set servers = ""
-
- foreach i ( $supdomains )
-
- # Knock the domainname name to upper case --
- # we use upper case domainnames for NIS
- # here, and this helps keep things straight.
- # Comment it out if you don't need it.
-
- set D = `echo $i | tr a-z A-Z `
-
- if ( -f $D ) then
- echo "Can't create directory for $i, flat file exists with"
- echo "that name!"
- break
- endif
-
- if ( ! -d $D ) then
- mkdir $D
- endif
-
- # Strip excess, since we only resolve one level
- # deep, we want REDWOOD.ic.shell.com to become
- # REDWOOD.ic. And create a host table for
- # each domain with the resulting entries.
-
- grep "^.*\.$i\." < hosts.4 > $D/named.hosts
-
-
- # Next, create the bootfile for the domain.
- #
- # phost = the primary host (top level host for the domain)
- # postmaster = the postmaster for the domain
- # phostip = the ip address for the top level host
-
- set unsp = "n"
-
- switch ($D)
- case IC:
- set phost = redwood
- set postmaster = "david"
- set phostip = "134.163.28.1"
- set mailto = "$postmaster.$phost.$i."
- breaksw
- case BRC:
- set phost = murex
- set postmaster = "david"
- set phostip = "88.3.0.58"
- set mailto = "$postmaster.$phost.$i."
- breaksw
- default:
- echo "Can't get master server info for: $D domain!"
- set phost = "unknown"
- set postmaster = "unknown"
- set phostip = "0.0.0.0"
- set mailto = "$postmaster.$phost.$i."
- set unsp="y"
- breaksw
- endsw
-
- # Cache servers that are supported for our rdist file
- # we are in the process of creating.
-
- if ( $unsp == "n" ) set servers = ($servers $phost )
-
- # Next create a named.boot for each domain.
- # Tack on the domainname for now to keep
- # them straight.
-
- set revip=( `echo $phostip | tr . '\040'` )
- set revphostip = "$revip[3].$revip[2].$revip[1].in-addr-arpa"
-
- cat > $D/named.boot <<FOOBOOT
- domain $D
- primary $D /etc/named.pri
- primary $revphostip /etc/named.rev
- primary 0.0.127.in-addr.arpa /etc/named.local
- cache . /etc/named.ca
- FOOBOOT
-
- # Create the subsidiary file mentioned in named.boot
- # that actually contains all the hosts.
-
- cat > $D/named.pri <<FOOBOOT
- ;
- ; ***DOMAIN $D
- ;
- ;\$ORIGIN $D
- @ IN SOA $phost.$i. $mailto (
- 45;
- 3600;
- 600;
- 360;
- 300 )
- ;
- IN NS $phost.$i.
- localhost IN A 127.0.0.1
- $phost IN A $phostip
- ;
- \$INCLUDE "/etc/named.hosts"
- ;
- ;
- FOOBOOT
- #
- # We also need a file for reverse address resolution.
- # As far as my meager knowledge goes, this is only
- # needed for the nameserver. If someone out there
- # in netland needs more, this is the place to put it!
- cat >$D/named.rev <<FOOBOOT
- @ IN SOA $phost.$i. $mailto (
- 1
- 3600
- 300
- 3600000
- 3600 )
- IN NS $phost.$i.
- $revip[4].$revip[3] IN PTR localhost.
- FOOBOOT
-
- #
- # Finally, we create the local file that points
- # back to host for 127.0.0.1 resolution.
- # In the likely event you know a better way to
- # do this, feel free.
- cat > $D/named.local <<FOOBOOT
- ;name ttl addr-class entry-type origin person
- @ IN SOA $phost.$i. $mailto (
- 1
- 3600
- 300
- 3600000
- 3600 )
- IN NS $phost.$i.
- 1 IN PTR localhost.
- ;
- FOOBOOT
- #
- # We also need a cache file.
- #
- cat >$D/named.ca<<FOOBOOT
- ;domain ttl addr-class entry-type server
- . 99999999 IN NS $phost.$i.
- $phost.$i. 99999999 IN A $phostip
- FOOBOOT
- #
- end
- #
- #
- set supdomains = ( `echo $supdomains | tr a-z A-Z` )
-
- cat >>distfile <<FOODIST
- DOMAINS = ( $supdomains )
- FOODIST
-
- #
- #
- #
-
- set q = 1
-
- while ( $q <= $#supdomains )
-
- echo -n "$supdomains[$q]" >> distfile
- echo ":" >> distfile
- echo -n "$supdomains[$q]" >> distfile
- echo -n '/${NAMEDFILES}' >> distfile
- echo " -> $servers[$q]" >> distfile
- echo " install /etc;" >> distfile
-
- @ q = $q + 1;
-
- end
- #
- # Cleanup
- #
- rm hosts.[1-4]
- #
- #
- #
-