#!/bin/sh

set -e

# debconf
. /usr/share/debconf/confmodule

case "$1" in
    configure)
        # continue below
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
        exit 0
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac

# only on a new install: copy the default search page
if [ -z "$2" ]; then
	if [ -d /var/www -a ! -e /var/www/search.html ]; then
		cp /usr/share/doc/htdig/examples/search.html /var/www
	fi
fi 


# move databases if upgrading
if [ -f /var/spool/htdig/db.docdb -a -f /var/spool/htdig/db.docs.index \
	-a -f /var/spool/htdig/db.wordlist -a -f /var/spool/htdig/db.words.db ]; then
	mv /var/spool/htdig/* /var/lib/htdig
	rmdir /var/spool/htdig
	echo "Moving ht://Dig databases to /var/lib/htdig"
fi

# db exists?
#if [ -f /var/lib/htdig/db.docdb -a -f /var/lib/htdig/db.docs.index \
#	-a -f /var/lib/htdig/db.wordlist -a -f /var/lib/htdig/db.words.db ]; then
#	echo "ht:://Dig endings database found."
#	echo "You can run /usr/sbin/htdigconfig to recreate them."
#	exit 0
#fi

# generate ht://Dig databases now?
db_get htdig/generate-databases
if [ "$RET" = "true" ]; then
	/usr/sbin/htdigconfig
fi


#DEBHELPER#

