+#!/bin/sh
+# postinst script for bind9-cn
+#
+# 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|reconfigure)
+ # continue below
+ ;;
+
+ *)
+ exit 0
+ ;;
+esac
+
+# import CN-functions
+. /usr/share/carnet-tools/functions.sh
+
+# check if monitrc is an empty template
+installfile=1
+if [ -e /etc/monit/monitrc ]; then
+ lines=$(grep -v '^#' /etc/monit/monitrc | wc -l)
+ if [ $lines -lt 2 ]; then
+ installfile=1
+ mv -f /etc/monit/monitrc /etc/monit/monitrc.dpkg-old
+ else
+ installfile=0
+ fi
+fi
+if [ $installfile -eq 1 ]; then
+ echo "CN: Installing default monitrc in /etc/monit/monitrc"
+ cp -a /usr/share/monit-cn/monitrc /etc/monit/monitrc
+ chmod u=rw,go= /etc/monit/monitrc
+fi
+
+# generate monit.d files
+update-monit.d
+
+# disable monit startup
+cp_check_and_sed '^startup=1/#startup=1/g' /etc/default/monit \
+ || true
+
+# install as inittab service
+if ! grep -q '/usr/sbin/monit' /etc/inittab; then
+ if [ -x "/etc/init.d/monit" ]; then
+ update-rc.d -f monit remove >/dev/null 2>&1
+ if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+ invoke-rc.d monit stop || true
+ else
+ /etc/init.d/monit stop || true
+ fi
+ fi
+ echo "CN: Installing monit service in /etc/inittab"
+ rm -f /etc/inittab.$$
+ cp /etc/inittab /etc/inittab.$$
+ cp-update monit-cn /etc/inittab.$$ <<EOF
+mo:2345:respawn:/usr/sbin/monit -Ic /etc/monit/monitrc
+m0:06:wait:/usr/sbin/monit -Ic /etc/monit/monitrc stop myprocess
+EOF
+ cp_mv /etc/inittab.$$ /etc/inittab
+fi
+
+# reload init, since we have new configuration
+echo "CN: Starting monit service, please check /var/log/daemon.log"
+kill -HUP 1
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0