#! /bin/sh
# postinst script for Xymon
#
# 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

case "$1" in
    configure)
        # Setup permissions for the newly created "xymon" user to write
	# data where he needs to.
	# And for the Apache-run CGI's to generate reports.
	test -d /var/run/xymon || mkdir /var/run/xymon
	chown xymon:xymon /var/run/xymon
	test -d /var/log/xymon || mkdir /var/log/xymon
	chown xymon:adm /var/log/xymon ; chmod 2755 /var/log/xymon

	cd /var/lib/xymon; chown xymon:xymon . acks data disabled hist histlogs hostdata logs rrd tmp www
	cd /var/lib/xymon/www; chown xymon:xymon html notes wml rep snap; chgrp www-data rep snap; chmod g+w rep snap
	cd /etc/xymon; chgrp www-data critical.cfg critical.cfg.bak; chmod g+w critical.cfg critical.cfg.bak

	if ! test -e /etc/xymon/hosts.cfg ; then
		if test -e /etc/default/xymon-client ; then
			. /etc/default/xymon-client || true
		fi
		cat > /etc/xymon/hosts.cfg <<EOF
# Master configuration file for Xymon
#
# This file defines several things:
#
# 1) By adding hosts to this file, you define hosts that are monitored by Xymon
# 2) By adding "page", "subpage", "group" definitions, you define the layout
#    of the Xymon webpages, and how hosts are divided among the various webpages 
#    that Xymon generates.
# 3) Several other definitions can be done for each host, see the hosts.cfg(5)
#    man-page.
#
# You need to define at least the Xymon server itself here.

#0.0.0.0	.default.	# NOPROPRED:+apt,+libs

#group Servers
127.0.0.1	$CLIENTHOSTNAME	# bbd http://$CLIENTHOSTNAME/

#group Dialup
#0.0.0.0	notebook.bla.net # noconn dialup
EOF
	fi

	test -e /etc/xymon/xymonpasswd || touch /etc/xymon/xymonpasswd
	test -e /etc/xymon/xymongroups || touch /etc/xymon/xymongroups
	if test -e /etc/init.d/apache2 ; then
	    a2enmod rewrite || :
	    invoke-rc.d apache2 reload || :
	fi
    ;;

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

    ;;

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

#DEBHELPER#

exit 0
