#!/bin/sh

functions()
	{
		SELFTMP=$0
		ORIGPWD=`pwd`
		REALPWD=`dirname $0`
		cd "$REALPWD"
		while [ -L "$SELFTMP" ]
			do
				SELFTMP=`readlink "$SELFTMP"`
				cd `dirname "$SELFTMP"`
				REALPWD=`pwd -P`
		done

		cd "$ORIGPWD"

		if [ "$INITIALIZED" != "1" ]
			then
				source $REALPWD/inc/functions.sh
		fi
	}

functions

initinstall()
	{
		INITRUNLEVEL=`cat /etc/inittab  |grep -v "^#" |grep initdefault |cut -d":" -f2`
		good ""
		good "Default runlevel seems to be ${HILITE}$INITRUNLEVEL${NORMAL}"
		warn "Please note that existing initscript will be replaced by the new version"
		good ""
		getconfirm "Add Merak Mail Server to runlevel ${HILITE}$INITRUNLEVEL${NORMAL}?" && (
			ln -sf ../../..${MERAKDIR}/scripts/merakd /etc/rc.d/init.d/merakd && ln -sf ../init.d/merakd /etc/rc.d/rc${INITRUNLEVEL}.d/S90merak && good "Initscript installed" || bad "Initscript install problem, check permissions"
		) || warn "User cancelled"
	}
	
initinstall