#!/bin/sh

#
# rundig
#
# $Id: rundig,v 1.7.4.3 2001/02/20 00:54:23 ghutchis Exp $
#
# This is a sample script to create a search database for ht://Dig.
#
DBDIR=@DATABASE_DIR@
COMMONDIR=@COMMON_DIR@
BINDIR=@BIN_DIR@

# To help debug problems, try running rundig -vvv
# This will add lots of debugging output to all of the programs
stats= opts= alt=
for arg
do
    case "$arg" in
    -a)  alt="$arg" ;;
    -s)  stats="$arg" ;;
    *)   opts="$opts $arg" ;;	# e.g. -v or -c config
    esac
done

#
# Set the TMPDIR variable if you want htdig and other programs to put 
# files in a location other than the default.  This is important if
# you are running this script as root, since /tmp is usually not
# secure.  Also, be aware that on some systems, /tmp is a memory
# mapped filesystem that takes away from virtual memory.
#
TMPDIR=$DBDIR
export TMPDIR

$BINDIR/htdig -i $opts $stats $alt
$BINDIR/htpurge $opts $alt
case "$alt" in
-a)
  ( cd $DBDIR && test -f db.docdb.work &&
    for f in *.work
    do
        mv -f $f `basename $f .work`
    done
    test -f db.words.db.work_weakcmpr &&
	mv -f db.words.db.work_weakcmpr db.words.db_weakcmpr) ;;
esac
$BINDIR/htnotify $opts
# If you want to use the soundex and (or) metaphone fuzzy matchings,
# Uncomment the following line
# $BINDIR/htfuzzy $opts soundex metaphone

#
# Create the endings and synonym databases if they don't exist
# or if they're older than the files they're generated from.
# These databases are semi-static, so even if pages change,
# these databases will not need to be rebuilt.
#
if [ "`ls -t $COMMONDIR/english.0 $COMMONDIR/word2root.db 2>/dev/null | sed 1q`" = \
	"$COMMONDIR/english.0" ]
then
    $BINDIR/htfuzzy $opts endings
fi

if [ "`ls -t $COMMONDIR/synonyms $COMMONDIR/synonyms.db 2>/dev/null | sed 1q`" = \
	"$COMMONDIR/synonyms" ]
then
    $BINDIR/htfuzzy $opts synonyms
fi
