#! /bin/sh
# postinst script for noris-server
#
# 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)
	# nrpe konfigurieren
	/etc/init.d/inetd stop
	sleep 1
	grep -e "^nrpe" /etc/inetd.conf > /dev/null || \
	echo "nrpe	stream	tcp	nowait	root	/usr/sbin/tcpd	/usr/sbin/nrpe -i /etc/nrpe.cfg" >> /etc/inetd.conf
	grep -e '^nrpe.*5666\/tcp' /etc/services > /dev/null || \
	echo "nrpe		5666/tcp			# NETSAINT" >> /etc/services
	/etc/init.d/inetd start
	# ssh
	cp /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-old
	sed -e 's/X11Forwarding\ no/X11Forwarding\ yes/g' /etc/ssh/sshd_config.dpkg-old > /etc/ssh/sshd_config
	/etc/init.d/ssh reload
	# inittab
	cp /etc/inittab /etc/inittab.dpkg-old
	sed -e 's#getty\ 38400#getty\ -f\ \/etc\/issue\.linuxlogo\ 38400#g;s#^\#T0\:23\:respawn\:\/sbin\/getty\ \-L\ ttyS0\ 9600\ vt100#T0\:23\:respawn\:\/sbin\/getty\ \-L\ ttyS0\ 9600\ vt100#g' /etc/inittab.dpkg-old > /etc/inittab
	/sbin/telinit q
	# firewall konfigurieren
	chmod 755 /etc/init.d/firewall
	update-rc.d firewall defaults 12 88
    ;;

    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.

#DEBHELPER#

exit 0


