#!/bin/ksh 

umask 022

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

VERSION="3.8"
if [ "$BS_PKG" = "381" ] ; then
  VERSION="3.81"
fi

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


function Header
{
	tput clear
	print
	print "\t\t\tInterScan VirusWall $VERSION"
	print
	print "\t\t\t    Utility Script"
	print
	print " ---------------------------------------------------------------------"
	print
}


function ChkResp
{
	typeset firstchar

	firstchar=`echo $1 | cut -c1`
	if [[ "$firstchar" = "" ]] ; then
		RESP=$2 
	fi
	case $1 in
	[yY]* )
		RESP=YES ;;
	[nN]* )
		RESP=NO ;;
	[qQ]* )
		RESP=QUIT ;;
        * )
		RESP=$2 ;;
	esac
}

function Change_path
{
	print -n "\n"
	print -n "	New mail queue path [             ]\b\b\b\b\b\b\b\b\b\b\b\b\b\b" ; read RESP

	M_PATH=`echo $RESP | grep "^/.*$"`
	if [[ "$M_PATH" = "" || "$M_PATH" = "0" ]] ; then
		print "\n Please enter correct path. \n"
		PressAnyKey
		return 0
	else

		print -n "\n"
		print -n "	Do you want to continue to change mail queue to  $M_PATH \n"
		print -n "	And restart InterScan all daemons ? [     ]\b\b\b\b\b" ; read RESP

		ChkResp $RESP "YES"
		if [ "$RESP" != "YES" ] ; then
			return 0
		fi
	fi

	print "\n\tPlease wait a minutes.... \n"
	/etc/iscan/changemq $M_PATH
	print "\n\tMail queue changed. \n"
	PressAnyKey
	
	return 0
}


function Main
{


    while ( true ); do
	MAIL_Q_PATH=`awk -F= '/^mail_queue_path.*/ { print $2 }' /etc/iscan/intscan.ini`
	Header
    	print "\tInterScan VirusWall $VERSION mail queue change utility\n"

	print "\n\tCurrent mail queue directory is :\t${BOLD}${MAIL_Q_PATH}${UNBOLD}\n"

    	print "\n\tTo change the mail queue , all InterScan daemon need to be restarted,"
    	print "\tand will take a minutes.\n"
    
    	print
    	{
    	 print "\t1.Change mail queue and restart all InterScan daemons."
    	 print "\t2.Exit utility."
    	} >&2
    	print 
    	print -n "		Select a number [   ]\b\b\b" ; read RESP
    
    	case $RESP in
    	1 ) Change_path MAX ;;
    	2 ) exit 1 ;;
    	* ) print "${BELL}\t\tPlease type a valid choice"
    	esac
    done
}
########        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

Main
