#!/bin/sh
#
# preinst for dwww
# "@(#)dwww:$Id: dwww.preinst,v 1.5 2005-09-15 22:30:26 robert Exp $"
#

set -e

if [ "$1" = "upgrade" ] && dpkg --compare-versions "$2" lt-nl "1.8.8"; then
 	
	# dwww spool directory was moved in dwww 1.5.0
	if [ -d /var/spool/dwww ] && [ -d /var/cache ] && [ ! -e /var/cache/dwww ]; then
 		echo "Moving dwww cache directory to /var/cache/dwww."
 		mv -f /var/spool/dwww /var/cache/dwww
 	fi

	# remove old configuration files saved by dwww 1.5.0
	for file in "/etc/cron.daily/dwww.saved_by_dwww_preinst" \
  		    "/etc/menu-methods/dwww.saved_by_dwww_preinst" ; do
		if [ -f "$file" ]; then
			echo "Removing $file file";
			rm -f "$file";
		fi
	done

	# remove file generated by a broken dwww 1.8.0
	if [ -f "/index.html" ] && 
	   	grep '<i>Generated by <a href="/dwww/"><b>dwww</b></a> version 1.8.0 ' \
			"/index.html" > /dev/null;  then
		echo "Removing /index.html file generated by broken dwww 1.8.0"
		rm -f "/index.html"
	fi
		
fi
			
if [ "$1" = "upgrade" ] && dpkg --compare-versions "$2" lt-nl "1.9.17"; then
	[ -d /var/cache/dwww ]  && rm -rf /var/cache/dwww
	mkdir -m 755 /var/cache/dwww
	[ -e /var/lib/dwww/dwww.swish++.index ] && \
		mv /var/lib/dwww/dwww.swish++.index /var/cache/dwww
	[ -e /var/lib/dwww/quickfind.dat ] && \
		mv /var/lib/dwww/quickfind.dat /var/cache/dwww
fi		
	

#DEBHELPER#
 
exit 0
