#!/bin/sh -e

if [ ! "$1" = "configure" ] && [ ! "$1" = "reconfigure" ]; then exit 0; fi

. /usr/share/debconf/confmodule

# if nsca's init script is already configured, we must reflect 
# that as the source of configuration, not debconf itself.
# this function figures that out.
run_nsca(){
	set +e
	invoke-rc.d --query nsca start 2>/dev/null
	invoke_said=$?
	set -e
	
	case $invoke_said in
	# 101 == disabled
	101)
		echo "false"
	;;
	# 104 == enabled
	104)
		echo "true"
	;;
	# anything else is "undefined", so we then use our defaults
	*)
		if which nagios >/dev/null 2>&2 || which nagios2 >/dev/null; then
			echo "true"
		else
			echo "false"
		fi
	;;
	esac
}

db_set nsca/run-nsca-daemon `run_nsca`
db_input medium nsca/run-nsca-daemon || true
db_go || true
