#!/bin/bash

set -e


if [ "$1" == "upgrade" -o "$1" == "install" ]; then
	if [ "$2" != "" ] && dpkg --compare-versions "$2" lt 3.1.1; then
		if [ "$1" == "upgrade" ]; then
			echo "WARNING! You are about to upgrade htdig."
			echo "This new package uses a different database library or format, so"
			echo "you won't be able to search your databases until you've rebuilt them"
			echo -n "Do you want to install this package now [y/N] ?"
			read a
			if echo $a | grep -qvi "^y"; then
				echo "Ok, refusing upgrade as you requested"
				exit 1
			fi
			echo "Don't forget to rebuild your search databases!"
		fi
		cp -a /usr/lib/htdig /etc/htdig
		rm -f /etc/htdig/*.gdbm
	fi		
	if [ "$2" != "" ] && dpkg --compare-versions "$2" lt 3.1.2; then
		echo "WARNING! I'm moving the configuration file from /etc to /etc/htdig"
		cp /etc/htdig.conf /etc/htdig.conf.dpkg-save
		mv /etc/htdig.conf /etc/htdig
	fi
fi

#DEBHELPER#

exit 0
