Subject: Re: bin/5231: makewhatis does not deal with multiple MANDIR's
To: Chris G. Demetriou <cgd@pa.dec.com>
From: Tim Rightnour <root@garbled.net>
List: netbsd-bugs
Date: 03/31/1998 05:32:45
Well, once again I've had quite a learning experience from my little attempt to
fix something here.. I do appreciate the suggestions though, I'd much rather do
it correctly, then have something broken comitted.

I'll try one more time.. This time I've retained the old behavior of only
working on the directory noted by the command line, in addition, if no command
line is given, it now works off man.conf. I had to keep the sed trick rather
than using "dirname" because dirname would strip the "man" off /usr/local/man.

The only bug I forsee in this, is that if you munge the dirname on the command
line, it is going to rebuild all of them.

Apologies for spamming the lists with this..


#! /bin/sh
#
#       $NetBSD: makewhatis.sh,v 1.13 1998/03/21 23:46:00 tron Exp $
#
# Recent changes by Tim Rightnour 03/29/1998 to make it work on multiple
# man dirs. Slight cleanup as well.
#
# written by matthew green <mrg@eterna.com.au>, based on the
# original by J.T. Conklin <jtc@netbsd.org> and Thorsten
# Frueauf <frueauf@ira.uka.de>.
#
# Public domain.
#

# The variables below make it slightly easier to put in local hacks to 
# getname and the sed routines.

GETNAME=/usr/libexec/getNAME
SEDFILE=/usr/share/man/makewhatis.sed
LIST=/tmp/makewhatislist$$
TMP=/tmp/whatis$$
trap "rm -f $LIST $TMP; exit 1" 1 2 15

# first perform a quick sanity check, and make sure all the dirs exist.
# could do all of this in one loop, But we waste no CPU if the last path
# element is bogus this way.

if test -d "$1" ; then
   MANX=$1
else
   MANX=`awk '/^_whatdb/ { print $2 }' /etc/man.conf`
   for TMPWHAT in $MANX
   do
        TMPDIR=`dirname $TMPWHAT`
        if test ! -d "${DESTDIR}$TMPDIR"; then 
           echo "makewhatis: ${DESTDIR}$TMPDIR: not a directory"
           exit 1
        fi
   done
fi

# now make the list.

for TMPWHAT in $MANX
do
    rm -f $TMP $LIST
    TMPDIR=`echo $TMPWHAT | sed 's/\/whatis.db//'`
    echo $TMPDIR
    find ${DESTDIR}$TMPDIR \( -type f -o -type l \) -name '*.[0-9]*' -ls | \
        sort -n | awk '{if (u[$1]) next; u[$1]++ ; print $11}' > $LIST

    egrep '\.[1-9]$' $LIST | xargs ${GETNAME} | \
        sed -e 's/ [a-zA-Z0-9]* \\-/ -/' > $TMP

    egrep '\.0$' $LIST | while read file
    do
        sed -n -f ${DESTDIR}${SEDFILE} $file;
    done >> $TMP

    egrep '\.[0].(gz|Z)$' $LIST | while read file
    do
        gzip -fdc $file | sed -n -f ${DESTDIR}${SEDFILE};
    done >> $TMP

    sort -u -o $TMP $TMP

    install -o bin -g bin -m 444 $TMP "$TMPDIR/whatis.db"
done

rm -f $LIST $TMP
exit 0


---
Tim Rightnour    -  root@garbled.net
http://www.zynetwc.com/~garbled/garbled.html