#!/bin/sh
# vim: syntax=sh ts=4 sw=4 sts=4 sr noet
# preinst script for arno-iptables-firewall
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


# Move a conffile. In case of an unmodified file simply
# remove it to not trigger dpkg questions.
# However, if the file is modified this question should occur.
mv_conffile() 
{
	CONFFILE="$1"
	NEWLOCATION="$2"

	if [ -e "$CONFFILE" ]; then
		md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`"
		old_md5sum=$(dpkg-query -W -f='${Conffiles}' arno-iptables-firewall | grep ${CONFFILE} | awk '{ print $2 }')
		if [ "$md5sum" = "$old_md5sum" ]; then
			rm -f "$CONFFILE"
		else
			mv "$CONFFILE" "$NEWLOCATION"
		fi
	fi
}

case "$1" in
	install|upgrade)
		if dpkg --compare-versions "$2" le-nl "2.0.1.f-1.1"; then
			if [ -e /etc/logrotate.d/arno-iptables-firewall.conf ]; then
				echo "Renaming old logrotate configuration to a new name."
				mv_conffile /etc/logrotate.d/arno-iptables-firewall.conf /etc/logrotate.d/arno-iptables-firewall
			fi
		fi
	;;

	abort-upgrade)
	;;

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

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0 
