Path: utzoo!attcan!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!lavaca.uh.edu!uhnix1!nuchat!abbadon From: abbadon@nuchat.UUCP (David Neal) Newsgroups: alt.sources Subject: quick hack for yp<->dns Keywords: yp dns Message-ID: <20707@nuchat.UUCP> Date: 20 Mar 90 15:34:06 GMT Organization: South Coast Computing Services, Inc. - Houston, Tx Lines: 350 #! /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 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< $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 < $D/named.pri <$D/named.rev < $D/named.local <$D/named.ca<>distfile <> 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 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 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