home *** CD-ROM | disk | FTP | other *** search
- # Written by: Chris Lewis, clewis@eci386
- # unpackmaps release 2.0 (alpha)
- trap "rm -f /tmp/unp?$$; exit" 0 1 2 3 15
- IFS="
- "
- export IFS
- PATH=/bin:/usr/bin
- export PATH
-
- # The name of the file that you've caused your news system to
- # batch the file names of the map articles.
- # Eg: C-news
- BATCH=/usr/lib/news/batch/b.maps/togo
- # Eg: B-news
- #BATCH=/usr/spool/batch/maps
- # News spool directory
- NEWSSPOOL=/usr/spool/news
- # Where you want the maps to go.
- # I like using /usr/spool/maps, but on our system, /usr/spool/news
- # is a separate file system, and /usr runs close to the limit...
- MAPDIR=/usr/spool/news/maps
- # Person to send results and error messages to
- NOTIFY=clewis
- # pathalias binary
- PATHALIAS=/usr/lbin/pathalias
- # where you want the path files to go:
- # A convenient place is /usr/lib/uucp/paths which is the smail
- # default. If you're going to put this in /usr/lib/uucp, I suggest
- # (rather than make /usr/lib/uucp writeable by everybody), doing
- # the following:
- # su root
- # cd /usr/lib/uucp
- # touch paths
- # chown news paths (or usenet)
- # chmod 644 paths
- PATHFILE=/usr/lib/uucp/paths
- # Auxiliary options to pathalias. Tune to local tastes....
- PATHOPTS="-dwatmath"
- # If you have a version[s] of your machine's map entry that is different
- # from what's published, change this variable to point at it/them.
- # (Eg: I publish the first entry here, and the second one is local tuning
- # and hidden connections)
- PATHLOCAL="/usr2/clewis/maps/path.local /usr2/clewis/maps/path.nonpublic"
- # If this variable is set to the compress binary, maps will be
- # compressed. DO NOT define this unless you've applied the accompanying
- # patch to your version 9 pathalias source, and you've set the path
- # in config.h to point at the same place.
- COMPRESS=/usr2/clewis/maps/compress12
- # 1 to strip comments from maps - don't do this if you ever try
- # to read the maps and figure out where the site is, their contacts
- # etc.
- NOCOMMENTS=0
- # PS: there is *one* possible edit that you might want to make
- # below - the maps used to generate wierd domains, but most of that
- # appears to be gone now (don't ask me, I never particularly understood
- # it, but since Peter Honeyman recommended it...). If you object
- # to these wierd domains, uncomment the egrep.
-
- # Edit no more....
-
- umask 022
-
- PATH=/bin:/usr/bin
- export PATH
-
- if test ! -d $MAPDIR -o ! -w $MAPDIR
- then
- echo "$MAPDIR missing, unwritable or not a directory" >&2
- exit
- fi
-
- if [ $# = 1 ]
- then
- case $1 in
- -p)
- forcepath=true
- ;;
- -i)
- cd /
- rm -f $BATCH.work
- # using find/sort instead of ls just in case there's lots of
- # articles....
- find $NEWSSPOOL/comp/mail/maps -type f -print | sort > $BATCH
- ;;
- *)
- echo "usage: unpackmaps [-i] [-p]" >&2
- exit 1
- ;;
- esac
- fi
-
- cd $MAPDIR
-
- while [ -f $BATCH -o -f $BATCH.work ]
- do
- # There is no window of vulnerability here as long as noone else is
- # creating $BATCH.work.
- if [ ! -f $BATCH.work ]
- then
- mv $BATCH $BATCH.work
- fi
-
- while read i stuff
- do
- # Using stuff to capture remaining junk on line.
- # Eg: C-news article sizes.
-
- if [ -z "$i" ]
- then
- break
- fi
-
- if [ ! -r $i ]
- then
- echo "$i apparently superseded or expired"
- continue
- fi
-
- # This awk script depends on the following map article format:
- # <don't cares>
- # cat << 'something' > filename
- # map body
- # something
- # <don't cares>
- # "something" doesn't have to be enclosed in quotes in the cat line.
- # This isn't particularly fast - could be dramatically speeded up
- # if written in C, but I was trying to ensure that this is as simple
- # and self-evident as possible.
-
- awk '
- $1 == "cat" {
- endtoken=$3;
- if (substr(endtoken, 1, 1) == "'"'"'")
- endtoken=substr(endtoken, 2, length(endtoken)-2);
- collecting = 1;
- foundone = 1;
- name = $5;
- if (index(name, "/") != 0) {
- printf("Security violation attempt in %s!\n", "'$i'");
- exit;
- } else
- printf("extracting %s from %s\n", name, "'$i'");
- next;
- }
-
- {
- if (!collecting)
- next;
- if ($1 == endtoken) {
- line = "rm -f " name ".Z"
- print "" | line
- collecting = 0;
- next
- }
- if ("'$NOCOMMENTS'" == 1 && $0 ~ /#/)
- print substr($0, 1, index($0, "#")) > name
- else
- print $0 > name
- }
-
- END {
- if (collecting) {
- printf("Non-terminated map in %s\n", "'$i'");
- }
- if (!foundone) {
- printf("%s does not contain a properly formed map\n", "'$i'");
- }
- }' $i
- done < $BATCH.work
- rm $BATCH.work
- done > /tmp/unpA$$ 2>&1
-
- if test -n "$PATHALIAS" -a -x "$PATHALIAS"
- then
- if test -s /tmp/unpA$$ -o -n "$forcepath"
- then
- cd $MAPDIR
-
- (
- $PATHALIAS -f $PATHOPTS ?.* $PATHLOCAL |
-
- # format of the pathalias -f output is
- # cost host route
- #
- # format of a 'paths' file for smail is
- # host route first_hop_cost
- #
- # move cost field to end of line:
-
- sed 's/\(.*\) \(.*\) \(.*\)/\2 \3 \1/' |
-
- # convert target domain/host to lower case:
-
- #lcasep |
-
- # remove some additional wierdnesses (per Peter Honeyman):
- # You can leave it in or not.
-
- # egrep -v '(\.(com|edu|mil|gov|net|org|arpa|[a-z][a-z]) .*!.*!)|(.\.(com|edu|mil|gov|net|org|arpa|[a-z][a-z]) )' |
-
- # sort the stream:
-
- sort > /tmp/paths ) > /tmp/unpB$$ 2>&1
-
- if test ! -s /tmp/paths
- then
- echo "Pathalias failed no map file created" >> /tmp/unpB$$
- else
- cat /tmp/paths > $PATHFILE 2>> /tmp/unpB$$
- if test $? != 0
- then
- echo "Copy to $PATHFILE failed" >> /tmp/unpB$$
- else
- rm /tmp/paths
- fi
- echo "Map remade" >> /tmp/unpB$$
- fi
-
- if test -s /tmp/unpB$$
- then
- echo "Pathalias output:" >> /tmp/unpA$$
- cat /tmp/unpB$$ >> /tmp/unpA$$
- fi
- fi
- fi
-
- if test -x "$COMPRESS"
- then
- files=`ls ?.* | sed -e '/\.Z$/d'`
- if [ -n "$files" ]
- then
- $COMPRESS -f $files
- fi
- fi
-
-
- if test -s /tmp/unpA$$
- then
- mail $NOTIFY < /tmp/unpA$$
- fi
-