#!/bin/sh
# $Id: postinst,v 1.13 2004-08-08 17:21:13 robert Exp $
set -e

#DEBHELPER#

. /usr/share/debconf/confmodule

if [ "$1" != "configure" ] ; then 
	db_stop || true
	exit 0  
fi

if dpkg --compare-versions "$2" lt-nl "1.5k-1" ; then
	rm -f /var/cache/man2html/manindex* /var/cache/man2html/whatis*

	# remove old unused glimpse files
	rm -f /var/cache/man2html/.glimpse*
fi


if [ -e /var/cache/man2html/ ] \
	&& [ -x /usr/bin/index++ ] \
	&& [ ! -e /var/cache/man2html/man2html.swish++.index ] \
	&& [ ! -e /var/cache/man2html/man2html.swish++.index.tmp ]; then
	db_get man2html/index_manpages || true
	db_stop || true
	if [ "$RET" = "true" ]; then
		tf=`tempfile -p 'm2h-' -s '.swish++.out'`
		echo "Running index++ in the background to index your manpages"
		echo "(redirected to $tf)."
		

		if [ -e /usr/local/man ]; then
			LOCALMAN=$(find /usr/local/man -type d -name "man?")
		fi
		
		if [ -e /usr/local/share/man ]; then
			LOCALSMAN=$(find /usr/local/share/man -type d -name "man?")
		fi
		
		
		index++ --config-file=/usr/share/man2html/swish++.conf \
			/usr/share/man/man* \
			/usr/man/man* \
			/usr/X11R6/man/man* $LOCALMAN $LOCALSMAN 2>&1 > "$tf" &
	fi
else
	db_stop || true
fi

exit 0
