#!/bin/sh

set -e

### XXXX: it is always a good idea to wrap operations around file, checking if the file exists.
### some packages create their config file at postinst phase, but none of the install tools (dpkg/apt-get)
### will ensure that the Packages: you Depends: on are already configured before your pkg will be configured.

if [ "$1" ] && [ -z "$2" ]; then

	if [ -e /etc/dhcp3/dhcpd.conf ]; then
		if ! grep --quiet "/etc/sbs/named.conf.sbs" /etc/dhcp3/dhcpd.conf; then
			echo "" >> /etc/dhcp3/dhcpd.conf
			echo "# Include Small Business Server DHCP Confguration File. (/etc/sbs/sbsdhcpd.conf)" >> /etc/dhcp3/dhcpd.conf
			echo "include \"/etc/sbs/sbsdhcpd.conf\";" >> /etc/dhcp3/dhcpd.conf
			### XXXX: you probably want to restart the service here ###
			### :D Not here, Services will be restarted after wizard. 
		fi
	fi

	### XXXX: fresh bind installations has named.conf.local that is preferred to named.conf.
	### try to use .local before the standard.
	BINDCONF=""
	if [ -e /etc/bind/named.conf.local ]; then
		BINDCONF="/etc/bind/named.conf.local"
	elif [ -e /etc/bind/named.conf ]; then
		BINDCONF="/etc/bind/named.conf"
	fi
	
	### XXXX: we proceed only if there is a config file.
	if [ -n "$BINDCONF" ]; then
		if ! grep --quiet "/etc/sbs/named.conf.sbs" $BINDCONF; then
			echo "" >> "$BINDCONF"
			echo "// Include Small Business Server DNS Confguration File (/etc/sbs/named.conf.sbs)." >> "$BINDCONF"
			echo "include \"/etc/sbs/named.conf.sbs\";" >> "$BINDCONF"
	
			### XXXX: you probably want to restart the service here.
			### :D Not here, Services will be restarted after wizard. 
		fi
	fi

	echo "wizards=Wizards" >> /etc/webmin/webmin.catnames
	
	### XXXX: be sure that update-webmin is installed and executable otherwise
	### a bad call will result in our pkg not being installed and configured.
	
	if [ -x /usr/sbin/update-webmin ]; then
		/usr/sbin/update-webmin add domaincontroller
	fi

fi
	
exit 0
	
#DEBHELPER#
