#!/bin/sh
set -e

CONFIG=/etc/put-dns/put-dns.conf

case "$1" in
    configure)
    . /usr/share/debconf/confmodule
    db_get put-dns/update-domain
    if [ "$RET" = "true" ]; then
        # Check if 'domain' in CONFIG is localhost and if not see if it
        # can be initailised to a sensible value
        INIDOMAIN=`crudini --get $CONFIG main domain`
        if [ "$INIDOMAIN" = "localdomain" ]; then
          # domain in the conf file is not a valid external one
          HOSTDOMAIN=`hostname -d`
          case "$HOSTDOMAIN" in
          localdomain|local|example.com|example.org|example.net)
         
          ;;
          *)
          # host domain may be correctly set already, use it
          sed -i -e "/domain = /s/$INIDOMAIN/$HOSTDOMAIN/" $CONFIG
          ;;
          esac
       fi
     fi
    
    ;;

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

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


#DEBHELPER#

exit 0
