#!/bin/ksh 

umask 022

typeset DASH="--------"
typeset BOLD=`tput bold`
typeset UNBOLD=`tput rmso`
typeset RESP

typeset ISBASE="None"
typeset ISFTP="None"
typeset ISADMIN="None"
typeset ISHTTP="None"
typeset ISSMTP="None"
typeset ISTVCS="None"
typeset ISCVP="None"
typeset MAIL_Q_PATH=""

function PressAnyKey
{
	print
	print -n "Press Enter to continue ..... " ; read
}

function CheckSW
{
  if [ -s /etc/iscan/pkg/ISBASE ] ; then
	ISBASE="Installed"
  fi 

  if [ -s /etc/iscan/pkg/ISFTP ] ; then
	ISFTP="Installed"
  fi 

  if [ -s /etc/iscan/pkg/ISSMTP ] ; then
	ISSMTP="Installed"
  fi 

  if [ -s /etc/iscan/pkg/ISHTTP ] ; then
	ISHTTP="Installed"
  fi 

  if [ -s /etc/iscan/pkg/ISADMIN ] ; then
	ISADMIN="Installed"
  fi 

  if [ -s /etc/iscan/pkg/ISTVCS ] ; then
	ISTVCS="Installed"
  fi 

  if [ -s /etc/iscan/pkg/ISCVP ] ; then
	ISCVP="Installed"
  fi 
}


function Main
{

	CheckSW

	#echo "New mail queue is $MAIL_Q_PATH."

        if [ ! -d $MAIL_Q_PATH ] ; then
		#echo "Creating directory $MAIL_Q_PATH"
		mkdir -p $MAIL_Q_PATH
	fi
	chown root $MAIL_Q_PATH
	chmod 600 $MAIL_Q_PATH

	#echo "Stopping InterScan daemon"
	if [ "$ISCVP" = "Installed" ] ; then
		#echo "Stopping InterScan CVP."
		/etc/iscan/S99IScvp stop > /dev/null
	else
		if [ "$ISFTP" = "Installed"  ] ; then 
			#echo "Stopping InterScan FTP."
			/etc/iscan/S99ISftp stop > /dev/null
		fi
		if [ "$ISHTTP" = "Installed" ] ; then
			#echo "Stopping InterScan HTTP."
			/etc/iscan/S99ISproxy stop > /dev/null
		fi
		if [ "$ISSMTP" = "Installed" ] ; then
			#echo "Stopping InterScan SMTP."
			/etc/iscan/S88sendmail stop > /dev/null
		fi
	fi
	if [ "$ISTVCS" = "Installed"  ] ; then 
		#echo "Stopping InterScan TVCS."
		/etc/iscan/S99IStvcs stop > /dev/null
	fi
	/etc/iscan/S99ISmaild stop > /dev/null


	#echo ""
	#echo "Modyfing intscan.ini"
	#echo ""
	
	OLD_MAIL_Q_PATH=`awk -F= '/^mail_queue_path.*/ { print $2 }' /etc/iscan/intscan.ini`
	/etc/iscan/getconf -s $MAIL_Q_PATH notification mail_queue_path   	> /dev/null
	if [ -f $OLD_MAIL_Q_PATH/* ] ; then
		cp -p $OLD_MAIL_Q_PATH/* $MAIL_Q_PATH/
	fi


	#echo "Starting InterScan daemon"
	if [ "$ISCVP" = "Installed" ] ; then
		#echo "Starting InterScan CVP."
		/etc/iscan/S99IScvp start > /dev/null
	else
		if [ "$ISFTP" = "Installed"  ] ; then 
			#echo "Starting InterScan FTP."
			/etc/iscan/S99ISftp start > /dev/null
		fi
		if [ "$ISHTTP" = "Installed" ] ; then
			#echo "Starting InterScan HTTP."
			/etc/iscan/S99ISproxy start > /dev/null
		fi
		if [ "$ISSMTP" = "Installed" ] ; then
			#echo "Starting InterScan SMTP."
			/etc/iscan/S88sendmail start > /dev/null
		fi
	fi
	if [ "$ISTVCS" = "Installed"  ] ; then 
		#echo "Starting InterScan TVCS."
		/etc/iscan/S99IStvcs start > /dev/null
	fi
	/etc/iscan/S99ISmaild start > /dev/null

	if [ -f $OLD_MAIL_Q_PATH/* ] ; then
		rm -rf $OLD_MAIL_Q_PATH/*
	fi

}
########        Main Program    ########

id | grep root > /dev/null 2>&1
if [ $? -ne 0 ] ; then
    echo "You must be super-user (root) to execute this script."
    exit 1
fi


if [ $# = 0 ] ; then
	echo "No path specified"
	exit 1
fi 
MAIL_Q_PATH=$1

Main
exit 0

