#!/bin/sh -e

#DEBHELPER#

# Make sure we should be running...
case "$1$2" in
upgrade*)
    if dpkg --compare-versions $2 lt 2.3.0
    then
	# Source debconf library.
	. /usr/share/debconf/confmodule

	db_get tripwire/upgrade
	case "$RET" in
	false)
	    exit 1;
	    ;;

	*)
	    etc=/etc/tripwire
	    if [ -f $etc/tw.config ]; then
		mv $etc/tw.config $etc/tw.config-1.2
		rm -f /etc/tw.config
	    else 
		[ -f /etc/tw.config ] && mv /etc/tw.config $etc/tw.config-1.2
	    fi
	    lib=/usr/lib/tripwire
	    [ -f $lib/tripwire ] && [ ! -f $lib/tripwire-1.2 ] \
		&& mv $lib/tripwire $lib/tripwire-1.2
	    [ -f $lib/ztripwire ] && [ ! -f $lib/ztripwire-1.2 ] \
		&& mv $lib/ztripwire $lib/ztripwire-1.2
	    man=/usr/share/man/man8
	    [ -f $man/tripwire.8.gz ] && [ ! -f $man/tripwire-1.2.8.gz ] \
		&& mv $man/tripwire.8.gz $man/tripwire-1.2.8.gz
	    cron=/etc/cron.daily/tripwire
	    sed -e "s!$lib/z*tripwire!&-1.2 -c $etc/tw.config-1.2!" < $cron > $cron-1.2
 	    rm $cron
	    ;;

	esac
    fi
    ;;

esac
