#! /bin/sh
set -e

case "$1" in
    configure)

    	. /usr/share/debconf/confmodule
    
	db_get apticron/notification
	EMAIL="$RET"

	if [ ! -d /etc/apticron/ ] ; then
		mkdir /etc/apticron
	fi
	
	if [ ! -e /etc/apticron/apticron.conf ] ; then
		cat <<EOF > /etc/apticron/apticron.conf
# apticron.conf 
#
# set EMAIL to a list of addresses which will be notified of impending updates
#
EMAIL="$EMAIL"

#
# Set LISTCHANGES_PROFILE if you would like apticron to invoke apt-listchanges
# with the --profile option. You should add a corresponding profile to 
# /etc/apt/listchanges.conf
#
# LISTCHANGES_PROFILE="apticron"

#
# Set SYSTEM if you would like apticron to use something other than the output
# of "hostname -f" for the system name in the mails it generates
#
# SYSTEM="foobar.example.com"

#
# Set IPADDRESSNUM if you would like to configure the maximal number of IP 
# addresses apticron displays. The default is to display 1 address of each
# family type (inet, inet6), if available.
#
# IPADDRESSNUM="1"

#
# Set IPADDRESSES to a whitespace seperated list of reachable addresses for 
# this system. By default, apticron will try to work these out using the
# "ip" command
#
# IPADDRESSES="192.0.2.1 2001:db8:1:2:3::1"
EOF
		chmod 644 /etc/apticron/apticron.conf

	else
		sed -i "s/EMAIL=.*/EMAIL=\"$EMAIL\"/" /etc/apticron/apticron.conf
	fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

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

#DEBHELPER#

exit 0
