#!/bin/sh
#
# httpd_wais_update					Version 1.0
#
#     -	update WAIS inverted index files.
#	Should be run regularly by cron.
#
# PARAMETERS:
#	none, but uses the IndexMap file created by httpd_wais.
#
# NEEDS THE FOLLOWING PROGRAMS IN $PROGDIR:
#	waisindex.
#
# WRITTEN BY:
#	Ari Luotonen, CERN, 8 Sep 1993, luotonen@dxcern.cern.ch
#
#
# !!! SET THE FOLLOWING VARIABLES TO CORRECT VALUES !!!
#

PROGDIR="/apps/WWW/bin"		# Directory where executables reside
WWW_HOME="/CERN_WWW/CERNWeb"	# Home of WWW document tree
INDEX_HOME="$WWW_HOME/Index"	# Home of inverted index tree

#
# !!! YOU SHOULDN'T NEED TO CHANGE ANYTHING AFTER THIS LINE !!!
#

# Binaries

WAISINDEX="$PROGDIR/waisindex"


# Files

INDEX_MAP="$INDEX_HOME/IndexMap"


# Process every entry in the index map file

while read LINE
do
	set $LINE
	INDEX_FILE=$1
	WWW_DIR=$2

	# Check for existing directories and create if needed

	DIRECTORIES=`echo $INDEX_FILE |
		     awk -F/ '{for(i=1; i<NF; i++) print $i}'`
	DIR=""
	for i in $DIRECTORIES
	do
		DIR=$DIR/$i
		if test ! -d $DIR
		then
			mkdir $DIR
		fi
	done

	# Update the inverted index

	cd $WWW_DIR
	INDEXED_FILES=`find . -name \*.html -a ! -name ,\* -print`
	$WAISINDEX -d $INDEX_FILE -nocat $INDEXED_FILES

done < $INDEX_MAP
