#!/bin/sh -e

. /usr/share/debconf/confmodule 

if [ "$1" = "configure" ]
then 
   # reset restart help
	db_clear shorewall/dont_restart || true
   db_go

	# if we are upgrading from version < 1.4 warns the user
	if [ "$2" ] && dpkg --compare-versions "$2" lt "1.4.0-1"
	then
		db_input critical shorewall/upgrade_to_14 || true
 		db_go 
 
		db_get shorewall/upgrade_to_14 || true
		if [ "$RET" = "false" ]
		then
			db_input critical shorewall/dont_restart || true
			db_go 
		fi

		# check if an old rfc1918 file has been left in /etc/shorewall
		# bug #308380
		if [ -f /etc/shorewall/rfc1918 -a "`cat /etc/shorewall/interfaces | grep -v "#" | grep  norfc1918`" != ""] ; then
			db_input critical shorewall/warnrfc1918 || true
			db_go 			
		fi

	fi

	# if we are upgrading from version < 2.0 warns the user
	if [ "$2" ] && dpkg --compare-versions "$2" lt "2.0" && dpkg --compare-versions "$2" gt "1.4.0-1"
	then
		db_input critical shorewall/upgrade_14_20 || true
 		db_go 
 
		db_get shorewall/upgrade_14_20 || true
		if [ "$RET" = "false" ]
		then
			db_input critical shorewall/dont_restart || true
			db_go 
		fi
	fi

	# if we are upgrading from version < 2.2 warns the user
	if [ "$2" ] && dpkg --compare-versions "$2" lt "2.1.99" && dpkg --compare-versions "$2" gt "2.0"
	then
		db_input critical shorewall/upgrade_20_22 || true
 		db_go 
 
		db_get shorewall/upgrade_20_22 || true
		if [ "$RET" = "false" ]
		then
			db_reset shorewall/dont_restart || true
			db_input critical shorewall/dont_restart || true
			db_go 
		fi
	fi

fi