#! /bin/sh
# $Id$
# postinst script for ser-0.8.7
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

case "$1" in
    configure)
        adduser --quiet --system --group --disabled-password \
                --shell /bin/false --gecos "SIP Express Router" \
                --home /var/run/ser ser || true

    ;;

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

    ;;

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

# # dh_installdeb will replace this with shell code automatically
# # generated by other debhelper scripts.
# deb_helper is not used here to avoid automatically starting ser after
# the installation (dh_installinit 4.0 , from woody does not support
# --nostart, if you're using a newer version is safe to comment out the 
# rest of the code and add again deb_helper)

# this will be added automatically by dh_installdocs if deb_helper is 
# "enabled"
if [ "$1" = "configure" ]; then
	if [ -d /usr/doc -a ! -e /usr/doc/ser -a -d /usr/share/doc/ser ]; then
		ln -sf ../share/doc/ser /usr/doc/ser
	fi
fi
# end dh_installdocs section
# this will be automativally added by dh_installinit if deb_helper is
# "enabled
if [ -x "/etc/init.d/ser" ]; then
	 update-rc.d ser defaults 23 >/dev/null
	 if ! invoke-rc.d ser restart ; then
		echo ""
		echo "ser failed to (re)start. Perhaps your configuration requires "
		echo "additional modules (e.g. ser-mysql-module, ser-jabber-module "
		echo "or ser-radius-modules). Next try to install any additional ser"
		echo "modules you might need and then (re)start ser by executing "
		echo "the command '/etc/init.d/ser start|restart'."
	fi
fi
# end dh_installinit section

exit 0