#!/bin/ksh 

umask 022

typeset	ISBASE_ENV="/tmp/isbase.env"
if [ "x$LANG" = "xja" -o "x$LANG" = "xjapanese" ] ; then
	export IS_LANG="JP"
else
	export IS_LANG="EN"
fi

typeset	TRIAL_EXT="evl"

typeset DASH="--------"
typeset BOLD=`tput bold`
typeset UNBOLD=`tput rmso`
typeset BELL=`tput bel`

typeset BASEPKG="isbase.tz"
typeset FTPPKG="isftp.tz"
typeset ADMINPKG="isadmin.tz"
typeset HTTPPKG="ishttp.tz"
typeset SMTPPKG="issmtp.tz"
typeset TVCSPKG="istvcs.tz"
typeset CVPPKG="iscvp.tz"
typeset TRIAL="NO"
typeset INSTALLCVP="NO" 

typeset ISBASE="None"
typeset ISFTP="None"
typeset ISADMIN="None"
typeset ISHTTP="None"
typeset ISSMTP="None"
typeset ISTVCS="None"
typeset ISCVP="None"
typeset PKG="IScan ISHTTP ISADMIN ISSMTP ISTVCS ISCVP"

typeset ISFTPTRIAL="0"
typeset ISHTTPTRIAL="0"
typeset ISSMTPTRIAL="0"
typeset ISCVPTRAIL="0"

typeset INSTFTP="NO"
typeset INSTHTTP="NO"
typeset INSTADMIN="NO"
typeset INSTSMTP="NO"
typeset INSTBASE="NO"
typeset INSTTVCS="NO"
typeset INSTCVP="NO"

typeset UPGRFTP="NO"
typeset UPGRHTTP="NO"
typeset UPGRADMIN="NO"
typeset UPGRSMTP="NO"
typeset UPGRBASE="NO"
typeset UPGRTVCS="NO"
typeset UPGRCVP="NO"

typeset VIRUSLOGPATH="/opt/trend/virus"
typeset ISVWROOT="/opt/trend"
typeset PLUGINPATH="/opt/trend/Plug-Ins"
typeset PLUGINSPATH="/etc/iscan_plugins"
typeset PLUGEMRESTORE="/opt/trend/Plug-Ins/EM/restore.sh"
typeset FTPPATH="/opt/trend/ISFTP"
typeset BASEPATH="/opt/trend/ISBASE"
typeset SMTPPATH="/opt/trend/ISSMTP"
typeset HTTPPATH="/opt/trend/ISHTTP"
typeset ADMINPATH="/opt/trend/ISADMIN"
typeset TVCSPATH="/opt/trend/ISTVCS"
typeset CVPPATH="/opt/trend/ISCVP"
typeset UPGRADE="NO"
# NKO CHANGE
typeset PATCHUPGRADE="NO"
typeset ASKYESNO="NO"
typeset OLDBASE=""
typeset OLDHTTP=""
typeset RESTARTFLG="YES"


typeset TVCS_CGI="Register SolarCommand tvcscfg.cgi tvcsinfo.cgi tvcsreg.cgi tvcsun_set.cgi tvcsunint.cgi"
typeset RESP
typeset ISPATH
typeset LICENSE="NOTOK"

# Administration parameter
typeset	NOTIFY_SERVER="localhost"
typeset	NOTIFY_PORT="25"
typeset rootgrp="sys"

function debug
{
	print -n "this is debug $1 message from matt."
}

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

function CheckSW
{
	case $1 in
	ISBASE )
	  if [ -s /etc/iscan/pkg/ISBASE ] ; then
		ISBASE="Installed"
		INSTBASE="NO"
		return
	  fi ;;
	ISFTP )
	  if [ -s /etc/iscan/pkg/ISFTP ] ; then
		ISFTP="Installed"
		INSTFTP="NO"
		return
	  fi ;;
	ISSMTP )
	  if [ -s /etc/iscan/pkg/ISSMTP ] ; then
		ISSMTP="Installed"
		INSTSMTP="NO"
		return
	  fi ;;
	ISHTTP )
	  if [ -s /etc/iscan/pkg/ISHTTP ] ; then
		ISHTTP="Installed"
		INSTHTTP="NO"
		return
	  fi ;;
	ISADMIN )
	  if [ -s /etc/iscan/pkg/ISADMIN ] ; then
		ISADMIN="Installed"
		INSTADMIN="NO"
		return
	  fi ;;
	ISTVCS )
	  if [ -s /etc/iscan/pkg/ISTVCS ] ; then
		ISTVCS="Installed"
		INSTTVCS="NO"
		return
	  fi ;;
	ISCVP ) 
	  if [ -s /etc/iscan/pkg/ISCVP ] ; then
		ISCVP="Installed"
		INSTCVP="NO"
		return
	  fi ;;
	esac  	
}

function ChkConfig
{
	CheckSW ISBASE 
	CheckSW ISFTP 
	CheckSW ISADMIN 
	CheckSW ISHTTP
	CheckSW ISSMTP
	CheckSW ISTVCS
	CheckSW ISCVP
}

function Header
{
	tput clear
	print
	print "\t\t\tInterScan VirusWall 3.7"
	print
	print "\t\t\t    Setup Script"
	print
	print " ---------------------------------------------------------------------"
	print
}

function ChkPath
{
	typeset firstchar

	print -n "\tNew Path is --- " ; read ISPATH
	firstchar=`echo $ISPATH | cut -c1`
	if [ "$firstchar" != "" ] ; then
	   if [ "$ISPATH" = "/etc/iscan" ] ; then
		print ${BOLD}
	   	print -n "\t\t/etc/iscan is the path for InterScan Viruswall internal use only."
		print -n "\t\tPlease change other directory."
		print ${UNBOLD}
		PressAnyKey
		ISPATH=`echo $1`
	   fi

	   if [ "$firstchar" != "/" ] ; then
		print -n "Please type in an ${BOLD}ABSOLUTE PATH${UNBOLD}."
		PressAnyKey
	   	ISPATH=`echo $1`
     	   fi		
	else
	   ISPATH=`echo $1`
	fi
}
#songmei 3/9/2000 user can only choice installation directory as /opt/trend, other directory is fix.
function checkpath
{
	if [ -s /etc/iscan/pkg/ISVWROOT ] ; then
	    ISPATH=`cat /etc/iscan/pkg/ISVWROOT`
	    print -n "\tInterScan is installed in ${ISPATH} " ; 
            PressAnyKey
	else 
	    print -n "\tBy default, InterScan installs in ${ISVWROOT} " ;
            print; 
	    print -n "\tChoose new path or hit ENTER to use default " ;
            print; 
	    ChkPath $ISVWROOT
	fi
	FTPPATH=$ISPATH\/ISFTP
	BASEPATH=$ISPATH\/ISBASE
	HTTPPATH=$ISPATH\/ISHTTP
	SMTPPATH=$ISPATH\/ISSMTP
	ADMINPATH=$ISPATH\/ISADMIN
	TVCSPATH=$ISPATH\/ISTVCS
	CVPPATH=$ISPATH\/ISCVP
	VIRUSLOGPATH=$ISPATH\/virus
	PLUGINPATH=$ISPATH\/Plug-Ins
        PLUGEMRESTORE=$PLUGINPATH\/EM\/restore.sh
	ISVWROOT=$ISPATH
}

#
# MakeUncomment function created by fuka.
#    Argument 1:	filename which must be formatted like intscan.ini.
#    Argument 2: 	line string except "#" for 1st character.
#
function MakeUncomment
{
	__file=$1
	__line=$2

	__param=`grep "^#$__line" $__file | awk -F= '{param=substr($1, 2); print param}'`
	__value=`grep "^#$__line" $__file | awk -F= '{print $2}'`

	if [ "x$__value" = "x" ] ; then
		return 1
	fi

	# NKO CHANGE
	#ex -s $__file << _EOF_ > /dev/null
	ex $__file << _EOF_ > /dev/null
/^#$__line
c
$__param=$__value
.
x
_EOF_

	return 0
}

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 Modify
{

	print -n "	Install InterScan VirusWall for $1? [     ]\b\b\b\b\b" ; read RESP
	case $1 in
	"BASE" ) 	ChkResp $RESP $INSTBASE
		 if [ "$RESP" = "YES" ] ; then
			INSTBASE=YES 

		 else
			INSTBASE=NO
		 fi ;;
	"FTP" ) 	ChkResp $RESP $INSTFTP
		 if [ "$RESP" = "YES" ] ; then
			INSTFTP=YES 
		 else
			INSTFTP=NO
		 fi ;;
	"HTTP" )	ChkResp $RESP $INSTHTTP
		 if [ "$RESP" = "YES" ] ; then
			INSTHTTP=YES 
		 else
			INSTHTTP=NO
		 fi ;;
	"TVCS" )	ChkResp $RESP  $INSTTVCS
		 if [ "$RESP" = "YES" ] ; then
			INSTTVCS=YES 
		 else
			INSTTVCS=NO
		 fi ;;
	"SMTP" )	ChkResp $RESP  $INSTSMTP
		 if [ "$RESP" = "YES" ] ; then
			INSTSMTP=YES 
		 else
			INSTSMTP=NO
		 fi ;;
	"ADMIN" ) 	ChkResp $RESP  $INSTADMIN
		 if [ "$RESP" = "YES" ] ; then
			INSTADMIN=YES 
		 else
			INSTADMIN=NO
		 fi  ;;
	"CVP" ) ChkResp $RESP  $INSTCVP
		if [ "$RESP" = "YES" ] ; then
			INSTCVP=YES
		else
			INSTCVP=NO
		fi ;;
	esac
	return 0
}

function FailMsg 
{
	print "${BOLD}"
	print "\t\tInterScan $1 has been installed but not properly setup in your system, please ask your support channel " 
	print "${UNBOLD}"
}


function StartInstall
{
	# nko 3.7 
	START_MAIL_DAEMON="NO"


	if [[ "$ISBASE" != "Installed" && "$INSTBASE" != "YES" ]] ; then
		print "${BOLD}"
		print "\t\tYou have to install InterScan Virus Base system."
		print "${UNBOLD}"
		PressAnyKey
		return 
	fi
	if [[ "$INSTBASE" = "YES" && "$ISBASE" = "Installed" ]] ; then
		print "\t\tI${BOLD}Scan BASE has been installed in your system${UNBOLD}"
		PressAnyKey
		INSTBASE="NO"
	fi
#	if [[ "$INSTFTP" = "YES" && "$ISFTP" = "Installed" ]] ; then
#		print "\t\t${BOLD}InterScan FTP has been installed in your system${UNBOLD}"
#		PressAnyKey
#		INSTFTP="NO"
#	fi
#	if [[ "$INSTHTTP" = "YES" && "$ISHTTP" = "Installed" ]] ; then
#		print "\t\t${BOLD}InterScan HTTP has been installed in your system${UNBOLD}"
#		PressAnyKey
#		INSTHTTP="NO"
#	fi
#	if [[ "$INSTSMTP" = "YES" && "$ISSMTP" = "Installed" ]] ; then
#		print "\t\t${BOLD}InterScan SMTP has been installed in your system${UNBOLD}"
#		PressAnyKey
#		INSTSMTP="NO"
#	fi
	if [[ "$INSTADMIN" = "YES" && "$ISADMIN" = "Installed" ]] ; then
		print "\t\t${BOLD}InterScan ADMIN has been installed in your system${UNBOLD}"
		PressAnyKey
		INSTADMIN="NO"
	fi

    # if install CVP will not do the following stuff.
      if [ $INSTALLCVP != "YES" ] ; then
	if [ "$INSTBASE" = "YES" ] ; then
		if [[ -d /etc/iscan ]] ; then
	       	     OLDBASE=`pkginfo IScan | awk '{ print $3 " " $4 " " $5 }'` 
			OLDHTTP=`pkginfo IScanHttp | awk '{ print $3 " " $4 }'` 
			print "${BOLD}"
			if [ "$OLDBASE" != "" ] ; then
			   print "\t\tFound older $OLDBASE installed."
			fi
			if [ "$OLDHTTP" != "" ] ; then
			   print "\t\tFound older $OLDHTTP installed."
			fi
			print
			print "${UNBOLD}"
			print -n "		Do you want to upgrade to InterScan VirusWall 3.7 ( yes ) [     ]\b\b\b\b\b" ; read RESP
			ChkResp $RESP "YES"
			if [ "$RESP" = "NO" ] ; then
				return
			fi
			UPGRADE="YES"

			mkdir /tmp/iscan_dir
			cp /etc/iscan/intscan.ini /tmp/iscan_dir
			cp /etc/iscan/iscan.log.* /tmp/iscan_dir
			if [ "$OLDHTTP" != "" ] ; then
				pkgrm IScanHttp 
			fi
			if [ "$OLDBASE" != "" ] ; then
				pkgrm IScan
			fi
			if [ $? -ne 0 ] ; then
			   echo $ERROR_LINE >> /usr/tmp/iscan_install_log
			   print "\t\tGive up Upgrade"
			   PressAnyKey
			   return
			fi
			rm -rf /etc/iscan
		fi

		if [ ! -s ./$BASEPKG ] ; then
			print "\t\tCan not find your InterScan Base system  software ( $BASEPKG ) in current directory." 
			PressAnyKey
			return
		fi

		Header

		# add on Sep 29th, 1999.
		if [ -d /tmp/pkgbase ] ; then
			/bin/rm -rf /tmp/pkgbase
		fi

		( cd /tmp ; mkdir pkgbase )
		/bin/zcat < ./$BASEPKG | ( cd /tmp/pkgbase ; tar xf - )  

		# 
		if [ -f $ISBASE_ENV ] ; then
			rm -f $ISBASE_ENV
		fi
		echo "IS_LANG=$IS_LANG" > $ISBASE_ENV

		pkgadd -d /tmp/pkgbase -R "$BASEPATH" ISBASE
		if [ $? -ne 0 ] ; then
			echo $ERROR_LINE >> /usr/tmp/iscan_install_log
			rm -rf $BASEPATH
		else
			ISBASE=Installed
			if [ ! -s /etc/iscan/pkg/ISVWROOT ] ; then
				echo $ISVWROOT > /etc/iscan/pkg/ISVWROOT
			fi
			if [ ! -d $VIRUSLOGPATH  ] ; then
				mkdir $VIRUSLOGPATH
			fi
			ln -s $VIRUSLOGPATH /etc/iscan/virus

			if [ ! -d $PLUGINPATH ] ; then
				mkdir $PLUGINPATH
  			fi
			if [ ! -d $PLUGINSPATH ] ; then
				mkdir $PLUGINSPATH
  			fi
			
			# Invalid Japanese function. 08/08/2000
			if [ "$IS_LANG" = "EN" ] ; then
			    awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("jp_func=no\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			    cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			    rm -f /tmp/jpfunc.$$
			fi
			Add_Iscan_user   
			chmodbase_root_to_iscan
		fi
               #songmei 3/29/2000 save old intscan.ini to /etc/iscan/old_log_ini
                if [[ -d /tmp/iscan_old ]] ; then
                     if [[ !  -d /etc/iscan/old_log_ini ]] ; then
                        mkdir /etc/iscan/old_log_ini
                     fi
                     if [[ -s /tmp/iscan_old/intscan.ini ]] ; then
                        cp /tmp/iscan_old/intscan.ini /etc/iscan/old_log_ini
                     fi
                fi                            
                #Songmei 3/29/2000 add end

		rm -f $ISBASE_ENV

		if [ "$UPGRADE" = "YES" ] ; then
			/etc/iscan/uplog /tmp/iscan_dir/iscan.log /etc/iscan/virus.log
			cp /tmp/iscan_dir/intscan.ini /etc/iscan/intscan.ini
			/etc/iscan/upgrade /etc/iscan/intscan.ini
			mkdir /etc/iscan/obsolete_log_ini
			cp /tmp/iscan_dir/* /etc/iscan/obsolete_log_ini
			rm -rf /tmp/iscan_dir
		fi
		PressAnyKey
		rm -rf /tmp/pkgbase
		INSTBASE="NO"

		# nko 3.7 
		###########################################
		# Prepare InterScan 3.7 mail deliver daemon
		###########################################
		cp $BASEPATH/IScan.BASE/S99ISmaild /etc/iscan/
		if [ ! -f /etc/rc2.d/S99ISmaild ] ; then
			cp $BASEPATH/IScan.BASE/ISmaild /etc/rc2.d/S99ISmaild
		fi
		if [[ ! -d /etc/iscan/mailq ]] ; then
			mkdir -p $BASEPATH/IScan.BASE/mailq
			chown -R iscan  $BASEPATH/IScan.BASE/mailq
			chgrp -R iscan  $BASEPATH/IScan.BASE/mailq
		fi
		ln -s $BASEPATH/IScan.BASE/mailq /etc/iscan/
		#ln -s $BASEPATH/IScan.BASE/isdelvd /etc/iscan/isdelvd
		chmod 0755 /etc/rc2.d/S99ISmaild
		chmod 4555 /etc/iscan/S99ISmaild

		START_MAIL_DAEMON="YES"


	fi
	## Install INSTADMIN 
	InstallADMOnly
	# songmei 3/8/2000 merger v3.02 code for check serial number in v3.x way
	####		CHECKING LICENSE
	if [[ "$INSTFTP" = "YES" || "$INSTHTTP" = "YES" || "$INSTTVCS" = YES || "$INSTSMTP" = "YES" || "$INSTALLCVP" = "YES" ]] ; then
		if [ ! -s /etc/iscan/license ]
		then
			print -n " Can not find your license check program"
			PressAnyKey
			return
		fi
	        Header
	        print -n "\tPlease input your serial number for InterScan VirusWall"
		print ;
	        print -n "\tOr hit ENTER to install a 30-day trial version:"
		print -n ${BOLD}

		SERIAL=""
		read SERIAL
		echo $SERIAL | /etc/iscan/license

		if [ "$?" = "0" ] ; then
		   LICENSE="OK"
		   sed -e 's/Serial=IS65432/Serial='$SERIAL'/' < /etc/iscan/intscan.ini > /tmp/isli$$
		   cat /tmp/isli$$ >| /etc/iscan/intscan.ini
		   rm -f /tmp/isli$$
 		else
		   PressAnyKey
		fi
		print -n ${UNBOLD}
	fi

	####		FINISH LICENSE CHECKING
      #songmei merger code end 
	### Install ISFTP 
	if [ "$INSTFTP" = "YES" ] ; then

	#	if [ ! -s /etc/iscan/license ]
	#	then
	#		print -n " Can not find your license check program"
	#		PressAnyKey
	#		return
	#	fi

		if [ "$ISFTPTRIAL" = "1" ] ; then
			Header
			print ${BOLD}
			print "\tYou have installed TRIAL VERSION in the system."
			print ${UNBOLD}
			print -n "\tDo you want to re-install InterScan VirusWall for FTP? [     ]\b\b\b\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				print -n "Removing the TRIAL VERSION."
				# pkgrm -R `cat /etc/iscan/pkg/ISFTP` ISFTP
				StartRemove "FTP" 
				FTPPKG="isftp.tz"
			else
				print -n ${UNBOLD}
				return
			fi
			ISFTPTRIAL=0
		fi
		# If installed, current system remove first.
		#    (fix lost sendmail.rc)   10/31/2000
		if [ "$ISFTP" = "Installed" ] ; then
			print -n "\tDo you want to re-install InterScan VirusWall for FTP? [     ]\b\b\b\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				printf -n "Removing the current FTP system."
				StartRemove "FTP" 
			else
				print -n ${UNBOLD}
				return
			fi
		fi
		Header
	  #     print -n "\tPlease input your serial number for InterScan FTP : "
	#	print -n ${BOLD}
	#	/etc/iscan/license FTP
	#	if [ "$?" != "0" ] ; then
		if [ "$LICENSE" != "OK" ] ; then
			print -n "\tDo you want to install InterScan VirusWall Trial version for FTP?[  ]\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				TRIAL="YES"
				FTPPKG="isftp.$TRIAL_EXT"
			else
				print -n ${UNBOLD}
				return
			fi
		fi
		print -n ${UNBOLD}

		if [ ! -s ./$FTPPKG ] ; then
			print "\t\tCan not find your InterScan FTP ( $FTPPKG ) in current directory." 
			PressAnyKey
			return
		fi

		# add on Sep 29th, 1999.
		if [ -d /tmp/pkgftp ] ; then
			/bin/rm -rf /tmp/pkgftp
		fi

		( cd /tmp ; mkdir pkgftp )
		/bin/zcat < ./$FTPPKG | ( cd /tmp/pkgftp ; tar xf - )  
		pkgadd -d /tmp/pkgftp -R "$FTPPATH" ISFTP
		if [ $? -ne 0 ] ; then
			echo $ERROR_LINE >> /usr/tmp/iscan_install_log
			rm -rf $FTPPATH
                else
		   chmod 4555 /etc/iscan/isftpd
		   chmod 4555 /etc/iscan/S99ISftp
		fi
			
		PressAnyKey
		rm -rf /tmp/pkgftp
		INSTFTP="NO"

	fi

	if [ "$INSTHTTP" = "YES" ] ; then

	#	if [ ! -s /etc/iscan/license ] ; then
	#		print -n " Can not find your license check program"
	#		PressAnyKey
	#		return
	#	fi
		if [ "$ISHTTPTRIAL" = "1" ] ; then
			Header
			print ${BOLD}
			print  "\tYou have installed TRIAL VERSION in the system."
			print ${UNBOLD}
			print -n "\tDo you want to re-install InterScan VirusWall for HTTP? [     ]\b\b\b\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				print -n "Removing the TRIAL VERSION."
		              #	pkgrm -R `cat /etc/iscan/pkg/ISHTTP` ISHTTP
				StartRemove "HTTP" 
				HTTPPKG="ishttp.tz"
			else
				print -n ${UNBOLD}
				return
			fi
			ISHTTPTRIAL=0
		fi
		# If installed, current system remove first.
		#    (fix lost sendmail.rc)   10/31/2000
		if [ "$ISHTTP" = "Installed" ] ; then
			print -n "\tDo you want to re-install InterScan VirusWall for HTTP? [     ]\b\b\b\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				printf -n "Removing the current HTTP system."
				StartRemove "HTTP" 
			else
				print -n ${UNBOLD}
				return
			fi
		fi
		Header
	 #     print -n "\tPlease input your serial number for InterScan HTTP : "
	#	print -n ${BOLD}
	#	/etc/iscan/license HTTP
	#	if [ "$?" != "0" ] ; then
		if [ "$LICENSE" != "OK" ] ; then
			print -n "\tDo you want to install InterScan VirusWall Trial version for HTTP?[  ]\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				TRIAL="YES"
				#HTTPPKG="ishttp.$TRIAL_EXT"
				# HIP http package is same name
				HTTPPKG="ishttp.tz"
			else
				print -n ${UNBOLD}
				return
			fi
		fi
		print -n ${UNBOLD}
		if [ ! -s ./$HTTPPKG ] ; then
			print "\t\tCan not find InterScan HTTP ( $HTTPPKG ) in current directory." 
			PressAnyKey
			return
		fi

		# add on Sep 29th, 1999.
		if [ -d /tmp/pkghttp ] ; then
			/bin/rm -rf /tmp/pkghttp
		fi

		( cd /tmp ; mkdir pkghttp )
		/bin/zcat < ./$HTTPPKG | ( cd /tmp/pkghttp ; tar xf - )  
		pkgadd -d /tmp/pkghttp -R "$HTTPPATH" ISHTTP
		if [ $? -ne 0 ] ; then
			echo $ERROR_LINE >> /usr/tmp/iscan_install_log
			rm -rf $HTTPPATH
                else
	           chmod 4555 /etc/iscan/ishttpd
		   chmod 4555 /etc/iscan/S99ISproxy
		fi
		PressAnyKey
		rm -rf /tmp/pkghttp
		INSTHTTP="NO"

	fi
	if [ "$INSTSMTP" = "YES" ] ; then

	#	if [ ! -s /etc/iscan/license ] ; then
	#		print -n " Can not find your license check program"
	#		PressAnykey
	#		return
	#	fi
		if [ "$ISSMTPTRIAL" != "0" ] ; then
			Header
			print ${BOLD}
		       print  "\tYou are currently running SMTP Trial Version.\n"
			print ${UNBOLD}
			print -n "\tDo you want to re-install InterScan VirusWall for SMTP?[  ]\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				print -n "Removing the TRIAL VERSION."
				# pkgrm -R `cat /etc/iscan/pkg/ISSMTP` ISSMTP
				StartRemove "SMTP" 
				SMTPPKG="issmtp.tz"
			else
				INSTCVP="NO" 
				return
			fi
			ISSMTPTRIAL=0
		fi
		# If installed, current system remove first.
		#    (fix lost sendmail.rc)   10/31/2000
		if [ "$ISSMTP" = "Installed" ] ; then
			print -n "\tDo you want to re-install InterScan VirusWall for SMTP? [     ]\b\b\b\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				printf -n "Removing the current SMTP system."
				StartRemove "SMTP" 
			else
				print -n ${UNBOLD}
				return
			fi
		fi
		Header
	#	print -n "\tPlease input your serial number for InterScan SMTP : "
	#	print -n ${BOLD}
	#	/etc/iscan/license SMTP
	#	if [ "$?" != "0" ] ; then
		if [ "$LICENSE" != "OK" ] ; then
		print -n "\tDo you want to install InterScan VirusWall Trial version for SMTP[  ]\b\b" ; read RESP
			ChkResp $RESP "no"
		 	if [ "$RESP" = "YES" ] ; then
				TRIAL="YES"
				SMTPPKG="issmtp.$TRIAL_EXT"
			else
				print -n ${UNBOLD}
				return
			fi
		fi

		print -n ${UNBOLD}
		if [ ! -s ./$SMTPPKG ] ; then
			print "\t\tCan not find InterScan E_MAIL ( $SMTPPKG ) in current directory." 
			PressAnyKey
			return
		fi

		# add on Sep 29th, 1999.
		if [ -d /tmp/pkgsmtp ] ; then
			/bin/rm -rf /tmp/pkgsmtp
		fi

		( cd /tmp ; mkdir pkgsmtp )
		/bin/zcat < ./$SMTPPKG | ( cd /tmp/pkgsmtp ; tar xf - )  
		pkgadd -d /tmp/pkgsmtp -R "$SMTPPATH" ISSMTP
		if [ $? -ne 0 ] ; then
			echo $ERROR_LINE >> /usr/tmp/iscan_install_log
			rm -rf $SMTPPATH
                else
          	   chmod 4555 /etc/iscan/sendmail
		   chmod 4555 /etc/iscan/S88sendmail
		   chmod 555 /etc/rc2.d/S99ISsmtp
		fi
		PressAnyKey
		rm -rf /tmp/pkgsmtp
		INSTSMTP="NO"

	fi
	### Installation of TVCS
	InstallTVCSOnly  

    else
	# start install CVP 
	StartInstallCVP
    fi

	# setup administration paramter.
	SetAdmin ;

	#NKO create nessecary link
	ASenvironPATH="$ISVWROOT/ISBASE/IScan.BASE/ASenviron.csh"
	AStopPATH="$ISVWROOT/ISBASE/IScan.BASE/AStop.csh"
	upiniPATH="$ISVWROOT/ISBASE/IScan.BASE/upini"
        if [ ! -r "/etc/iscan/ASenviron.csh" ] ; then
            ln -s $ASenvironPATH /etc/iscan/ASenviron.csh
        fi
        if [ ! -r "/etc/iscan/AStop.csh" ] ; then
            ln -s $AStopPATH /etc/iscan/AStop.csh
        fi
        if [ ! -r "/etc/iscan/upini" ] ; then
            ln -s $upiniPATH /etc/iscan/upini
        fi

	##################
	# create pid directory 
	##################
	if [ ! -d /etc/iscan/pids ] ; then
		mkdir -p /etc/iscan/pids
		chown -R iscan  /etc/iscan/pids
		chgrp -R iscan  /etc/iscan/pids
	fi

	##################
	# Create link for http perfmon
	##################
	if [ ! -f /etc/iscan/perfmonhttp ] ; then
	    ln -s $BASEPATH/IScan.BASE/perfmonhttp /etc/iscan/perfmonhttp
	fi

	if [ "$START_MAIL_DAEMON" = "YES" ] ; then
	    ###########################################
	    # Prepare InterScan 3.7 mail deliver daemon
	    ###########################################
	    print "\t${BOLD} Starting mail delivery daemon... ${UNBOLD}"
	    # start the daemon
	    /etc/rc2.d/S99ISmaild stop   > /dev/null
	    /etc/rc2.d/S99ISmaild start  > /dev/null
         fi

	##################
	# Create link for mail q util
	##################
	if [ ! -f /etc/iscan/changemq ] ; then
	    ln -s $BASEPATH/IScan.BASE/changemq /etc/iscan/changemq
	fi
	if [ ! -f /etc/iscan/mailqutil ] ; then
	    ln -s $BASEPATH/IScan.BASE/mailqutil /etc/iscan/mailqutil
	fi

	RESP=""
	if [ "$TRIAL" = "YES" ] ; then
		TRIAL_DAYS=30
		LIC=`/etc/iscan/gentrial $TRIAL_DAYS`
		echo
		echo "\tThis trial version of InterScan will expire in $TRIAL_DAYS days,"
		echo "\tat which time virus protection on your system will be disabled."
		echo "\tTo ensure continuous protection, you must purchase InterScan VirusWall."
		echo "\tCheck the following URL for more information. "
		echo
		echo "\t\t http://www.antivirus.com/buy/"
	      #echo "\tIScan will send E-Mail to remind you before the pending "
	      #	echo "\texpiration." 
		echo 

		PressAnyKey
		ADDRESS=root

		if [ "$UPGRADE" = "YES" ]
		then

		grep "license=" /etc/iscan/intscan.ini
		if [ "$?" != "0" ] ; then
ed /etc/iscan/intscan.ini << T_EOF > /dev/null
/HttpScan=
i
license=xxxxxx
.
w
q
T_EOF
		fi

		fi

		if [ "$LIC" != "" ] ; then
		sed -e 's/license=xxxxxx/license='$LIC'/' < /etc/iscan/intscan.ini > /tmp/iscandd
		cp /tmp/iscandd /etc/iscan/intscan.ini
		fi
                #songmei 3/29/2000 display warning message
                if [[ -d /etc/iscan/old_log_ini ]] ; then
                   print ${BOLD}
                   print -n "\t----------------------------------------------------------\n" 
                   print  "\tYour old intscan.ini has been saved in the                "
                   print  "\t/etc/iscan/old_log_ini directory. The new intscan.ini "
		   print  "\tcontains default values. To retain your customized "
		   print  "\tintscan.ini values, you MUST manually replace the default "
		   print  "\tvalues in the new intscan.ini file with your customized values." 
                   print -n "\t----------------------------------------------------------\n" 
                   print ${UNBOLD}
                   PressAnyKey
                   rm -rf /tmp/iscan_old                     
                fi
                #songmei 3/29/2000 add end


		# Invalid Japanese function. 08/08/2000
		IS_PWD=`pwd`
		cd /
		echo "echo \"The trial version of InterScan VirusWall you have installed will expire in: 28 DAYS. For infomation on how you upgrade to the enterprise edition of InterScan VirusWall, call TrendMicro at: 1-800-228-5651 or visit us at our web site: http://www.antivirus.com\" | mailx -s'InterScan expire notification' ${ADDRESS}" | at now "+ 2day" 2>/tmp/tmpid
		echo "echo \"The trial version of InterScan VirusWall you have installed will expire in: 21 DAYS. For infomation on how you upgrade to the enterprise edition of InterScan VirusWall, call TrendMicro at: 1-800-228-5651 or visit us at our web site: http://www.antivirus.com\" | mailx -s'InterScan expire notification' ${ADDRESS}" | at now "+ 9day" 2>>/tmp/tmpid
		echo "echo \"The trial version of InterScan VirusWall you have installed will expire in: 14 DAYS. For infomation on how you upgrade to the enterprise edition of InterScan VirusWall, call TrendMicro at: 1-800-228-5651 or visit us at our web site: http://www.antivirus.com\" | mailx -s'InterScan expire notification' ${ADDRESS}" | at now "+ 16day" 2>>/tmp/tmpid
		echo "echo \"The trial version of InterScan VirusWall you have installed will expire in: 7 DAYS. For infomation on how you upgrade to the enterprise edition of InterScan VirusWall, call TrendMicro at: 1-800-228-5651 or visit us at our web site: http://www.antivirus.com\" | mailx -s'InterScan expire notification' ${ADDRESS}" | at now "+ 23day" 2>>/tmp/tmpid
		echo "echo \"The trial version of InterScan VirusWall you have installed on your system has expired. For information on how you can upgrade to the enterprise edition of InterScan VirusWall, call TrendMicro at: 1-800-228-5651 or visit us at our web site: http://www.antivirus.com\" | mailx -s'InterScan expire notification' ${ADDRESS}" | at now "+ 30day" 2>>/tmp/tmpid
		echo "echo \"# expire is yes\" >> /etc/iscan/intscan.ini" | at now "+ 30day" 2>>/tmp/tmpid
		ATID=`grep job /tmp/tmpid | /bin/cut -d' ' -f2`
		for ind in ${ATID}
		do
		  echo "# notify_id is ${ind}" >> /etc/iscan/intscan.ini
		done
		rm -f /tmp/tmpid
		rm -f /tmp/iscandd
		cat /dev/null > /etc/iscan/gentrial
		TRIAL="NO"
		cd $IS_PWD

	fi

}

#
# Update administration parameter
#
function SetAdmin
{
	Header

	print "\t\t${BOLD}Setup several administration parameter...${UNBOLD}"

	# Follwing is to update intscan.ini which has some parameter as comment.
	MakeUncomment /etc/iscan/intscan.ini server
	MakeUncomment /etc/iscan/intscan.ini port

	# NKO CHANGE
	#ex -s /etc/iscan/intscan.ini << _EOF_ > /dev/null
	ex /etc/iscan/intscan.ini << _EOF_ > /dev/null
/^server
c
server=$NOTIFY_SERVER
.
/^port
c
port=$NOTIFY_PORT
.
x
_EOF_

	PressAnyKey
}

#
# Change Administration paramter. "NOTIFY_SERVER", "NOTIFY_PORT"
#
function ChangeAdmin
{
    keep_menu=1

    while ( [ $keep_menu = 1 ] ); do
	Header
	print "\t\t${BOLD}Notification server${UNBOLD}\t: [$NOTIFY_SERVER]."
	print "\t\t${BOLD}Notification port${UNBOLD}\t: [$NOTIFY_PORT]."
	print

	print
	{
	 print "\t1.\tModify Notification server."
	 print "\t2.\tModify Notification port."
	 print "\t3.\tBack to Menu."
	} >&2
	print 
	print -n "		Select a number [   ]\b\b\b" ; read RESP


	print
	case $RESP in
	1 ) print -n "\tPlease specify notification server name: ";
	    read RESP;
	    export NOTIFY_SERVER=$RESP ;;
	2 ) print -n "\tPlease specify notification port: ";
	    read RESP;
	    export NOTIFY_PORT=$RESP ;;
	3 ) keep_menu=0 ;;
	esac

    done
}

#
# Change Language paramter "IS_LANG"
#
function ChangeLang
{
	Header
	print "\t1.\tInstall ${BOLD}Japanese${UNBOLD} Package."
	print "\t2.\tInstall ${BOLD}English${UNBOLD}  Package."
	print

	print -n "		Select a number [   ]\b\b\b" ; read RESP

	case $RESP in
	1 ) export IS_LANG="JP" ;;
	2 ) export IS_LANG="EN" ;;
	esac

}

function Install
{
	### Check if Install CVP already, need to remove it first.
	if [ $ISCVP = "Installed" ] ; then
		return
	fi

	ChkPkg
	ChkConfig
	while ( true ); do
	Header
	#print
	print "\tInterScan VirusWall 3.7 Installation List"
	#print
	print "\tInstall InterScan VirusWall Base System\t ${DASH} [ ${BOLD}${INSTBASE}${UNBOLD} ]"
	print "\tInstallation Path\t${BOLD}${BASEPATH}${UNBOLD}"
#	print
	print "\tInstall InterScan VirusWall CGI Admin\t ${DASH} [ ${BOLD}${INSTADMIN}${UNBOLD} ]"
	print "\tInstallation Path\t${BOLD}${ADMINPATH}${UNBOLD}"
	#print
	print "\tInstall InterScan VirusWall for FTP\t ${DASH} [ ${BOLD}${INSTFTP}${UNBOLD} ]"
	print "\tInstallation Path\t${BOLD}${FTPPATH}${UNBOLD}"
	#print
	print "\tInstall InterScan VirusWall for HTTP\t ${DASH} [ ${BOLD}${INSTHTTP}${UNBOLD} ]"
	print "\tInstallation Path\t${BOLD}${HTTPPATH}${UNBOLD}"
	print "\tInstall InterScan VirusWall for E-Mail\t ${DASH} [ ${BOLD}${INSTSMTP}${UNBOLD} ]"
#	print
	print "\tInstallation Path\t${BOLD}${SMTPPATH}${UNBOLD}"

	#print 
	print "\tInstall TVCS Agent for InterScan VirusWall ${DASH} [ ${BOLD}${INSTTVCS}${UNBOLD} ]"
	print "\tInstallation Path\t${BOLD}${TVCSPATH}${UNBOLD}"
	#print
	print "\tInterScan VirusWall Package Language\t ${DASH} [ ${BOLD}${IS_LANG}${UNBOLD} ]"
	print
	{
	 print "\t1.\tModify option for InterScan VirusWall for BASE."
	 print "\t2.\tModify option for InterScan VirusWall for ADMIN."
	 print "\t3.\tModify option for InterScan VirusWall for FTP."
	 print "\t4.\tModify option for InterScan VirusWall for HTTP."
	 print "\t5.\tModify option for InterScan VirusWall for SMTP."
	 print "\t6.\tModify option for InterScan VirusWall for TVCS."
	 print "\t7.\tAdministration."
	 print "\t8.\tModify Package Language."
	 print "\t9.\tStart installation."
	 print "\t10.\tBack to Main Menu."
	} >&2
	print 
	print -n "		Select a number [   ]\b\b\b" ; read RESP

	case $RESP in
	1 ) Modify BASE ;;
	2 ) Modify ADMIN ;;
	3 ) Modify FTP ;;
	4 ) Modify HTTP ;;
	5 ) Modify SMTP ;;
	6 ) Modify TVCS ;;
	7 ) ChangeAdmin ;;
	8 ) ChangeLang ;;
	9 ) StartInstall ;;
	10 ) FirstPage ;;
	* ) print "${BELL}\t\tPlease type a valid choice"
	esac
	done
}

function StartRemove
{
	typeset REMOVERESP

	case $1 in 
	BASE )  if [ "$ISBASE" = "Installed" ] ; then
		   for i in $ISFTP $ISHTTP $ISADMIN $ISSMTP $ISCVP $ISTVCS; do
		       if [[ "$i" = "Installed" ]] ; then
			   print "${BOLD}"
		           print "\t\tYou have to remove other InterScan sub-system first if you really want to remove InterScan $1 System" 
			   print "${UNBOLD}"
			   PressAnyKey
			   return ;
		       fi
		   done
		   Header
		   print ${BOLD}
		   print -n "Removing InterScan $1 package means no InterScan functionality will exist on the system. Do you want to remove this package?" 
		   print ${UNBOLD}
                   #songmei 3/29/2000 add. get virus path, save old intscan.ini to /tmp/iscan_old
		   if [ -s /etc/iscan/pkg/ISVWROOT ] ; then
	    		ISPATH=`cat /etc/iscan/pkg/ISVWROOT`
	    		VIRUSLOGPATH=$ISPATH\/virus
	   	   fi
		   if [[ !  -d /tmp/iscan_old ]] ; then
                        mkdir /tmp/iscan_old
                   fi
                   cp /etc/iscan/intscan.ini /tmp/iscan_old    
		   #songmei add end

		   ##################################
		   # stop mail deliver daemon
		   ##################################
		   # stop daemon
		   if [ -f /etc/rc2.d/S99ISmaild ] ; then
		      /etc/rc2.d/S99ISmaild stop
		   fi
		   
		   # remove pid file
		   if [ -f /etc/iscan/pids/isdelvd.pids ] ; then
			rm -f /etc/iscan/pids/isdelvd.pids
		   fi
		   # remove boot lock
		   if [ -f /etc/iscan/isdelv.boot.lock ] ; then
			rm -f /etc/iscan/isdelv.boot.lock
		   fi
		   # remove rc script
		   if [ -f /etc/rc2.d/S99ISmaild ] ; then
			rm -rf /etc/rc2.d/S99ISmaild 
		   fi
		   

		   pkgrm -R `cat /etc/iscan/pkg/ISBASE` ISBASE
		   if [[ "$?" = "0"  && ! -r /etc/iscan ]] ; then
			ISBASE="None"	
			INSTBASE="YES"
			rm -r $BASEPATH
			if [  -d $VIRUSLOGPATH  ] ; then
				rm -rf  $VIRUSLOGPATH
			fi
		   fi
                   #songmei 3/29/2000 add display warning message
                   print ${BOLD}
                   print -n "\t------------------------------------------------------------\n" 
               print -n "\tYour old intscan.ini has been temporarily saved in the\n" 
                   print -n "\t/tmp/iscan_old directory. \n" 
                   print -n "\t------------------------------------------------------------\n" 
                   print ${UNBOLD}        
		   #songmei add end
                   Remove_Iscan_user 
		else
		   print ${BOLD}
		   print "\t\tPlease install the InterScan Base package first." 
		   print ${UNBOLD}
		fi 
	        PressAnyKey ;;
	ADMIN ) if [ "$ISADMIN" = "Installed" ] ; then
		   Header
		   ## if CVP installed can't remove this pkages
			if [ "$ISCVP" = "Installed" ] ; then 
				print "${BOLD}"
				print "\t\tYou have to remove InterScan CVP first"  
				print "${UNBOLD}"
                       		PressAnyKey
                           	return ;
                        fi
		   ## if there is no CVP installed than remove ADMIN
		   print ${BOLD}
		   print "Removing the InterScan $1 package means you will not be able to configure InterScan VirusWall from a web browser. Do you want to remove this package?" 
		   print ${UNBOLD}
		   pkgrm -R `cat /etc/iscan/pkg/ISADMIN` ISADMIN
		   if [[ "$?" = "0" && ! -s /etc/rc2.d/S99IScanHttpd ]] ; then
			ISADMIN="None"	
			INSTADMIN="YES"
			rm -r $ADMINPATH
		   fi
		else
		   print ${BOLD}
		   print "\t\tPlease install the InterScan ADMIN package first." 
		   print ${UNBOLD}
		fi
	        PressAnyKey  ;;
	FTP ) if [ "$ISFTP" = "Installed" ] ; then
		Header
		print ${BOLD}
		print "Removing InterScan $1 VirusWall means your network users will lose virus protection on their network file transfers. Do you want to remove this package?" 
		print ${UNBOLD}
		pkgrm -R `cat /etc/iscan/pkg/ISFTP` ISFTP
		if [[ "$?" = "0" && ! -s /etc/iscan/isftpd ]] ; then
			ISFTP="None"	
			rm -r $FTPPATH
			ISFTPTRIAL=0
		fi
	      else
		   print ${BOLD}
		   print "\t\tYou haven't install InterScan VirusWall FTP system yet" 
		   print ${UNBOLD}
	      fi

ATID=`grep "# notify_id" /etc/iscan/intscan.ini | /bin/cut -d' ' -f4`
for ind in ${ATID}
do
	at -r $ind
done
sed -e '/# notify_id/d' /etc/iscan/intscan.ini > /tmp/iscan$$
cp /tmp/iscan$$ /etc/iscan/intscan.ini
rm  /tmp/iscan$$ 

	      PressAnyKey ;;
	SMTP ) if [ "$ISSMTP" = "Installed" ] ; then
		  Header
		  print ${BOLD}
		  print "Removing InterScan $1 VirusWall means your network users will lose virus protection on their e-mail transmissions. Do you want to remove this package?" 
		  print ${UNBOLD}
		  pkgrm -R `cat /etc/iscan/pkg/ISSMTP` ISSMTP
		  if [[ "$?" = "0" && ! -s /etc/iscan/sendmail ]] ; then
			ISSMTP="None"	
			rm -r $SMTPPATH
			ISSMTPTRIAL=0
		  fi
		else
		   print ${BOLD}
		   print "\t\tYou haven't install InterScan VirusWall SMTP system yet" 
		   print ${UNBOLD}
		fi
ATID=`grep "# notify_id" /etc/iscan/intscan.ini | /bin/cut -d' ' -f4`
for ind in ${ATID}
do
	at -r $ind
done
sed -e '/# notify_id/d' /etc/iscan/intscan.ini > /tmp/iscan$$
cp /tmp/iscan$$ /etc/iscan/intscan.ini
rm  /tmp/iscan$$ 
	        PressAnyKey ;;
	HTTP ) if [ "$ISHTTP" = "Installed" ] ; then
		Header
		print ${BOLD}
		print "Removing InterScan $1 VirusWall means your network users will lose virus protection on their Internet and intranet file transfers. Do you want to remove this package?" 
		print ${UNBOLD}
		pkgrm -R `cat /etc/iscan/pkg/ISHTTP` ISHTTP
		if [[ "$?" = "0" && ! -s /etc/iscan/ishttpd ]] ; then
			ISHTTP="None"	
			rm -r $HTTPPATH
			ISHTTPTRIAL=0
		fi
	       else
		print ${BOLD}
		print "\t\tYou haven't install InterScan VirusWall Base system yet" 
		print ${UNBOLD}
	       fi
ATID=`grep "# notify_id" /etc/iscan/intscan.ini | /bin/cut -d' ' -f4`
for ind in ${ATID}
do
	at -r $ind
done
sed -e '/# notify_id/d' /etc/iscan/intscan.ini > /tmp/iscan$$
cp /tmp/iscan$$ /etc/iscan/intscan.ini
rm  /tmp/iscan$$ 
	       PressAnyKey ;;
	TVCS ) if [ "$ISTVCS" = "Installed" ] ; then
		   Header
		   print ${BOLD}
		   print "Please have your TVCS administrator remove this InterScan registration from TVCS console." 
		   print ${UNBOLD}
		   pkgrm -R `cat /etc/iscan/pkg/ISTVCS` ISTVCS
		   if [ "$?" = "0" ] ; then
			ISTVCS="None"
			INSTTVCS="YES"
			rm -r $TVCSPATH
		   fi

		   # TJ_FIX: add to judge ini file has TVCS part
		   #         modify number of delete line 14 to 19
		   #
		   grep "TVCS" /etc/iscan/intscan.ini > /dev/null 2>&1
		   if [ ! $? ] ; then
			ed /etc/iscan/intscan.ini <<EOF >/dev/null 2>/dev/null
/\[TVCS
.,+19d
.
w
q
EOF
		  fi
		else
		   print ${BOLD}
		   print "\t\tPlease install the Trend VCS Agent first." 
		   print ${UNBOLD}
		fi
	        PressAnyKey  ;;
	CVP ) if [ "$ISCVP" = "Installed" ] ; then
		Header
		pkgrm -R `cat /etc/iscan/pkg/ISCVP` ISCVP
		rm -rf /etc/iscan/pkg/ISCVPON
		if [[ "$?" = "0" && ! -s /etc/iscan/iscvp ]] ; then
			ISCVP="None"
			INSTCVP="YES"
			ISCVPTRIAL="0" 
			rm -r $CVPPATH
			ISCVPTRIAL=0
		fi 
              else
		print ${BOLD}
                print "\t\tYou haven't install InterScan CVP yet "
		print ${UNBOLD}
		return 
              fi
ATID=`grep "# notify_id" /etc/iscan/intscan.ini | /bin/cut -d' ' -f4`
for ind in ${ATID}
do
        at -r $ind
done
sed -e '/# notify_id/d' /etc/iscan/intscan.ini > /tmp/iscan$$
cp /tmp/iscan$$ /etc/iscan/intscan.ini
rm  /tmp/iscan$$ 
	      PressAnyKey  ;;	
	
	esac
	RESP=""
}

function Remove
{
	typeset RRESP

	while ( true ) ; do

	Header
	print
	print "\t1.\tRemove InterScan VirusWall Base System."
	print "\t2.\tRemove InterScan VirusWall Admin System."
	print "\t3.\tRemove InterScan VirusWall FTP System."
	print "\t4.\tRemove InterScan VirusWall HTTP System."
	print "\t5.\tRemove InterScan VirusWall E-Mail System."
	print "\t6.\tRemove InterScan VirusWall TVCS System."
	print "\t7.\tRemove All InterScan VirusWall System."
	print "\t8.\tBack to Main Menu."
	print 
	print -n "		Select a number [   ]\b\b\b";read RRESP
	case $RRESP in
	1 ) StartRemove "BASE" ;;
	2 ) StartRemove "ADMIN" ;;
	3 ) StartRemove "FTP" ;;
	4 ) StartRemove "HTTP" ;;
	5 ) StartRemove "SMTP" ;;
	6 ) StartRemove "TVCS" ;;
	7 ) RemoveAll ;; 
	8 ) FirstPage ;;
	* ) print "${BELL}\t\tAn invalid choice was entered. Please try again."
	esac

	done
}

function RemoveCVP 
{
	typeset RESPCVP

	while (true) ; do 
	Header
	print
	print "\t1.\tRemove InterScan VirusWall Base System."
	print "\t2.\tRemove InterScan VirusWall Admin System."
	print "\t3.\tRemove InterScan VirusWall CVP System."
	print "\t4.\tRemove InterScan VirusWall TVCS System."
	print "\t5.\tRemove All InterScan VirusWall System."
	print "\t6.\tBack to Main Menu."
	print
        print -n "              Select a number [   ]\b\b\b";read RESPCVP
        case $RESPCVP in
	1 )StartRemove "BASE" ;;
	2 )StartRemove "ADMIN" ;;
	3 )StartRemove "CVP" ;;
	4 )StartRemove "TVCS" ;;
	5 )RemoveAll ;; 
	6 )FirstPageCVP ;; 
	* ) print "${BELL}\t\tAn invalid choice was entered. Please try again."
	esac
	done
}	

function Exit
{
  if [ ! -s /etc/iscan ] ; then
	exit 0
  fi
  
  if [  -s /etc/iscan/pkg ] ; then
     chown -R iscan /etc/iscan/pkg
     chgrp -R iscan /etc/iscan/pkg
  fi

  # NKO CHANGE
  if [ $RESTARTFLG = "NO" ] ; then 
	   Header
	   print
	print "\tUpdate your pattern file and scan engine."
	exit 0
  fi

	print -n "\tDo you want to start InterScan VirusWall now? [     ]\b\b\b\b\b" ; read RESP
	ChkResp $RESP "yes"
	if [ "$RESP" = "YES" ] ; then
		# enable to eject cdrom if to install on CDROM
		cd /etc/iscan
	    ### Turn on the ISFTP 
	    if [ -s /etc/iscan/pkg/ISFTP ] ; then
		INETD=/etc/inetd.conf
		sed -e "s/^\(ftp[ 	]*stream[ 	]*tcp[ 	]\)/#_ISCAN_ \1/" $INETD > /tmp/tmp$$
		# NKO CHANGE
		#mv /tmp/tmp$$ $INETD
		cat /tmp/tmp$$ >| $INETD

		INETDPID=`ps -e | grep inetd | grep -v grep | awk '{ print $1}'`
		if [ "$INETDPID" ] ; then
		    kill -HUP $INETDPID
		    sleep 3
		fi
	        /etc/rc2.d/S99ISftp stop > /dev/null
                /etc/rc2.d/S99ISftp start  > /dev/null
	    fi

	    ### Turn on ISHTTP 
	    if [ -s /etc/iscan/pkg/ISHTTP ] ; then
		/etc/rc2.d/S99ISproxy stop > /dev/null
		/etc/rc2.d/S99ISproxy start > /dev/null
	    fi

	    #### Turn on ISSMTP 
	    if [ -s /etc/iscan/pkg/ISSMTP ] ; then
		/etc/rc2.d/S88sendmail stop  > /dev/null
		/etc/rc2.d/S88sendmail start > /dev/null
		/etc/rc2.d/S99ISsmtp stop  > /dev/null
		/etc/rc2.d/S99ISsmtp start > /dev/null
	    fi

	    #### Turn on ISCVP
	    if [ -s /etc/iscan/pkg/ISCVP ] ; then 
		/etc/rc2.d/S99IScvp stop > /dev/null
		/etc/rc2.d/S99IScvp start > /dev/null
	    fi

	    # NKO JP-1366 2001/05/07
	    #### Turn on ISTVCS
	    if [ -s /etc/iscan/pkg/ISTVCS ] ; then 

		TVCSSERVERADD=`awk -F"=" '/^VccServer.*/ { print $2 }' < /etc/iscan/intscan.ini  `
		if [ "$TVCSSERVERADD" != "0" ] ; then
		    /etc/rc2.d/S99IStvcs stop > /dev/null
		    /etc/rc2.d/S99IStvcs start > /dev/null
		fi
	    fi

	    Header
	    print
	    print "\tUpdate your pattern file and scan engine."
	    print

	else
           if [ -s /etc/iscan/pkg/ISFTP ] ; then
               echo 0 >| /etc/iscan/pkg/ISFTPON
           fi
           if [ -s /etc/iscan/pkg/ISHTTP ] ; then
               echo 0 >| /etc/iscan/pkg/ISHTTPON
           fi
           if [ -s /etc/iscan/pkg/ISSMTP ] ; then
               echo 0 >| /etc/iscan/pkg/ISSMTPON
           fi
           if [ -s /etc/iscan/pkg/ISCVP ] ; then
               echo 0 >| /etc/iscan/pkg/ISCVPON
           fi
           chown -R iscan /etc/iscan/pkg
           chgrp -R iscan /etc/iscan/pkg
           
	   Header
	   print
	   print "\tYou could browse InterScan configuration page later"
	   print "\tAnd turn on InterScan VirusWall then."
	   print
	   print "\tUpdate your pattern file and scan engine."
	   print
	   print

	fi
	exit 0
}

function BringupBrowser
{
	typeset NETSCAPE
	typeset BROWSER
	typeset BROWSERPATH
	typeset firstchar
	typeset	HOSTNAME

	Header
	if [ "$ISADMIN" != "Installed" ] ; then
		print ${BOLD}
		print "\t\tPlease install the InterScan ADMIN package first."
		print ${UNBOLD}
		PressAnyKey
		return
	fi
	print -n "\tPlease identify the browser you use(e.g. netscape): " ; read BROWSER
	NETSCAPE=${BROWSER:-"netscape"}
	BROWSER=`/usr/bin/which $NETSCAPE`
	if [ ! -x $BROWSER ] ; then
		print -n "\tEnter the path where your browser is located: " ; read BROWSERPATH	
		if [ ! -x $BROWSERPATH/$NETSCAPE ] ; then
		   print ${BOLD}
		   print "\t\tNo executable browser program in the directory."
		  # print "\t\tBringup text configure menu...?"
		   print ${UNBOLD}
		   PressAnyKey
		  # exec /etc/iscan/config
		  # Exit
		   return
		fi	
		HOSTNAME=`hostname`
		NETSCAPE=`echo $BROWSERPATH/$NETSCAPE`
	else
		HOSTNAME=`hostname`
		NETSCAPE=`echo $NETSCAPE`
	fi
	exec $NETSCAPE $HOSTNAME:1812/interscan &
	Exit
}

function MainStatusCVP
{
	## Add ChkConfig to correct installed information . Jessica 
	ChkConfig
        print "\t\tCurrent System Configuration : "
        print
        print "\t\tInstalled :\tAlready installed on the system"
        print "\t\tNone:\t\tNot found on the system"
        print
	print "\t\tInterScan VirusWall Base System\t ${DASH} [ ${BOLD}${ISBASE}${UNBOLD} ]"
        if [ "$ISBASE" = "Installed" ] ; then
           BASEPATH=`cat /etc/iscan/pkg/ISBASE`
           print "\t\tInstallation Path\t${BOLD}${BASEPATH}${UNBOLD}"
        fi
        #print
        print "\t\tInterScan VirusWall CGI Admin\t ${DASH} [ ${BOLD}${ISADMIN}${UNBOLD} ]"
        if [ "$ISADMIN" = "Installed" ] ; then
           ADMINPATH=`cat /etc/iscan/pkg/ISADMIN`
           print "\t\tInstallation Path\t${BOLD}${ADMINPATH}${UNBOLD}"
        fi
        #print
        if [ "$ISCVP" = "Installed"  ] ; then
           CVPPATH=`cat /etc/iscan/pkg/ISCVP`
           if [ -x $CVPPATH/IScan.CVP/iscvp.trial ] ; then
                ISCVPTRIAL=1
                print "\t\tInterScan VirusWall Trial for CVP ${DASH}[ ${BOLD}${ISCVP}${UNBOLD} ]"
           else
                print "\t\tInterScan VirusWall for CVP\t ${DASH} [ ${BOLD}${ISCVP}${UNBOLD} ]"
           fi
           print "\t\tInstallation Path\t${BOLD}${CVPPATH}${UNBOLD}"
        else
           print "\t\tInterScan VirusWall for CVP\t ${DASH} [ ${BOLD}${ISCVP}${UNBOLD} ]"
        fi
        #print
        if [ "$ISTVCS" = "Installed"  ] ; then
           TVCSPATH=`cat /etc/iscan/pkg/ISTVCS`
           print "\t\tInterScan VirusWall for TVCS\t ${DASH} [ ${BOLD}${ISTVCS}${UNBOLD} ]"
           print "\t\tInstallation Path\t${BOLD}${TVCSPATH}${UNBOLD}"
        else
           print "\t\tInterScan VirusWall for TVCS\t ${DASH} [ ${BOLD}${ISTVCS}${UNBOLD} ]"
        fi
        #print
}

function MainStatus {
	## Add ChkConfig to correct installed information . Jessica
	ChkConfig
	print "\t\tCurrent System Configuration: "
	print
	print "\t\tInstalled:\tAlready installed on the system"
	print "\t\tNone:\t\tNot Found on the system"
	print

	print "\t\tInterScan VirusWall Base System\t ${DASH} [ ${BOLD}${ISBASE}${UNBOLD} ]"
	if [ "$ISBASE" = "Installed" ] ; then
	   BASEPATH=`cat /etc/iscan/pkg/ISBASE`
	   print "\t\tInstallation Path\t${BOLD}${BASEPATH}${UNBOLD}"
	fi
#	print
	print "\t\tInterScan VirusWall CGI Admin\t ${DASH} [ ${BOLD}${ISADMIN}${UNBOLD} ]"
	if [ "$ISADMIN" = "Installed" ] ; then
	   ADMINPATH=`cat /etc/iscan/pkg/ISADMIN`
	   print "\t\tInstallation Path\t${BOLD}${ADMINPATH}${UNBOLD}"
	fi
#	print
	if [ "$ISFTP" = "Installed"  ] ; then 
	   FTPPATH=`cat /etc/iscan/pkg/ISFTP`
	   if [ -x $FTPPATH/IScan.FTP/isftpd.trial ] ; then
		ISFTPTRIAL=1
		print "\t\tInterScan VirusWall Trial for FTP ${DASH}[ ${BOLD}${ISFTP}${UNBOLD} ]"
	   else
		print "\t\tInterScan VirusWall for FTP\t ${DASH} [ ${BOLD}${ISFTP}${UNBOLD} ]"
	   fi
	   print "\t\tInstallation Path\t${BOLD}${FTPPATH}${UNBOLD}"
	else
	   print "\t\tInterScan VirusWall for FTP\t ${DASH} [ ${BOLD}${ISFTP}${UNBOLD} ]"
	fi
#	print
	if [ "$ISHTTP" = "Installed" ] ; then
	   HTTPPATH=`cat /etc/iscan/pkg/ISHTTP`
	   if [ -x $HTTPPATH/IScan.HTTP/ishttpd.trial ] ; then
		ISHTTPTRIAL=1
		print "\t\tInterScan VirusWall Trial for HTTP${DASH}[ ${BOLD}${ISHTTP}${UNBOLD} ]"
	   else
		print "\t\tInterScan VirusWall for HTTP\t ${DASH} [ ${BOLD}${ISHTTP}${UNBOLD} ]"
	   fi
	   print "\t\tInstallation Path\t${BOLD}${HTTPPATH}${UNBOLD}"
	else
	   print "\t\tInterScan VirusWall for HTTP\t ${DASH} [ ${BOLD}${ISHTTP}${UNBOLD} ]"
	fi
#	print
	if [ "$ISSMTP" = "Installed" ] ; then
	   SMTPPATH=`cat /etc/iscan/pkg/ISSMTP`
	   if [ -x $SMTPPATH/IScan.SMTP/issmtpd.trial ] ; then
		ISSMTPTRIAL=1
		print "\t\tInterScan VirusWall Trial for SMTP${DASH}[ ${BOLD}${ISSMTP}${UNBOLD} ]"
	   else
		print "\t\tInterScan VirusWall for SMTP\t ${DASH} [ ${BOLD}${ISSMTP}${UNBOLD} ]"
	   fi
	   print "\t\tInstallation Path\t${BOLD}${SMTPPATH}${UNBOLD}"
	else
	   print "\t\tInterScan VirusWall for E-Mail\t ${DASH} [ ${BOLD}${ISSMTP}${UNBOLD} ]"
	fi
#	print
	if [ "$ISTVCS" = "Installed"  ] ; then 
	   TVCSPATH=`cat /etc/iscan/pkg/ISTVCS`
	   print "\t\tInterScan VirusWall for TVCS\t ${DASH} [ ${BOLD}${ISTVCS}${UNBOLD} ]"
	   print "\t\tInstallation Path\t${BOLD}${TVCSPATH}${UNBOLD}"
	else
	   print "\t\tInterScan VirusWall for TVCS\t ${DASH} [ ${BOLD}${ISTVCS}${UNBOLD} ]"
	fi
	print
}

function CheckINSTCVP
{
   # Check if allready installed CVP and remove all of then
    clear
    CheckSW "ISCVP"
    Header 
    if [ "$ISCVP" = "Installed" ] ; then 
	    print ${BOLD}
	if [ "$ISCVPTRIAL" = "1" ] ; then 
	   print -n "\t\tYou are currently running CVP Trial Version.\n" 
	else 
         print -n "\t\tYou are currently running InterScan for CVP.\n"
	fi 
	    print -n "\t\tPlease remove it before installing this version.\n"
            print ${UNBOLD}
          print -n "\tDo you want to remove it now? [     ]\b\b\b\b\b" ; read RESP
        ChkResp $RESP "no"
                if [ "$RESP" = "YES" ] ; then
		         StartRemove "CVP" 
                else
                         Main  
                fi
    fi
}

function FirstPage
{
	# Check if allready installed CVP 
	CheckINSTCVP 
	typeset done=false

	while [[ $done = false ]] ; do
	done=true
	{

	 Header
	 print "\t\tMain Menu"
	 print
	 MainStatus

	 print "\t1.\tInstall InterScan VirusWall sub-system."
	 #print
	 print "\t2.\tRemove InterScan VirusWall sub-system."
	 #print
         print "\t3.\tRegister InterScan VirusWall with a Trend VCS server."
         #print
         print "\t4.\tConfigure InterScan VirusWall via Web browser (exit Setup)."
         #print
	 print "\t5.\tBack to the First Page." 
	 #print
	 print "\t6.\tExit."
	 
	} >&2
	print 
	print -n "		Select a number [   ]\b\b\b";read RESP

	case $RESP in
	1 ) checkpath; Install ; done=false ;;
	2 ) Remove ;;
	3 ) VCCRegister ; done=false ;;
	4 ) BringupBrowser ; done=false;; 
	5 ) Main ;;
	6 ) Exit ;;
	* ) print "\t\tAn invalid choice was entered. Please try again."
	    done=false ;;
	esac

	done
}

function ChkPkg
{
	if [ -a ./$BASEPKG ] ; then
		INSTBASE="YES"
	fi
	if [ -a ./$ADMINPKG ] ; then
		INSTADMIN="YES"
	fi
	if [ -a ./$FTPPKG ] ; then
		INSTFTP="YES"
	fi
	if [ -a ./$SMTPPKG ] ; then
		INSTSMTP="YES"
	fi
	if [ -a ./$HTTPPKG ] ; then
		INSTHTTP="YES"
	fi
	if [ -a ./$TVCSPKG ] ; then
		#Force INSTTVCS=NO
		INSTTVCS="NO"
	fi
	if [ -a ./$CVPPKG ] ; then 
		INSTCVP="YES"
	fi
}

function PVCCINFO
{
        clear
        print ; print ;
	print "Trend VCS Information:\n" ; 
        print  "\t1. InterScan host :[$host]";
	print ;
        print  "\t2. Site name: [$LO]." ;
	print ;
        print  "\t3. IP address of the Trend VCS server: [$VCC]." ;
	print ;
}

function VCCINFOCHANGE
{

        PVCCINFO
        print -n "  Specify the item number to modify or press Enter to accept:[   ]\b\b\b";read infnum
	        case $infnum in
        1 ) print -n "\tInterScan host:[          ]\b\b\b\b\b\b\b\b\b\b\b" ; read host;;
	2 ) print -n "\t Site name:[                ]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" ; read LO ;;
	3 )print -n "\tIP address of the Trend VCS server:[                       ]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"; read VCC ;;
	* ) print ;;
        esac
	PressAnyKey
	return

}

function VCCINFO
{
	print ; print 
        host=`hostname`;
        ipaddr=`/etc/iscan/ip $host`;
        print -n "\tEnter the Trend VCS Site name for this server:[                ]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" ; read LO
        print -n "\tSpecify the IP address of the Trend VCS server:[                      ]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"; read VCC
	print -n "\t Trend VCS Information:\n" ;
        PVCCINFO
        print -n "\tCorrect?[    ]\b\b\b\b" ; read RESP
        ChkResp $RESP ""
}

function DoRegister
{
        $ADMINPATH/IScan.adm/cgi-bin/Register /etc/iscan/intscan.ini > /dev/null ;
        if [ $? -eq 1 ] ; then
            rm -f /etc/iscan/solar.tmp
            echo "Registration successful."
            /etc/rc2.d/S99IStvcs start  > /dev/null
        else
            sed -e 's/VccServer=*.*.*.*/VccServer=0/' < /etc/iscan/intscan.ini > /tmp/solar ;
            cp /tmp/solar /etc/iscan/intscan.ini ;
            rm -f /tmp/solar
            echo "Unable to register with the Trend VCS server."
            echo "Please check the IP address specified (and network connection) then try again." 
        fi
        PressAnyKey
        return
}

function VCCRegister
{
	clear

        grep "VccServer=0" /etc/iscan/intscan.ini > /dev/null ;
        if [ $? -ne 0 ] ;then
            print "Registration already done!"
            PressAnyKey
            return
        fi

        if [ -s /etc/iscan/ip ] ; then
                VCCINFO
          while (true) ; do
                if [ "$RESP" = "YES" ] ; then
                        break;
                else
                        clear
                        VCCINFOCHANGE
                        PVCCINFO
                        print -n "\tCorrect? (Enter y/Y to accept, n/N to reject)[    ]\b\b\b\b" ; read RESP
                        ChkResp $RESP ""
                fi
          done
          LO=$(print $LO | tr ' ' '_')
          sed -e 's/VccServer=0[ ]*/VccServer='$VCC'/;s/Location=0[ ]*/Location='$LO'/;s/Server=0[ ]*/Server='$host'/;s/ServerIP=0[ ]*/ServerIP='$ipaddr'/' < /etc/iscan/intscan.ini > /etc/iscan/solar.tmp;
          cp /etc/iscan/intscan.ini /etc/iscan/intscan.ini.bak;
          cp /etc/iscan/solar.tmp /etc/iscan/intscan.ini;
          DoRegister
        else
                print ${BOLD}
                print -n "\t\tEnter a 1 to install Trend VCS."
                print ${UNBOLD}
		PressAnyKey
                return
        fi
        return
}

function InstallCVPOnly
{
        # start install cvp pkg and check the licence
     if [ "$INSTCVP" = "YES" ] ; then 

        # check cvp pkg
        if [ ! -s ./$CVPPKG ] ; then
                print "\t\tCan not find InterScan CVP ($CVPPKG) in current directory." 
                PressAnyKey
                return
        fi
        # check license program exist or not
        if [ ! -s /etc/iscan/license ] ; then
                        print -n " Can not find your license check program"
                        PressAnyKey
                        return
        fi

        Header
        print -n "\tEnter serial number for InterScan VirusWall CVP:"
        print -n ${BOLD}

	SERIAL=""
	read SERIAL
	echo $SERIAL | /etc/iscan/license

        # change pkg into trail version if serial number not match
        if [ $? != 0 ] ; then
                print -n "\tDo you want to install InterScan VirusWall Trial version for CVP?[  ]\b\b" ; read RESP
                ChkResp $RESP "no"
                if [ $RESP = "YES" ] ; then
                        TRIAL="YES"
                        CVPPKG="iscvp.$TRIAL_EXT"
                else
                        print -n ${UNBOLD}
                        return
                fi
	else
	   sed -e 's/Serial=IS65432/Serial='$SERIAL'/' < /etc/iscan/intscan.ini > /tmp/isli$$
	   cat /tmp/isli$$ >| /etc/iscan/intscan.ini
	   rm -f /tmp/isli$$
        fi
        print -n ${UNBOLD}

	# add on Sep 29th, 1999.
	if [ -d /tmp/pkgcvp ] ; then
		/bin/rm -rf /tmp/pkgcvp
	fi

        # begin to install CVP
        (cd /tmp ; mkdir pkgcvp )
        /bin/zcat < ./$CVPPKG | (cd /tmp/pkgcvp ; tar xf - )
        pkgadd -d /tmp/pkgcvp -R "$CVPPATH" ISCVP
        if [ $? -ne 0 ] ; then
                echo $ERROR_LINE >> /usr/tmp/iscan_install_log
                rm -rf $CVPPATH
        else
                ISCVP="Installed"
          	chmod 4555 /etc/iscan/iscvp
		chmod 4555 /etc/iscan/S99IScvp
        fi
        PressAnyKey
        rm -rf /tmp/pkgcvp
        INSTCVP="NO"
      fi 
} 

function InstallTVCSOnly
{
	Header

        if [[ "$INSTTVCS" = "YES" && "$ISTVCS" = "Installed" ]] ; then
                print "\t\t${BOLD}InterScan TVCS has been installed in your system${UNBOLD}"
		PressAnyKey
                INSTTVCS="NO"
        fi

if [ "$INSTTVCS" = "YES" ] ; then
                if [ ! -s ./$TVCSPKG ] ; then
                        print "\t\tCan not find InterScan TVCS ($TVCSPKG ) in current directory." 
                        PressAnyKey
                        return
                fi

		# add on Sep 29th, 1999.
		if [ -d /tmp/pkgtvcs ] ; then
			/bin/rm -rf /tmp/pkgtvcs
		fi

                ( cd /tmp ; mkdir pkgtvcs )
                /bin/zcat < ./$TVCSPKG | ( cd /tmp/pkgtvcs ; tar xf - )
                pkgadd -d /tmp/pkgtvcs -R "$TVCSPATH" ISTVCS
                if [ $? -ne 0 ] ; then
                        echo $ERROR_LINE >> /usr/tmp/iscan_install_log
                        rm -rf $TVCSPATH
                else
                  print
                  print "\tNote: Be sure to register this InterScan Agent."  
		  ISTVCS="Installed" 
		  INSTTVCS="NO" 
		  chmodtvcs_root_to_iscan
                fi
                print
                PressAnyKey
                rm -rf /tmp/pkgtvcs
        fi
}

function InstallADMOnly 
{

    Header

    if [[ "$INSTADMIN" = "YES" && "$ISADMIN" = "Installed" ]] ; then
	print "\t\t${BOLD}InterScan ADMIN has been installed in your system${UNBOLD}"
	PressAnyKey
	INSTADMIN="NO"
    fi

      #	print "\t\t${BOLD}Start Install IScan Admin...!${UNBOLD}\n" 

	if [ "$INSTADMIN" = "YES" ] ; then
		#if [ "x$IS_LANG" = "xEN" ] ; then
		if [ "$IS_LANG" = "EN" ] ; then
			ADMINPKG="isadmin.en.tz"
		else
			ADMINPKG="isadmin.tz"
		fi

                if [ ! -s ./$ADMINPKG ] ; then
                        print "\t\tCan not find InterScan Admin ($ADMINPKG) in current directory." 
                        PressAnyKey
                        return
                fi

		# add on Sep 29th, 1999.
		if [ -d /tmp/pkgadmin ] ; then
			/bin/rm -rf /tmp/pkgadmin
		fi

                ( cd /tmp ; mkdir pkgadmin )
                /bin/zcat < ./$ADMINPKG | ( cd /tmp/pkgadmin ; tar xf - )
                pkgadd -d /tmp/pkgadmin -R "$ADMINPATH" ISADMIN
                if [ $? -ne 0 ] ; then
                        echo $ERROR_LINE >> /usr/tmp/iscan_install_log
                        rm -rf $ADMINPATH
		else
			ISADMIN="Installed" 
			#songmei 3/22/2000 add. Check if eManager exist,call restore_script
			if [ -s /etc/iscan_plugins/em.dsc ] ; then
			   PLUGEMRESTORE=`grep restore_script /etc/iscan_plugins/em.dsc | sed -e 's/restore_script=//g' `
			   $PLUGEMRESTORE
			fi
			#songmei 3/22/2000 add end
			#songmei 3/23/2000 add. Check if TVCS exist,restore TVCS symbol link
			if [ -s /etc/iscan/pkg/ISTVCS ] ; then
			  for i in ${TVCS_CGI}
			  do
			 	ln -s $TVCSPATH/IScan.TVCS/$i $ADMINPATH/IScan.adm/cgi-bin	
			  done
			  ln -s $TVCSPATH/IScan.TVCS/uninstall.gif $ADMINPATH/IScan.adm/images	
			  ln -s $TVCSPATH/IScan.TVCS/register.gif $ADMINPATH/IScan.adm/images	
			
			fi
			#songmei 3/23/2000 add end
	                chmodadmin_root_to_iscan		
                fi
                PressAnyKey
                rm -rf /tmp/pkgadmin
                INSTADMIN="NO"
        fi
} 

function InstallBASEOnly
{
     Header

     if [ "$INSTBASE" = "YES" ] ; then
	if [ ! -s ./$BASEPKG ] ; then
                print "\t\tCan not find your InterScan Base system  software ( $BASEPKG ) in current directory." 
                PressAnyKey
                return
        fi

	# add on Sep 29th, 1999.
	if [ -d /tmp/pkgbase ] ; then
		/bin/rm -rf /tmp/pkgbase
	fi

          # start install base pkg
          ( cd /tmp ; mkdir pkgbase )
	  /bin/zcat < ./$BASEPKG | ( cd /tmp/pkgbase ; tar xf - )  
	  if [ -f $ISBASE_ENV ] ; then
		rm -f $ISBASE_ENV
	  fi
	  echo "IS_LANG=$IS_LANG" > $ISBASE_ENV
          
	  pkgadd -d /tmp/pkgbase -R "$BASEPATH" ISBASE
          if [ $? -ne 0 ] ; then
                echo $ERROR_LINE >> /usr/tmp/iscan_install_log
                rm -rf $BASEPATH
          else
                ISBASE=Installed
		if [ ! -s /etc/iscan/pkg/ISVWROOT ]; then
			echo $ISVWROOT > /etc/iscan/pkg/ISVWROOT
                fi
	      	if [ ! -d $VIRUSLOGPATH  ] ; then
			mkdir $VIRUSLOGPATH
		fi
		ln -s $VIRUSLOGPATH /etc/iscan/virus

	       #if install cvp, use the intscan.ini of v36
	       if [[ -s /etc/iscan/intscan.ini ]] ; then
		  rm /etc/iscan/intscan.ini
	       fi
	       if [[ -s /etc/iscan/intscan.ini.orig ]] ; then
		  rm /etc/iscan/intscan.ini.orig
	       fi
	       ln -s $BASEPATH/IScan.BASE/intscan.ini.cvp /etc/iscan/intscan.ini
	       ln -s $BASEPATH/IScan.BASE/intscan.ini.cvp.orig /etc/iscan/intscan.ini.orig

               #songmei 3/29/2000 save old intscan.ini to /etc/iscan/old_log_ini
                if [[ -d /tmp/iscan_old ]] ; then
                     if [[ !  -d /etc/iscan/old_log_ini ]] ; then
                        mkdir /etc/iscan/old_log_ini
                     fi
                     if [[ -s /tmp/iscan_old/intscan.ini ]] ; then
                        cp /tmp/iscan_old/intscan.ini /etc/iscan/old_log_ini
                     fi
                fi                            
                #Songmei 3/29/2000 add end

		# Invalid Japanese function. 08/08/2000
		if [ "$IS_LANG" = "EN" ] ; then
			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("jp_func=no\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$
		fi
		###########################################
		# Prepare InterScan 3.7 mail deliver daemon
		###########################################
		cp $BASEPATH/IScan.BASE/S99ISmaild /etc/iscan/
		if [ ! -f /etc/rc2.d/S99ISmaild ] ; then
			cp $BASEPATH/IScan.BASE/ISmaild /etc/rc2.d/S99ISmaild
		fi
		if [[ ! -d /etc/iscan/mailq ]] ; then
			mkdir -p $BASEPATH/IScan.BASE/mailq
			chown -R iscan  $BASEPATH/IScan.BASE/mailq
			chgrp -R iscan  $BASEPATH/IScan.BASE/mailq
		fi
		ln -s $BASEPATH/IScan.BASE/mailq /etc/iscan/
		#ln -s $BASEPATH/IScan.BASE/isdelvd /etc/iscan/isdelvd
		chmod 0755 /etc/rc2.d/S99ISmaild
		chmod 4555 /etc/iscan/S99ISmaild

		START_MAIL_DAEMON="YES"

		Add_Iscan_user
		chmodbase_root_to_iscan
          fi
                PressAnyKey
                rm -rf /tmp/pkgbase
                INSTBASE="NO"
         # checking admin pkg
         if [ ! -s ./$ADMINPKG ] ; then
                print "\t\tCan not find InterScan Admin ( iscanhtp.tz ) in current d
irectory." 
                PressAnyKey
                return
         fi
    fi

}
	
function StartInstallCVP
{

	# if install CVP do the following command.
        # Check if ADMIN pkg installed
	if [[ "$ISADMIN" != "Installed" && "$INSTADMIN" != "YES" ]] ; then
		print "${BOLD}"
		print "\t\tYou have to install InterScan Virus ADMIN system."
		print "${UNBOLD}"
		PressAnyKey
		return
	fi
	if [ $ISBASE != "Installed" ] ; then 
		InstallBASEOnly 
		InstallADMOnly
		InstallCVPOnly
		InstallTVCSOnly	
		
		#NKO create nessecary link
		ASenvironPATH="$ISVWROOT/ISBASE/IScan.BASE/ASenviron.csh"
		AStopPATH="$ISVWROOT/ISBASE/IScan.BASE/AStop.csh"
		upiniPATH="$ISVWROOT/ISBASE/IScan.BASE/upini"
		if [ ! -r "/etc/iscan/ASenviron.csh" ] ; then
			ln -s $ASenvironPATH /etc/iscan/ASenviron.csh
		fi
		if [ ! -r "/etc/iscan/AStop.csh" ] ; then
			ln -s $AStopPATH /etc/iscan/AStop.csh
		fi
		if [ ! -r "/etc/iscan/upini" ] ; then
			ln -s $upiniPATH /etc/iscan/upini
		fi
	
	else 
		## Install ADM PKG
		#	InstallADMOnly
		# start install cvp pkg and check the licence
		# check cvp pkg
		
		if [ "$INSTCVP" = "YES" ] ; then 
			if [ "$ISCVPTRIAL" = "1" ] ; then
				Header
				print ${BOLD}
				print "\tYou are currently running CVP Trial Version.\n"
				print ${UNBOLD}
				print -n "\tDo you want to re-install InterScan VirusWall for CVP?[  ]\b\b" ; read RESP
				ChkResp $RESP "no"
				if [ "$RESP" = "YES" ] ; then
					print -n "Removing the TRIAL VERSION."
					# pkgrm -R `cat /etc/iscan/pkg/ISCVP` ISCVP
					StartRemove "CVP" 
					CVPPKG="iscvp.tz"
				else
					#  print -n ${UNBOLD}
					INSTCVP="NO" 
					return
				fi
				ISCVPTRIAL=0
				InstallADMOnly
				InstallCVPOnly 
				InstallTVCSOnly  
				return 
			fi
			
			## if CVP (but not trial version )already installed
			if [[ "$ISCVP" = "Installed" ]] ; then 	
				clear
				Header
				print ${BOLD} 
				print -n "\t\tYou are currently running InterScan for CVP.\n"
				print -n "\t\tPlease remove it before installing this version.\n"
				print ${UNBOLD} 
				print -n "\t\tDo you want to remove it now? [     ]\b\b\b\b\b" ; read RESP 
				ChkResp $RESP "no"
				if  [ "$RESP" = "YES" ] ; then 
					StartRemove "CVP" 
					InstallADMOnly 
					InstallCVPOnly
					InstallTVCSOnly 
					return 
				else
					INSTCVP="NO" 
					return
				fi 
			fi 
			
			## If there is Old Base and Admin exist.
			if [[ "$ISFTP" = "Installed" || "$ISSMTP" = "Installed" || "$ISHTTP" = "Installed" ]] ; then
				print ${BOLD} 
				print -n "\tIf you are running InterScan VirusWall version 3.7 or earlier, \n"
				print -n "\tyou must remove ALL packages before installing the CVP version.\n"
				print -n "\tDo you want to do this now?\n" 
				print
				print -n "\t\tyes -- remove all packages \n"
				print -n "\t\tno -- remove smtp, http, ftp only\n"
				print -n "\t\tquit \n" 
				print ${UNBOLD}
				print -n "\tDo you want to remove all the packages?[     ]\b\b\b\b\b" ; read RESP
				ChkResp $RESP "no"
				if [ "$RESP" = "YES" ] ; then
					### If ISTVCS already installed than reinstalled after remove
					## All the package
					if [ "$ISTVCS" = "Installed" ] ; then
						INSTTVCS="YES"
					fi
					RemoveAll	
					clear
					#	print -n "\tStarting CVP installation ...\n" 
					print 
					StartInstallCVP  
					return 
				fi
				if [ "$RESP" = "NO" ]  ; then 	
					# keep the base and admin. 
					if [[ "$ISFTP" = "Installed" ]] ; then
						StartRemove "FTP"
					fi
					if [[ "$ISHTTP" = "Installed" ]] ; then
						StartRemove "HTTP"
					fi
					if [[ "$ISSMTP" = "Installed" ]] ; then
						StartRemove "SMTP"
					fi
					InstallADMOnly 
					InstallCVPOnly  
					InstallTVCSOnly 
					return 
				fi
				if [ "$RESP" = "QUIT" ] ; then 	
					return 
				fi
			else 
				Ther is no Other InterScan viruswall installed 
				InstallADMOnly
				InstallCVPOnly   
				InstallTVCSOnly 
				return 
			fi
		fi 
		InstallADMOnly   
		InstallTVCSOnly
		
		#NKO create nessecary link
		ASenvironPATH="$ISVWROOT/ISBASE/IScan.BASE/ASenviron.csh"
		AStopPATH="$ISVWROOT/ISBASE/IScan.BASE/AStop.csh"
		upiniPATH="$ISVWROOT/ISBASE/IScan.BASE/upini"
		if [ ! -r "/etc/iscan/ASenviron.csh" ] ; then
			ln -s $ASenvironPATH /etc/iscan/ASenviron.csh
		fi
		if [ ! -r "/etc/iscan/AStop.csh" ] ; then
			ln -s $AStopPATH /etc/iscan/AStop.csh
		fi
		if [ ! -r "/etc/iscan/upini" ] ; then
			ln -s $upiniPATH /etc/iscan/upini
		fi
	fi
	
}

function FirstPageCVP
{
        typeset done=false

	INSTALLCVP="YES"

        while [[ $done = false ]] ; do
        done=true
        {

         Header
         print "\t\tMain Menu"
         print
	 MainStatusCVP 
         print
         print "\t1.\tInstall InterScan CVP sub-system."
         #print
         print "\t2.\tRemove InterScan CVP sub-system."
         #print
         print "\t3.\tRegister InterScan with a Trend VCS server."
         #print
	 print "\t4.\tConfigure InterScan CVP via Web browser (exit Setup)."
	 #print
	 print "\t5.\tBack to the First Page."
	 #print
	 print "\t6.\tExit."
	} >&2
	print ; print
        print -n " \tSelect a number [   ]\b\b\b";read RESP 
	case $RESP in
        1 ) checkpath; InstallCVP ;;
        2 ) RemoveCVP ;; 
	3 ) VCCRegister ; done=false ;; 
	4 ) BringupBrowser ; done=false;;
	5 ) Main ; done=false;;
	6 ) Exit ;;
	* ) print "\t\tAn invalid choice was entered. Please try again."
            done=false ;;
        esac

        done
}

function InstallCVP
{
        ChkPkg
        ChkConfig 

	while ( true ); do
        Header
	print "\t\tInstall InterScan VirusWall Base System\t${DASH}[ ${BOLD}${INSTBASE}${UNBOLD}]"
        print "\t\tInstallation Path\t${BOLD}${BASEPATH}${UNBOLD}"
	print "\t\tInstall InterScan VirusWall CGI Admin\t${DASH}[ ${BOLD}${INSTADMIN}${UNBOLD}]"
	print "\t\tInstallation Path\t${BOLD}${ADMINPATH}${UNBOLD}"
        print "\t\tInstall InterScan VirusWall CVP System\t${DASH}[ ${BOLD}${INSTCVP}${UNBOLD}]"
        print "\t\tInstallation Path\t${BOLD}${CVPPATH}${UNBOLD}"
        print "\t\tInstall InterScan VirusWall for TVCS\t${DASH}[ ${BOLD}${INSTTVCS}${UNBOLD}]"
        print "\t\tInstallation Path\t${BOLD}${TVCSPATH}${UNBOLD}"
	print "\t\tInterScan VirusWall Package Language\t${DASH}[ ${BOLD}${IS_LANG}${UNBOLD}]"
        print
	{
	print "\t1.\tModify option for InterScan VirusWall for BASE."
        print "\t2.\tModify option for InterScan VirusWall for ADMIN."
        print "\t3.\tModify option for InterScan VirusWall for CVP. "
	print "\t4.\tModify option for InterScan VirusWall for TVCS."
	print "\t5.\tAdministration."
	print "\t6.\tModify Package Language."
 	print "\t7.\tStart installation."
        print "\t8.\tBack to Main Menu."
	} >&2	
	print
        print -n "              Select a number [   ]\b\b\b" ; read RESP
	case $RESP in
	1 ) Modify BASE ;;
        2 ) Modify ADMIN ;;
        3 ) Modify CVP ;;
	4 ) Modify TVCS ;; 
	5 ) ChangeAdmin ;;
	6 ) ChangeLang ;;
	7 ) StartInstall ;;
	8 ) FirstPageCVP ;;
        * ) print "${BELL}\t\tAn invalid choice was entered. Please try again."
        esac
        done
}	

function RemoveAll
{
	    if [[ "$ISTVCS" = "Installed" ]] ; then
                StartRemove "TVCS"
            fi
            if [[ "$ISFTP" = "Installed" ]] ; then
                StartRemove "FTP"
            fi
            if [[ "$ISHTTP" = "Installed" ]] ; then
                StartRemove "HTTP"
            fi
            if [[ "$ISSMTP" = "Installed" ]] ; then
                StartRemove "SMTP"
            fi
            if [[ "$ISCVP" = "Installed" ]] ; then
                StartRemove "CVP"
            fi
            if [[ "$ISADMIN" = "Installed" ]] ; then
                StartRemove "ADMIN"
            fi
            if [[ "$ISBASE" = "Installed" ]] ; then
                StartRemove "BASE"
            fi 
}

function UpgradeBackfile
{
    DELETE_FILES=".htpasswd .tvcs InterScanCmd.ftp InterScanCmd.http InterScanCmd.smtp JavaScan.zip S88sendmail.orig arglist cleanscan config daemonhup.sh eoiscan.input gentrial getconf index.html install.html intscan.ini intscan.ini.orig ip iscanpsw iscvp iscvp.conf isftpd ishttpd isswitch.cgi jsapi.dll libvsapi.so license macr$gen.600 macro.lst office_update officecall.ini old_log_ini opsec_putkey perfmon pkg prescan.cgi sendmail setupex.exe shutdown.cgi solar.ini srvscan start.cgi tvcs_unint.sh upgrade uplog vcagt virinfo virus vsapi32.dll vscan"

    for i in ${DELETE_FILES} ; do
	d_file="/tmp/backupgr.$$/iscan/$i"
	if [[ -f $d_file || -d $d_file || -h $d_file ]] ; then
	    rm -rf $d_file
	fi
    done

    (cd /tmp/backupgr.$$/iscan ; tar cf - * | ( cd /etc/iscan ; tar xf - ) )

    rm -rf /tmp/backupgr.$$
}

function UpgradeINIfile
{

############
#
# hostname
#
grep "TVCS" /tmp/upgr.ini > /dev/null
if [ $? -ne 0 ] ;then
ed /tmp/upgr.ini << T_EOF > /dev/null
/hostname=www.trendmicro.com
d
a
hostname=isux-p1k.update.trendmicro.com
.
w
q
T_EOF

else
ed /tmp/upgr.ini << T_EOF > /dev/null
/hostname=www.trendmicro.com
d
i
hostname=isux-p1k.update.trendmicro.com
.
w
q
T_EOF

fi

############
#
# Version
#
ed /tmp/upgr.ini << T_EOF > /dev/null
/Version=3.5 for
d
i
Version=3.7 for Solaris
.
w
q
T_EOF

############
#
# Version for 3.7
#
ed /tmp/upgr.ini << T_EOF > /dev/null
/Version=3.6 for
d
i
Version=3.7 for Solaris
.
w
q
T_EOF

}

function StartUpgrade
{
    clear
    

    grep "license=xxxxxx" /etc/iscan/intscan.ini > /dev/null
    if [ $? != 0 ] ;then
        print "\n\tTrial version is installed on this system."
        print "\n\tPlease uninstall it before install InterScan 3.7"
	PressAnyKey
	return
    fi


    # For 3.7 
    # Check the serial
    # If the serial is not valid, trial version will be installed
    if [ ! -s /etc/iscan/license ]
    then
        print -n " Can not find your license check program"
        print -n " Do you want to upgrade to InterScan 3.7 30-day trial version ? [     ]\b\b\b\b\b" ; read RESP < /dev/tty
        ChkResp $RESP "YES"
        if [ "$RESP" = "YES" ] ; then
		UPGRADE_TRIAL="YES"
        else
		return
        fi
    else
	SERIAL_LIC=`awk -F"=" '/^Serial.*/ { print $2 }' < /etc/iscan/intscan.ini`
	echo $SERIAL_LIC | /etc/iscan/license > /dev/null
	if [ "$?" != "0" ] ; then
		print -n "\n\tInstalled version is not registered."
	        print -n "\n\tPlease input your serial number for InterScan VirusWall"
		print ;
	        print -n "\n\tOr hit ENTER to upgrade to 30-day trial version:"
		print -n ${BOLD}

		SERIAL=""
		read UPGR_SERIAL
		echo $UPGR_SERIAL | /etc/iscan/license

		if [ "$?" = "0" ] ; then
			# Serial valid
			print "\n\tAccept valid serial number."
			print "\n\tUpgrade to InterScan ordinary version."
			PressAnyKey
			print "\n"
			UPGRADE_TRIAL="NO"
		else
			# Serial NOT valid
			print -n " Do you want to upgrade to InterScan 3.7 30-day trial version ? [     ]\b\b\b\b\b" ; read RESP < /dev/tty
			ChkResp $RESP "YES"
			if [ "$RESP" = "YES" ] ; then
				UPGRADE_TRIAL="YES"
				UPGR_SERIAL="IS65432"
			else
				return
			fi
		fi
	else
		# Serial valid
		UPGRADE_TRIAL="NO"
		UPGR_SERIAL="";

	fi
    fi

    cp /etc/iscan/intscan.ini /tmp/upgr.ini
    mkdir /tmp/backupgr.$$
    (cd /etc ; tar cf - iscan | ( cd /tmp/backupgr.$$ ; tar xf - ) )


    print "\t-----------------------------------------------------------"
    print "\t${BOLD} Please respond to all remaining messages with \"yes\". ${UNBOLD}"
    print "\t-----------------------------------------------------------"
    PressAnyKey

    ##### Remove TVCS
    if [ "$UPGRTVCS" = "YES" ] ; then
	TVCSPATH=`cat /etc/iscan/pkg/ISTVCS`

	# NKO JP-1366 2001/05/07
	# backup TVCS log file before remove package

	TVCSFILE="$TVCSPATH/IScan.TVCS/tvcs"
	if [ -f $TVCSFILE ] ; then
	    cp -p $TVCSFILE /tmp/tvcs
	fi

	pkgrm -R "$TVCSPATH" ISTVCS
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	fi
    fi

    ##### Remove SMTP
    if [ "$UPGRSMTP" = "YES" ] ; then
	SMTPPATH=`cat /etc/iscan/pkg/ISSMTP`
	#if [ -x $SMTPPATH/IScan.SMTP/issmtpd.trial ] ; then
	if [ "$UPGRADE_TRIAL" = "YES" ] ; then
	    ISSMTPTRIAL=1
	    SMTPPKG="issmtp.$TRIAL_EXT"
	fi
	pkgrm -R "$SMTPPATH" ISSMTP
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	fi
    fi

    ##### Remove HTTP
    if [ "$UPGRHTTP" = "YES" ] ; then
	HTTPPATH=`cat /etc/iscan/pkg/ISHTTP`
	#if [ -x $HTTPPATH/IScan.HTTP/ishttpd.trial ] ; then
	if [ "$UPGRADE_TRIAL" = "YES" ] ; then
	    ISHTTPTRIAL=1
	    #HTTPPKG="ishttp.$TRIAL_EXT"
	    # HIP http package is same name
	    HTTPPKG="ishttp.tz"
	fi
	pkgrm -R "$HTTPPATH" ISHTTP
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	fi
    fi

    ##### Remove FTP
    if [ "$UPGRFTP" = "YES" ] ; then
	FTPPATH=`cat /etc/iscan/pkg/ISFTP`
	#if [ -x $FTPPATH/IScan.FTP/isftpd.trial ] ; then
	if [ "$UPGRADE_TRIAL" = "YES" ] ; then
	    ISFTPTRIAL=1
	    FTPPKG="isftp.$TRIAL_EXT"
	fi
	pkgrm -R "$FTPPATH" ISFTP
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	fi
    fi

    ##### Remove CVP
    if [ "$UPGRCVP" = "YES" ] ; then
	CVPPATH=`cat /etc/iscan/pkg/ISCVP`
	#if [ -x $CVPPATH/IScan.CVP/iscvp.trial ] ; then
	if [ "$UPGRADE_TRIAL" = "YES" ] ; then
	    ISCVPTRIAL=1
	    CVPPKG="iscvp.$TRIAL_EXT"
	fi
	pkgrm -R "$CVPPATH" ISCVP
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	fi
    fi

    ##### Remove ADMIN
    if [ "$UPGRADMIN" = "YES" ] ; then
	ADMINPATH=`cat /etc/iscan/pkg/ISADMIN`
	pkgrm -R "$ADMINPATH" ISADMIN
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	fi
    fi

    ##### Remove BASE
    if [ "$UPGRBASE" = "YES" ] ; then
	ISPATH=`cat /etc/iscan/pkg/ISVWROOT`
	ISVWROOT=$ISPATH
	VIRUSLOGPATH=$ISPATH\/virus
	BASEPATH=`cat /etc/iscan/pkg/ISBASE`
	pkgrm -R "$BASEPATH" ISBASE
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	fi

    fi

    ##### Install BASE
    if [ "$UPGRBASE" = "YES" ] ; then
	if [ ! -s ./$BASEPKG ] ; then
	    print "\t\tCan not find your InterScan Base system  software ( $BASEPKG ) in current directory." 
	    PressAnyKey
	    return
	fi
	if [ -d /tmp/pkgbase ] ; then
	    /bin/rm -rf /tmp/pkgbase
	fi
	( cd /tmp ; mkdir pkgbase )
	/bin/zcat < ./$BASEPKG | ( cd /tmp/pkgbase ; tar xf - )  
	if [ -f $ISBASE_ENV ] ; then
	    rm -f $ISBASE_ENV
	fi
	echo "IS_LANG=$IS_LANG" > $ISBASE_ENV
	echo "y\n" | pkgadd -d /tmp/pkgbase -R "$BASEPATH" ISBASE
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $BASEPATH
	else
	    if [ ! -s /etc/iscan/pkg/ISVWROOT ] ; then
		echo $ISVWROOT > /etc/iscan/pkg/ISVWROOT
	    fi
	    if [ ! -d $VIRUSLOGPATH  ] ; then
		mkdir $VIRUSLOGPATH
	    fi
	    ln -s $VIRUSLOGPATH /etc/iscan/virus
	    if [ ! -d $PLUGINPATH ] ; then
		mkdir $PLUGINPATH
	    fi
	    if [ ! -d $PLUGINSPATH ] ; then
		mkdir $PLUGINSPATH
	    fi
	    # Invalid Japanese function. 08/08/2000
	    if [ "$IS_LANG" = "EN" ] ; then
		awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("jp_func=no\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
		cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
		rm -f /tmp/jpfunc.$$
	    fi
	fi

	###########################################
	# Prepare InterScan 3.7 mail deliver daemon
	###########################################
	if [ "$UPGRBASE" = "YES" ] ; then

		cp $BASEPATH/IScan.BASE/S99ISmaild /etc/iscan/
		if [ ! -f /etc/rc2.d/S99ISmaild ] ; then
		    cp $BASEPATH/IScan.BASE/ISmaild /etc/rc2.d/S99ISmaild
		fi

		if [[ ! -d /etc/iscan/mailq ]] ; then
		    mkdir -p $BASEPATH/IScan.BASE/mailq
		fi
		ln -s $BASEPATH/IScan.BASE/mailq /etc/iscan/

		#ln -s $BASEPATH/IScan.BASE/isdelvd /etc/iscan/isdelvd

		chmod 0755 /etc/rc2.d/S99ISmaild
		chmod 4555 /etc/iscan/S99ISmaild

	fi


	rm -rf /tmp/pkgbase
	rm -f $ISBASE_ENV
    fi

    ##### Install ADMIN
    if [ "$UPGRADMIN" = "YES" ] ; then
	if [ "$IS_LANG" = "EN" ] ; then
	    ADMINPKG="isadmin.en.tz"
	else
	    ADMINPKG="isadmin.tz"
	fi
	if [ ! -s ./$ADMINPKG ] ; then
	    print "\t\tCan not find InterScan Admin ( $ADMINPKG ) in current directory." 
	    PressAnyKey
	    return
	fi
	if [ -d /tmp/pkgadmin ] ; then
	    /bin/rm -rf /tmp/pkgadmin
	fi
	( cd /tmp ; mkdir pkgadmin )
	/bin/zcat < ./$ADMINPKG | ( cd /tmp/pkgadmin ; tar xf - )
	echo "y\n" | pkgadd -d /tmp/pkgadmin -R "$ADMINPATH" ISADMIN
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $ADMINPATH
	else
	    if [ -s /etc/iscan_plugins/em.dsc ] ; then
		PLUGEMRESTORE=`grep restore_script /etc/iscan_plugins/em.dsc | sed -e 's/restore_script=//g' `
		$PLUGEMRESTORE
	    fi
	    # Check if TVCS exist,restore TVCS symbol link
	    if [ -s /etc/iscan/pkg/ISTVCS ] ; then
	       for i in ${TVCS_CGI}
	       do
	 	   ln -s $TVCSPATH/IScan.TVCS/$i $ADMINPATH/IScan.adm/cgi-bin	
	       done
	       ln -s $TVCSPATH/IScan.TVCS/uninstall.gif $ADMINPATH/IScan.adm/images	
	       ln -s $TVCSPATH/IScan.TVCS/register.gif $ADMINPATH/IScan.adm/images	
			
	    fi
	    chmodadmin_root_to_iscan		
	fi
	rm -rf /tmp/pkgadmin
    fi


    ##### Install CVP
    if [ "$UPGRCVP" = "YES" ] ; then
	if [ ! -s ./$CVPPKG ] ; then
	    print "\t\tCan not find InterScan CVP ( $CVPPKG ) in current directory." 
	    PressAnyKey
	    return
	fi
	if [ -d /tmp/pkgcvp ] ; then
	    /bin/rm -rf /tmp/pkgcvp
	fi
	(cd /tmp ; mkdir pkgcvp )
	/bin/zcat < ./$CVPPKG | (cd /tmp/pkgcvp ; tar xf - )
	echo "y\n" | pkgadd -d /tmp/pkgcvp -R "$CVPPATH" ISCVP
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $CVPPATH
        else
          chmod 4555 /etc/iscan/iscvp
	  chmod 4555 /etc/iscan/S99IScvp
	fi
	rm -rf /tmp/pkgcvp
    fi

    ##### Install FTP
    if [ "$UPGRFTP" = "YES" ] ; then
	if [ ! -s ./$FTPPKG ] ; then
	    print "\t\tCan not find your InterScan FTP ( $FTPPKG ) in current directory." 
	    PressAnyKey
	    return
	fi
	if [ -d /tmp/pkgftp ] ; then
	    /bin/rm -rf /tmp/pkgftp
	fi
	( cd /tmp ; mkdir pkgftp )
	/bin/zcat < ./$FTPPKG | ( cd /tmp/pkgftp ; tar xf - )  
	echo "y\n" | pkgadd -d /tmp/pkgftp -R "$FTPPATH" ISFTP
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $FTPPATH
        else
	   chmod 4555 /etc/iscan/isftpd
	   chmod 4555 /etc/iscan/S99ISftp
	fi
	rm -rf /tmp/pkgftp
    fi

    ##### Install HTTP
    if [ "$UPGRHTTP" = "YES" ] ; then
	if [ ! -s ./$HTTPPKG ] ; then
	    print "\t\tCan not find InterScan HTTP ( $HTTPPKG ) in current directory." 
	    PressAnyKey
	    return
	fi
	if [ -d /tmp/pkghttp ] ; then
	    /bin/rm -rf /tmp/pkghttp
	fi
	( cd /tmp ; mkdir pkghttp )
	/bin/zcat < ./$HTTPPKG | ( cd /tmp/pkghttp ; tar xf - )  
	echo "y\n" | pkgadd -d /tmp/pkghttp -R "$HTTPPATH" ISHTTP
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $HTTPPATH
        else
	   chmod 4555 /etc/iscan/ishttpd
	   chmod 4555 /etc/iscan/S99ISproxy
	fi
	rm -rf /tmp/pkghttp
    fi

    ##### Install SMTP
    if [ "$UPGRSMTP" = "YES" ] ; then
	if [ ! -s ./$SMTPPKG ] ; then
	    print "\t\tCan not find InterScan E_MAIL ( $SMTPPKG ) in current directory." 
	    PressAnyKey
	    return
	fi
	if [ -d /tmp/pkgsmtp ] ; then
	    /bin/rm -rf /tmp/pkgsmtp
	fi
	( cd /tmp ; mkdir pkgsmtp )
	/bin/zcat < ./$SMTPPKG | ( cd /tmp/pkgsmtp ; tar xf - )  
	echo "y\n" | pkgadd -d /tmp/pkgsmtp -R "$SMTPPATH" ISSMTP
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $SMTPPATH
        else
          chmod 4555 /etc/iscan/sendmail
	  chmod 4555 /etc/iscan/S88sendmail
          chmod 555 /etc/rc2.d/S99ISsmtp
	fi
	rm -rf /tmp/pkgsmtp
    fi

    ##### Install TVCS
    if [ "$UPGRTVCS" = "YES" ] ; then
	if [ ! -s ./$TVCSPKG ] ; then
	print "\t\tCan not find InterScan TVCS ( $TVCSPKG ) in current directory." 
	PressAnyKey
	return
	fi
	if [ -d /tmp/pkgtvcs ] ; then
	    /bin/rm -rf /tmp/pkgtvcs
	fi
	( cd /tmp ; mkdir pkgtvcs )
	/bin/zcat < ./$TVCSPKG | ( cd /tmp/pkgtvcs ; tar xf - )
	echo "y\n" | pkgadd -d /tmp/pkgtvcs -R "$TVCSPATH" ISTVCS
	if [ $? -ne 0 ] ; then
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $TVCSPATH
        else
            print
            print "\tNote: Be sure to register this InterScan Agent."  
	    ISTVCS="Installed" 
	    INSTTVCS="NO" 
	    chmodtvcs_root_to_iscan
	fi
	rm -rf /tmp/pkgtvcs

	# NKO JP-1366 2001/05/07
	# backup TVCS log file 
	if [ -f /tmp/tvcs ] ; then
	    cp -p  /tmp/tvcs $TVCSFILE
	    rm /tmp/tvcs
	fi

    fi

    UpgradeBackfile
    
    UpgradeINIfile

    /etc/iscan/upini /tmp/upgr.ini /etc/iscan/intscan.ini > /tmp/upgr2.ini
    sed 's/ $//g' < /tmp/upgr2.ini >| /etc/iscan/intscan.ini
    rm -f /tmp/upgr.ini /tmp/upgr2.ini

    ##################
    # create pid directory 
    ##################
    if [ ! -d /etc/iscan/pids ] ; then
	mkdir -p /etc/iscan/pids
    fi


    ###########################################
    # Prepare InterScan 3.7 mail deliver daemon
    ###########################################
    if [ "$UPGRBASE" = "YES" ] ; then

	print "\t${BOLD} Starting mail delivery daemon... ${UNBOLD}"
	# start the daemon
	/etc/rc2.d/S99ISmaild stop   > /dev/null
	/etc/rc2.d/S99ISmaild start  > /dev/null
    fi

    ##################
    # Create link for http perfmon
    ##################
    if [ ! -f /etc/iscan/perfmonhttp ] ; then
        ln -s $BASEPATH/IScan.BASE/perfmonhttp /etc/iscan/perfmonhttp
    fi

    ##################
    # Create link for mail q util
    ##################
    if [ ! -f /etc/iscan/changemq ] ; then
        ln -s $BASEPATH/IScan.BASE/changemq /etc/iscan/changemq
    fi
    if [ ! -f /etc/iscan/mailqutil ] ; then
        ln -s $BASEPATH/IScan.BASE/mailqutil /etc/iscan/mailqutil
    fi

    ##################
    # Performance setting 
    ##################
    
    MAX_PROC=`awk -F"=" 'BEGIN { x = 0 } /^[http].*/ { x = 1 }  /^max_proc.*/ { if(x==1) {print $2 ; exit -1} }' < /etc/iscan/intscan.ini`
    THREAD_P=`awk -F"=" 'BEGIN { x = 0 } /^[http].*/ { x = 1 }  /^thr_per_proc.*/ { if(x==1) {print $2 ; exit -1} }' < /etc/iscan/intscan.ini`
    PRE_SPAWN=`awk -F"=" 'BEGIN { x = 0 } /^[http].*/ { x = 1 }  /^pre_spawn.*/ { if(x==1) {print $2 ; exit -1} }' < /etc/iscan/intscan.ini`
    
    if [[ "$MAX_PROC" = "" || "$MAX_PROC" = "0" ]] ; then
    	MAX_PROC=5
    fi
    if [[ "$THREAD_P" = "" || "$THREAD_P" = "0" ]] ; then
    	THREAD_P=5
    fi
    if [[ "$PRE_SPAWN" = "" || "$PRE_SPAWN" = "0" ]] ; then
    	PRE_SPAWN=2
    fi
    if [ "$PRE_SPAWN" -gt "$MAX_PROC" ] ; then
    	MAX_PROC=$PRE_SPAWN
    fi
    
    R_MAX_PROC=`expr $MAX_PROC \* $THREAD_P / 2`
    R_PRE_SPAWN=`expr $PRE_SPAWN \* $THREAD_P / 2`
    R_MIN_PROC=$R_PRE_SPAWN

    if [ "$R_MAX_PROC" -gt 1024 ] ; then
	R_MAX_PROC=1024
    fi
   
    while ( true ); do
    Header
    	print "\tInterScan VirusWall 3.7 performance setting \n"

	print "\n\tCurrent performance-related parameters of http scan are set as follows.\n"

    	print "\tMaximum number of http scan processes :\t${BOLD}${MAX_PROC}${UNBOLD}"
    	print "\tPre spawn of http scan processes      :\t${BOLD}${PRE_SPAWN}${UNBOLD}"

    	print "\n\tThe InterScan VirusWall 3.7 HTTP scan architecture has been changed."
    	print "\tTo get better performance,"
    	print "\tthe installation script recommends the following settings.\n"
    
    	print "\tMaximum number of http scan processes :\t${BOLD}${R_MAX_PROC}${UNBOLD}"
    	print "\tMinimum number of http scan processes :\t${BOLD}${R_MIN_PROC}${UNBOLD}"
    	print "\tPre spawn of http scan processes      :\t${BOLD}${R_PRE_SPAWN}${UNBOLD}"
    
    	print
    	{
    	 print "\t1.Change maximum number of processes."
    	 print "\t2.Change minimum number of processes."
    	 print "\t3.Change number of pre-spawned processes."
    	 print "\t4.Apply this setting."
    	 print "\t5.Do not change."
    	} >&2
    	print 
    	print -n "		Select a number [   ]\b\b\b" ; read RESP
    
    	case $RESP in
    	1 ) Modify_param MAX ;;
    	2 ) Modify_param MIN ;;
    	3 ) Modify_param PRE ;;
    	4 ) APPLY_FLG="YES" ; break ;;
    	5 ) APPLY_FLG="NO" 	; break ;;
    	* ) print "${BELL}\t\tPlease type a valid choice"
    	esac
    done

    if [ "$APPLY_FLG" = "YES" ] ; then
    	 print "\tChange intscan.ini..."
	/etc/iscan/getconf -s $R_MAX_PROC http max_proc   	> /dev/null
	/etc/iscan/getconf -s $R_PRE_SPAWN http pre_spawn   	> /dev/null
	/etc/iscan/getconf -s $R_MIN_PROC http min_proc   	> /dev/null
    fi

    ################################################
    # Modify intscan.ini to set the serial number
    ################################################
    if [ "$UPGRADE_TRIAL" = "NO" ] ; then
    	if [ "$UPGR_SERIAL" != "" ] ; then
		print "\nWriting serial number to intscan.ini.\n"
		sed -e 's/^Serial=.*/Serial='$UPGR_SERIAL'/' < /etc/iscan/intscan.ini > /tmp/isli$$
		cat /tmp/isli$$ >| /etc/iscan/intscan.ini
		rm -f /tmp/isli$$
		sed -e 's/^license=.*/license=xxxxxx/' < /etc/iscan/intscan.ini > /tmp/isli$$
		cat /tmp/isli$$ >| /etc/iscan/intscan.ini
		rm -f /tmp/isli$$
	fi
    else
	    sed -e 's/Serial=.*/Serial=IS65432/' < /etc/iscan/intscan.ini > /tmp/isli$$
	    cat /tmp/isli$$ >| /etc/iscan/intscan.ini
	    rm -f /tmp/isli$$


	    grep "license=xxxxxx" /etc/iscan/intscan.ini > /dev/null
	    if [ $? = 0 ] ;then
		TRIAL_DAYS=30
		LIC=`/etc/iscan/gentrial $TRIAL_DAYS`
		sed -e 's/license=xxxxxx/license='$LIC'/' < /etc/iscan/intscan.ini > /tmp/isli$$
		cat /tmp/isli$$ >| /etc/iscan/intscan.ini
		rm -f /tmp/isli$$
	    fi

    fi


    print 
    print 
    print "\t${BOLD} --- Upgrade finish --- ${UNBOLD}"
    PressAnyKey
}

function Modify_param
{

	case $1 in
	"MAX" )
		print -n "	New value of maximum processes for http scan [     ]\b\b\b\b\b" ; read RESP
		VAL=`echo $RESP | grep "^[0-9]*$"`
		if [[ "$VAL" = "" || "$VAL" = "0" ]] ; then
			print "\n Please enter correct value. \n"
			PressAnyKey
		else
			if [ "$VAL" -gt 1024 ] ; then 
				R_MAX_PROC=1024
			else
				R_MAX_PROC=$VAL
			fi
		fi
		;;
	"MIN" )
		print -n "	New value of minimum processes for http scan [     ]\b\b\b\b\b" ; read RESP
		VAL=`echo $RESP | grep "^[0-9]*$"`
		if [[ "$VAL" = "" || "$VAL" = "0" ]] ; then
			print "\n Please enter correct value. \n"
			PressAnyKey
		else
			if [ "$VAL" -gt 1024 ] ; then 
				R_MIN_PROC=1024
			else
				R_MIN_PROC=$VAL
			fi
		fi
		;;
	"PRE" )
		print -n "	New value of pre spawn processes for http scan [     ]\b\b\b\b\b" ; read RESP
		VAL=`echo $RESP | grep "^[0-9]*$"`
		if [[ "$VAL" = "" || "$VAL" = "0" ]] ; then
			print "\n Please enter correct value. \n"
			PressAnyKey
		else
			if [ "$VAL" -gt 1024 ] ; then 
				R_PRE_SPAWN=1024
			else
				R_PRE_SPAWN=$VAL
			fi
		fi
	esac
	if [ $R_MIN_PROC -gt $R_MAX_PROC ] ; then
		R_MIN_PROC=$R_MAX_PROC
	fi

return 0
}



# NKO CHANGE 
function StartPatchUpgrade
{

    typeset firstchar

    clear

    cp /etc/iscan/intscan.ini /tmp/upgr.ini

    print -n "Do you want to back up replacing files ? ( yes ) [     ]\b\b\b\b\b" ; read RESP < /dev/tty
    ChkResp $RESP "YES"
    if [ "$RESP" = "YES" ] ; then
        BACKUPDIR="/tmp/backupgr.$$"
        print -n "\n\tBy default, Files will be backed up into ${BACKUPDIR} " ;
        print; 
        print -n "\tChoose new path or hit ENTER to use default " ;
        print; 

        while (true) ; do
            print -n "\tNew Path is --- " ; read USERBACKUPDIR
            firstchar=`echo $USERBACKUPDIR | cut -c1`
            if [ "$USERBACKUPDIR" != "" ] ; then
                if [ "$USERBACKUPDIR" = "/etc/iscan" ] ; then
                    print ${BOLD}
                    print "\t\t/etc/iscan is the path for InterScan Viruswall internal use only."
                    print "\t\tPlease change other directory."
                    print ${UNBOLD}
                    PressAnyKey
                    USERBACKUPDIR=`echo $1`
                    continue 
                fi
                if [ "$firstchar" != "/" ] ; then
                    print "Please type in an ${BOLD}ABSOLUTE PATH${UNBOLD}."
                    PressAnyKey
                    USERBACKUPDIR=`echo $1`
                    continue 
                fi	
		# NKO JP-1200	
                if [ -f $USERBACKUPDIR ] ; then
                    print ${BOLD}
                    print "\t\tSpecified directory name already exist as file."
                    print "\t\tPlease change to other directory."
                    print ${UNBOLD}
                    PressAnyKey
                    USERBACKUPDIR=`echo $1`
                    continue 
                fi

                if [ -d $USERBACKUPDIR ] ; then
                    print ${BOLD}
                    print "\t\tSpecified directory already exist."
		    print -n "\t\tDo you want to use this directory for backup ? ( yes ) [     ]\b\b\b\b\b" ; read RESP < /dev/tty
                    print ${UNBOLD}
		    ChkResp $RESP "YES"
		    if [ "$RESP" = "YES" ] ; then
# NKO CHANGE 2001/03/28
	                BACKUPDIR=$USERBACKUPDIR
			break
		    else
	                continue 
                    fi
                fi


                BACKUPDIR=$USERBACKUPDIR
                break
            else
                break
            fi
        done

# NKO CHANGE 2001/03/28
	if [ ! -d $BACKUPDIR ] ; then
	        mkdir -p $BACKUPDIR
	fi

    else
        BACKUPDIR=""
    fi

    
    echo "Extracting archive files...."
    if [ -d /tmp/pkgbase ] ; then
    	/bin/rm -rf /tmp/pkgbase
    fi

    ( cd /tmp ; mkdir pkgbase )
    if [ "$ISBASE" = "Installed" ] ; then
    	/bin/zcat < ./$BASEPKG | ( cd /tmp/pkgbase ; tar xf - )  
    fi
    if [ "$ISADMIN" = "Installed" ] ; then

	# To stop IscanWeb , It may be cause problem usgin S99IScanHttpd
        #/etc/rc2.d/S99IScanHttpd stop > /dev/null
    	/bin/zcat < ./$ADMINPKG | ( cd /tmp/pkgbase ; tar xf - )  

	pid=`/bin/ps -e | /bin/grep IScanWeb | /bin/sed -e 's/^  *//' -e 's/ .*//'`
	if test "$pid"
	then
		kill -9 $pid
	fi
	PIDFILE=`awk -F"=" '/^PIDFILE.*/ { print $2 }' < /etc/rc2.d/S99IScanHttpd `
	rm -f $PIDFILE



    fi
    if [ "$ISCVP" = "Installed" ] ; then
        /etc/rc2.d/S99IScvp stop > /dev/null
    	/bin/zcat < ./$CVPPKG | ( cd /tmp/pkgbase ; tar xf - )  
    else
    	if [ "$ISFTP" = "Installed"  ] ; then 
                /etc/rc2.d/S99ISftp stop > /dev/null
                /bin/zcat < ./$FTPPKG | ( cd /tmp/pkgbase ; tar xf - )  
    	fi
    	if [ "$ISHTTP" = "Installed" ] ; then
                /etc/rc2.d/S99ISproxy stop > /dev/null
                /bin/zcat < ./$HTTPPKG | ( cd /tmp/pkgbase ; tar xf - )  
    	fi
    	if [ "$ISSMTP" = "Installed" ] ; then
                /etc/rc2.d/S88sendmail stop > /dev/null
                /etc/rc2.d/S99ISsmtp stop > /dev/null
                /bin/zcat < ./$SMTPPKG | ( cd /tmp/pkgbase ; tar xf - )  
    	fi
    fi
    if [ "$ISTVCS" = "Installed"  ] ; then 
    	/bin/zcat < ./$TVCSPKG | ( cd /tmp/pkgbase ; tar xf - )  
        /etc/rc2.d/S99IStvcs stop > /dev/null
    fi
    
    ISVWROOT=`cat /etc/iscan/pkg/ISVWROOT`

    clear
    

    if [ ! $CHANGESFILELOC ] ; then 
        #echo "changes file location is NOT assigned. use current "
        exec 9<&0 < ./Changes
    else
        #echo "changes file location is assigned "
        exec 9<&0 < $CHANGESFILELOC
    fi


    STATUS="IGNORE"
    LINKMODE=""
    while read line
    do

        if [[ "$line" = "[PATCH-PART-START]" && "$STATUS" = "IGNORE" ]] ; then    
	    STATUS="APPLY"
            continue    
        fi
        if [[ "$line" = "[PATCH-PART-END]" && "$STATUS" = "APPLY" ]] ; then    
	    STATUS="IGNORE"
        fi
        if [ "$STATUS" = "IGNORE" ] ; then        
            continue    
        fi


        if [ "$line" = "" ] ; then        
            continue    
        fi

        first_col=`echo $line | cut -d'/' -f2`
        #echo "first_col is $first_col "
        # Ignore other platforms data
    	case $first_col in 
#    	SHELL_SOLARIS )  
#            continue    ;;
    	SHELL_LINUX )  
            continue    ;;
    	SHELL_TRU64 )
            continue    ;;
    	SHELL_HP )
            continue    ;;
    	SHELL_AIX )
            continue    ;;
    	esac

        if [ "$line" = "[LINK]" ] ; then        
            # Label .. ignore  
            LINKMODE="LINKMODE"
            echo "\n\nInstallation script is setting up file links...."
            continue 
	fi


        if [ "$LINKMODE" = "LINKMODE" ] ; then        
            #######################################
            # Acting as static linking  
            #######################################

            left_line=`echo $line | cut -d':' -f1`
            right_line=`echo $line | cut -d':' -f2`

            #echo " left_line " $left_line    # NKO DEBUG
            #echo " right_line " $right_line    # NKO DEBUG
            
            # check if the source is SHELL
            TARGETPKG=`echo $left_line | cut -d'/' -f2`
            if [ "$TARGETPKG" = "SHELL_SOLARIS" ] ; then        
                SHELLINSTALL="YES"
                #echo "source is SHELL "  # NKO DEBUG
            else
                SHELLINSTALL=""
                #echo "source is normal file  "  # NKO DEBUG
            fi
            
            if [ "$SHELLINSTALL" = "YES" ] ; then        
                SOURCEFILE=`echo $left_line | sed -e 's/^\/SHELL_SOLARIS\/ISFTP/\/etc\/rc2.d/g
                                                      s/^\/SHELL_SOLARIS\/ISHTTP/\/etc\/rc2.d/g
                                                      s/^\/SHELL_SOLARIS\/ISSMTP/\/etc\/rc2.d/g
                                                      s/^\/SHELL_SOLARIS\/ISBASE/\/etc\/rc2.d/g
                                                      s/^\/SHELL_SOLARIS\/ISTVCS/\/etc\/rc2.d/g
                                                      s/^\/SHELL_SOLARIS\/ISCVP/\/etc\/rc2.d/g
                                                      s/^\/SHELL_SOLARIS\/ISADMIN\/bin/\/etc\/rc2.d/g' `
            else
                SOURCEFILE=`echo $left_line | sed -e 's/^\/ISFTP/\/ISFTP\/IScan\.FTP/g
                                                 s/^\/ISHTTP/\/ISHTTP\/IScan\.HTTP/g
                                                 s/^\/ISSMTP/\/ISSMTP\/IScan\.SMTP/g
                                                 s/^\/ISBASE/\/ISBASE\/IScan\.BASE/g
                                                 s/^\/ISTVCS/\/ISTVCS\/IScan\.TVCS/g
                                                 s/^\/ISCVP/\/ISCVP\/IScan\.CVP/g
                                                 s/^\/ISADMIN/\/ISADMIN\/IScan\.adm/g' `
            fi

            TARGETFILE=`echo $right_line | sed -e 's/^\/ISFTP/\/ISFTP\/IScan\.FTP/g
                                             s/^\/ISHTTP/\/ISHTTP\/IScan\.HTTP/g
                                             s/^\/ISSMTP/\/ISSMTP\/IScan\.SMTP/g
                                             s/^\/ISBASE/\/ISBASE\/IScan\.BASE/g
                                             s/^\/ISTVCS/\/ISTVCS\/IScan\.TVCS/g
                                             s/^\/ISCVP/\/ISCVP\/IScan\.CVP/g
                                             s/^\/ISADMIN/\/ISADMIN\/IScan\.adm/g' `

            SOURCEFILE="$ISVWROOT$SOURCEFILE"

            #echo " source is $SOURCEFILE "
            #echo " target is $TARGETFILE "

            if [ -r $SOURCEFILE ] ; then
                if [ -r $TARGETFILE ] ; then
                    # once remove old link 
                    rm  $TARGETFILE
                fi
                # create link
                ln -s $SOURCEFILE $TARGETFILE
            fi

            
        else
            #######################################
            # Target is patch file installation
            #######################################

	    # NKO 2001.06.13
	    echo "$line" | grep ".:."  > /dev/null
	    if [ $? = 0 ] ; then
			TARGET_PLATFORM_SW=`echo "$line"  | cut -d':' -f2 `
			if [ "$TARGET_PLATFORM_SW" != "" ] ; then
				# right parameter of ":" is presented
				TARGET_PLATFORM_SW=`echo "$TARGET_PLATFORM_SW" | grep SOLARIS`
				#TARGET_PLATFORM_SW=`echo "$TARGET_PLATFORM_SW" | grep LINUX`
				#TARGET_PLATFORM_SW=`echo "$TARGET_PLATFORM_SW" | grep HP`
				#TARGET_PLATFORM_SW=`echo "$TARGET_PLATFORM_SW" | grep TRU64`
				#TARGET_PLATFORM_SW=`echo "$TARGET_PLATFORM_SW" | grep AIX`
				if [ "$TARGET_PLATFORM_SW" = "" ] ; then
					#echo "Right parameter found, but different platform is specified. ignore.."
					continue
				fi
			fi
			line=`echo "$line"  | cut -d':' -f1`
	    fi

        
            # check exstance of components
            TARGETPKGTMP=`echo $line | cut -d'/' -f2`
            TARGETPKG=`echo $TARGETPKGTMP | sed -e 's/SHELL_SOLARIS/SHELL/g
                                                    s/SHELL_LINUX/SHELL/g
                                                    s/SHELL_TRU64/SHELL/g
                                                    s/SHELL_AIX/SHELL/g
                                                    s/SHELL_HP/SHELL/g' `


            if [ "$TARGETPKG" = "SHELL" ] ; then        
                TARGETPKG=`echo $line | sed -e 's/^\/SHELL_SOLARIS\/ISFTP\/.*/ISFTP/g
                                                s/^\/SHELL_SOLARIS\/ISHTTP\/.*/ISHTTP/g
                                                s/^\/SHELL_SOLARIS\/ISSMTP\/.*/ISSMTP/g
                                                s/^\/SHELL_SOLARIS\/ISBASE\/.*/ISBASE/g
                                                s/^\/SHELL_SOLARIS\/ISTVCS\/.*/ISTVCS/g
                                                s/^\/SHELL_SOLARIS\/ISCVP\/.*/ISCVP/g
                                                s/^\/SHELL_SOLARIS\/ISADMIN\/.*/ISADMIN/g' `
                SHELLINSTALL="YES"
            else
                TARGETPKG=`echo $line | sed -e 's/^\/ISFTP\/.*/ISFTP/g
                                                s/^\/ISHTTP\/.*/ISHTTP/g
                                                s/^\/ISSMTP\/.*/ISSMTP/g
                                                s/^\/ISBASE\/.*/ISBASE/g
                                                s/^\/ISTVCS\/.*/ISTVCS/g
                                                s/^\/ISCVP\/.*/ISCVP/g
                                                s/^\/ISADMIN\/.*/ISADMIN/g' `
                SHELLINSTALL=""
            fi
    
    
            INSTALLFLG=NO
    
            case $TARGETPKG in 
                ISFTP )  if [ "$ISFTP" = "Installed" ] ; then
                INSTALLFLG=YES
            fi  ;;
                ISHTTP )  if [ "$ISHTTP" = "Installed" ] ; then
                INSTALLFLG=YES
            fi  ;;
                ISSMTP )  if [ "$ISSMTP" = "Installed" ] ; then
                INSTALLFLG=YES
            fi  ;;
                ISBASE )  if [ "$ISBASE" = "Installed" ] ; then
                INSTALLFLG=YES
            fi  ;;
                ISTVCS )  if [ "$ISTVCS" = "Installed" ] ; then
                INSTALLFLG=YES
            fi  ;;
                ISCVP )  if [ "$ISCVP" = "Installed" ] ; then
                INSTALLFLG=YES
            fi  ;;
                ISADMIN )  if [ "$ISADMIN" = "Installed" ] ; then
                INSTALLFLG=YES
            fi  ;;
            esac
    
            # nko debug
            #INSTALLFLG="YES"
            #echo "TARGETPKG  is $TARGETPKG"  
    
            if [ "$INSTALLFLG" = "YES" ] ; then
    
                if [ "$SHELLINSTALL" = "YES" ] ; then        
    
                    SOURCEFILE=`echo $line | sed -e 's/^\/SHELL_SOLARIS\/ISFTP/\/tmp\/pkgbase\/ISFTP\/root\/IScan.FTP/g
                                                     s/^\/SHELL_SOLARIS\/ISHTTP/\/tmp\/pkgbase\/ISHTTP\/root\/IScan.HTTP/g
                                                     s/^\/SHELL_SOLARIS\/ISSMTP/\/tmp\/pkgbase\/ISSMTP\/root\/IScan.SMTP/g
                                                     s/^\/SHELL_SOLARIS\/ISBASE/\/tmp\/pkgbase\/ISBASE\/root\/IScan.BASE/g
                                                     s/^\/SHELL_SOLARIS\/ISTVCS/\/tmp\/pkgbase\/ISTVCS\/root\/IScan.TVCS/g
                                                     s/^\/SHELL_SOLARIS\/ISCVP/\/tmp\/pkgbase\/ISCVP\/root\/IScan.CVP/g
                                                     s/^\/SHELL_SOLARIS\/ISADMIN/\/tmp\/pkgbase\/ISADMIN\/root\/IScan.adm/g' `
    
                    TARGETFILE=`echo $line | sed -e 's/^\/SHELL_SOLARIS\/ISFTP/\/ISFTP\/IScan\.FTP/g
                                                     s/^\/SHELL_SOLARIS\/ISHTTP/\/ISHTTP\/IScan\.HTTP/g
                                                     s/^\/SHELL_SOLARIS\/ISSMTP/\/ISSMTP\/IScan\.SMTP/g
                                                     s/^\/SHELL_SOLARIS\/ISBASE/\/ISBASE\/IScan\.BASE/g
                                                     s/^\/SHELL_SOLARIS\/ISTVCS/\/ISTVCS\/IScan\.TVCS/g
                                                     s/^\/SHELL_SOLARIS\/ISCVP/\/ISCVP\/IScan\.CVP/g
                                                     s/^\/SHELL_SOLARIS\/ISADMIN/\/ISADMIN\/IScan\.adm/g' `
    
                    TARGETFILE="$ISVWROOT$TARGETFILE"
    
                    TARGETFILERC=`echo $line | sed -e 's/^\/SHELL_SOLARIS\/ISFTP/\/etc\/rc2.d/g
                                                       s/^\/SHELL_SOLARIS\/ISHTTP/\/etc\/rc2.d/g
                                                       s/^\/SHELL_SOLARIS\/ISSMTP/\/etc\/rc2.d/g
                                                       s/^\/SHELL_SOLARIS\/ISBASE/\/etc\/rc2.d/g
                                                       s/^\/SHELL_SOLARIS\/ISTVCS/\/etc\/rc2.d/g
                                                       s/^\/SHELL_SOLARIS\/ISCVP/\/etc\/rc2.d/g
                                                       s/^\/SHELL_SOLARIS\/ISADMIN\/bin/\/etc\/rc2.d/g' `
    
                    ADDFLG=NO
                    REPLACEFLG=NO
    
                else
    
    
                    SOURCEFILE=`echo $line | sed -e 's/^\/ISFTP/\/tmp\/pkgbase\/ISFTP\/root\/IScan.FTP/g
                                                     s/^\/ISHTTP/\/tmp\/pkgbase\/ISHTTP\/root\/IScan.HTTP/g
                                                     s/^\/ISSMTP/\/tmp\/pkgbase\/ISSMTP\/root\/IScan.SMTP/g
                                                     s/^\/ISBASE/\/tmp\/pkgbase\/ISBASE\/root\/IScan.BASE/g
                                                     s/^\/ISTVCS/\/tmp\/pkgbase\/ISTVCS\/root\/IScan.TVCS/g
                                                     s/^\/ISCVP/\/tmp\/pkgbase\/ISCVP\/root\/IScan.CVP/g
                                                     s/^\/ISADMIN/\/tmp\/pkgbase\/ISADMIN\/root\/IScan.adm/g' `
    
                    TARGETFILE=`echo $line | sed -e 's/^\/ISFTP/\/ISFTP\/IScan\.FTP/g
                                                     s/^\/ISHTTP/\/ISHTTP\/IScan\.HTTP/g
                                                     s/^\/ISSMTP/\/ISSMTP\/IScan\.SMTP/g
                                                     s/^\/ISBASE/\/ISBASE\/IScan\.BASE/g
                                                     s/^\/ISTVCS/\/ISTVCS\/IScan\.TVCS/g
                                                     s/^\/ISCVP/\/ISCVP\/IScan\.CVP/g
                                                     s/^\/ISADMIN/\/ISADMIN\/IScan\.adm/g' `
    
                    TARGETFILE="$ISVWROOT$TARGETFILE"
                    TARGETFILERC=""
    
                    ADDFLG=NO
                    REPLACEFLG=NO
    
                fi        
    
                if [ "$SHELLINSTALL" = "YES" ] ; then        
                    echo "\n\nUpgrade target RC file is " $TARGETFILERC
                else
                    echo "\n\nUpgrade target file is " $TARGETFILE
                fi
    
    
    
# nko debug
#echo "SOURCEFILE  is $SOURCEFILE"  
#echo "TARGETFILE  is $TARGETFILE"  
#if [ "$TARGETFILERC" != "" ] ; then
#echo "TARGETFILERC  is $TARGETFILERC"  
#fi
    
                if [ ! -f $TARGETFILE ] ; then
                    if [ "$ASKYESNO" = "YES" ] ; then
                        print -n "The destination file $TARGETFILE not found.\nDo you want to add this module ? ( yes ) [     ]\b\b\b\b\b" ; read RESP < /dev/tty
                        ChkResp $RESP "YES"
                        if [ "$RESP" = "YES" ] ; then
                            ADDFLG=YES
                        fi
                    else
                        echo "The destination file $TARGETFILE not found. add the file."
                        ADDFLG=YES
                    fi
                else
                    if [ ! -f $SOURCEFILE ] ; then
                	echo "The source file $SOURCEFILE not found. no replaced."
                        continue 
                    fi
                
                    # grep version info from installed target module
                    TARGETVER=`strings $TARGETFILE | grep "Version 3.7-Build" | awk '{param=substr($2, 11); print param;exit}'  `

		    # NKO retry get version info, follow the another format.
                    if [ "$TARGETVER" = ""  ] ; then 
			TARGETVER=`strings $TARGETFILE | grep "Version 3.7-Build" | awk '{param=substr($3, 11); print param;exit}'  `
		    fi

                    if [ $TARGETVER ] ; then 
                        #echo $TARGETFILE  " version info found"
                        SOURCEVER=`strings $SOURCEFILE | grep "Version 3.7-Build" | awk '{param=substr($2, 11); print param;exit}'  `

			# NKO retry get version info, follow the another format.
	                if [ "$SOURCEVER" = ""  ] ; then 
			    SOURCEVER=`strings $SOURCEFILE | grep "Version 3.7-Build" | awk '{param=substr($3, 11); print param;exit}'  `
			fi

                        #echo "Target version is $TARGETVER. source version is $SOURCEVER."
                        if [ $TARGETVER = $SOURCEVER ] ; then 
                             echo "Module is up to date. no need to upgrade for $TARGETFILE."
                        else
                            REPLACEFLG=YES
                	fi
                    else
                        #echo $TARGETFILE  " version info NOT found"
                        cmp -s $TARGETFILE SOURCEFILE
                        if [ $? -ne 0 ] ; then
                            #echo "The file may be differ ......"
                            if [ "$SHELLINSTALL" = "YES" ] ; then        
                                #TINFO=`/usr/bin/ls -l $TARGETFILERC | awk '{printf("File:%s size:%s time:%s %s %s",$9,$5,$6,$7,$8) ;exit}' `
                                TSIZE==`/usr/bin/ls -l $TARGETFILERC | awk '{print($5);exit}' `
                                TTIME==`/usr/bin/ls -l $TARGETFILERC | awk '{print($6 $7 $8);exit}' `
                            else
                                #TINFO=`/usr/bin/ls -l $TARGETFILE | awk '{printf("File:%s size:%s time:%s %s %s",$9,$5,$6,$7,$8) ;exit}' `
                                TSIZE==`/usr/bin/ls -l $TARGETFILE | awk '{print($5);exit}' `
                                TTIME==`/usr/bin/ls -l $TARGETFILE | awk '{print($6 $7 $8);exit}' `
                            fi
                            #SINFO=`/usr/bin/ls -l $SOURCEFILE | awk '{printf("File:%s size:%s time:%s %s %s",$9,$5,$6,$7,$8) ;exit}' `
                            SSIZE==`/usr/bin/ls -l $SOURCEFILE | awk '{print($5);exit}' `
                            STIME==`/usr/bin/ls -l $SOURCEFILE | awk '{print($6 $7 $8) ;exit}' `
                            REPLACEFLG=YES
                        fi
                    fi
                fi
        
                # Existing file replace
                if [ $REPLACEFLG = "YES" ] ; then
                    if [ ! $TARGETVER ] ; then 
                        echo "Installed file is   " 
                        if [ "$SHELLINSTALL" = "YES" ] ; then        
                            echo "    RC File:$TARGETFILERC "
                        else
                            echo "    File:$TARGETFILE "
                        fi
                        echo "    Size:$TSIZE "
                        echo "    Time:$TTIME "
                        echo "Patch module is  "
                        echo "    File:$SOURCEFILE "
                        echo "    Size:$SSIZE "
                        echo "    Time:$STIME "
                        print -n "Do you want to replace installed file with this patch module ?  ( yes ) [     ]\b\b\b\b\b" ; read RESP < /dev/tty
                    else
                        RESP=YES
                        if [ "$ASKYESNO" = "YES" ] ; then
                             print -n "Do you want to upgrade this module ? ( no ) [     ]\b\b\b\b\b" ; read RESP < /dev/tty
                        else
                             RESP=YES
                        fi
                    fi
                    ChkResp $RESP "YES"
                    if [ "$RESP" = "YES" ] ; then
  
                        if [ "$SHELLINSTALL" = "YES" ] ; then        
                            echo "Replacing file  $TARGETFILERC ........." 
                            if [ "$BACKUPDIR" != "" ] ; then
                                cp -p -f $TARGETFILE $BACKUPDIR
                            fi 
                            cp -p -f $SOURCEFILE $TARGETFILERC
                            chown root $TARGETFILERC
                            chgrp sys  $TARGETFILERC
                            chmod 555  $TARGETFILERC
                            cp -p -f $SOURCEFILE $TARGETFILE
                            chown root $TARGETFILE
                            chgrp sys  $TARGETFILE
                            chmod 555  $TARGETFILE

			    # NKO Special proces for S99IScanHttpd(Solaris)

			    IsIscanWebRC=""
                            IsIscanWebRC=`echo $TARGETFILE | grep S99IScanHttpd `
                            if [ "$IsIscanWebRC" != "" ] ; then        
                                echo "Modifying file  $TARGETFILERC ........." 

				PKG_INSTALL_ROOT=`echo $TARGETFILE | awk -F"ISADMIN" '{print($1"ISADMIN");exit}' `
				echo $PKG_INSTALL_ROOT"/IScan.adm" | sed -e 's/\//\\\//g' > /tmp/tmpvar$$
				TMPVAR=`cat /tmp/tmpvar$$` ; rm -f /tmp/tmpvar$$
				sed -e 's/PKG_INSTALL_ROOT/'${TMPVAR}'/g'  ${PKG_INSTALL_ROOT}/IScan.adm/bin/S99IScanHttpd  > /tmp/pp$$
				cp /tmp/pp$$ /etc/rc2.d/S99IScanHttpd 
				rm /tmp/pp$$
                                chown root /etc/rc2.d/S99IScanHttpd
                                chgrp sys /etc/rc2.d/S99IScanHttpd
                                chmod 0755 /etc/rc2.d/S99IScanHttpd

                            fi

                        else
                            echo "Replacing file  $TARGETFILE ........."
                            if [ "$BACKUPDIR" != "" ] ; then
                                cp -p -f $TARGETFILE $BACKUPDIR
                            fi 
                            cp -p -f $SOURCEFILE $TARGETFILE
                            chown root $TARGETFILE
                            chgrp sys  $TARGETFILE
                            chmod 555  $TARGETFILE
                        fi
    
                        echo "Replacing done. "
                    fi
                fi
        
                # Adding new file
                if [ $ADDFLG = "YES" ] ; then
                    echo "Adding file  $SOURCEFILE ........."
                    cp -p -f $SOURCEFILE $TARGETFILE
                    chown root $TARGETFILE
                    chgrp sys  $TARGETFILE
                    chmod 555  $TARGETFILE
                    echo "Adding done. "
                fi
        
            else
                echo "\n\nNo package installed for $TARGETPKG. ignored."
            fi
        
        fi  # if [ "$TARGETLINK" != "" ] ; then        
    done
    
    exec 0<&9 9<&-
    


    #########################################################
    # By dafault Engine and Pattern file would be replaced
    #########################################################

    ################################
    # pattern file
    ################################
    PATTERN_PATH=`cat /etc/iscan/intscan.ini | grep "pattern_path" | cut -d'=' -f2`
    if [ "$PATTERN_PATH" = "" ] ; then
        PATTERN_PATH="/etc/iscan"
    fi
    #echo "PATTERN_PATH is $PATTERN_PATH"

    # NKO JP-1600
    chown root /tmp/pkgbase/ISBASE/root/IScan.BASE/lpt\$vpn.*
    chgrp sys  /tmp/pkgbase/ISBASE/root/IScan.BASE/lpt\$vpn.*
    chmod 400  /tmp/pkgbase/ISBASE/root/IScan.BASE/lpt\$vpn.*

    cp -p /tmp/pkgbase/ISBASE/root/IScan.BASE/lpt\$vpn.* $PATTERN_PATH

    #tmp/pkgbase/ISBASE/root/IScan.BASE 
    ################################
    # scan engine 
    ################################

    TARGET_ENGINE="$ISVWROOT/ISBASE/IScan.BASE/libvsapi.so"
    SOURCE_ENGINE="/tmp/pkgbase/ISBASE/root/IScan.BASE/libvsapi.so"

    #echo "TARGET_ENGINE is $TARGET_ENGINE "
    #echo "SOURCE_ENGINE is $SOURCE_ENGINE "

    #TINFO=`/usr/bin/ls -l $TARGET_ENGINE | awk '{printf("File:%s size:%s time:%s %s %s",$9,$5,$6,$7,$8) ;exit}' `
    TSIZE==`/usr/bin/ls -l $TARGET_ENGINE | awk '{print($5);exit}' `
    TTIME==`/usr/bin/ls -l $TARGET_ENGINE | awk '{print($6 $7 $8);exit}' `
    #SINFO=`/usr/bin/ls -l $SOURCE_ENGINE | awk '{printf("File:%s size:%s time:%s %s %s",$9,$5,$6,$7,$8) ;exit}' `
    SSIZE==`/usr/bin/ls -l $SOURCE_ENGINE | awk '{print($5);exit}' `
    STIME==`/usr/bin/ls -l $SOURCE_ENGINE | awk '{print($6 $7 $8) ;exit}' `

    echo "\n\nPatch installation will install scan engine file into base directory,"
    echo "and create a static link from /etc/iscan "
    echo "Installed Scan engine  "
    echo "    File:$TARGET_ENGINE "
    echo "    Size:$TSIZE "
    echo "    Time:$TTIME "
    echo "Patch module is  "
    echo "    File:$SOURCE_ENGINE "
    echo "    Size:$SSIZE "
    echo "    Time:$STIME "
    print -n "Do you want to continue repracing scan engine ?  ( yes ) [     ]\b\b\b\b\b" ; read RESP < /dev/tty
    ChkResp $RESP "YES"
    if [ "$RESP" = "YES" ] ; then
        cp -p -f $SOURCE_ENGINE $TARGET_ENGINE
        rm /etc/iscan/libvsapi.so
        ln -s $TARGET_ENGINE /etc/iscan/libvsapi.so

	# NKO JP-1600
	chown root $TARGET_ENGINE
	chgrp sys  $TARGET_ENGINE
	chmod 555  $TARGET_ENGINE

    fi

    echo "\n\nupgrading intscan.ini file..."
    UpgradeINIfile

    /etc/iscan/upini /tmp/upgr.ini /tmp/pkgbase/ISBASE/root/IScan.BASE/intscan.ini  > /tmp/upgr2.ini
    sed 's/ $//g' < /tmp/upgr2.ini >| /etc/iscan/intscan.ini
    rm -f /tmp/upgr.ini /tmp/upgr2.ini

    # NKO for P1k , need to change the location of pattern server.
    sed 's/^hostname.*/hostname=isux-p1k.update.trendmicro.com/g' < /etc/iscan/intscan.ini > /tmp/upgr.ini
    cat /tmp/upgr.ini >| /etc/iscan/intscan.ini
    rm -f /tmp/upgr.ini 

    # Restart daemons

    # NKO 06/25/2001
    TMP_CUR_DIR=`pwd`

    # NKO 06/12/2001
    cd /etc/iscan

    if [ "$ISADMIN" = "Installed" ] ; then
        /etc/rc2.d/S99IScanHttpd start > /dev/null
    fi
    if [ "$ISCVP" = "Installed" ] ; then
        /etc/rc2.d/S99IScvp start > /dev/null
    else
    	if [ "$ISFTP" = "Installed"  ] ; then 
            /etc/rc2.d/S99ISftp start > /dev/null
    	fi
    	if [ "$ISHTTP" = "Installed" ] ; then
            /etc/rc2.d/S99ISproxy start > /dev/null
    	fi
    	if [ "$ISSMTP" = "Installed" ] ; then
            /etc/rc2.d/S88sendmail start > /dev/null
            /etc/rc2.d/S99smtp start > /dev/null
    	fi
    fi
    if [ "$ISTVCS" = "Installed"  ] ; then 
        /etc/rc2.d/S99IStvcs start > /dev/null
    fi

    RESTARTFLG="NO"

    # NKO 06/25/2001
    cd $TMP_CUR_DIR

    print "\n\n\nPatch Upgrade finish"
    if [ "$BACKUPDIR" != "" ] ; then
        print "Replaced files have been backed up into $BACKUPDIR"
        print "If it's unnecessary ,please remove the back up directory."
    fi 
    PressAnyKey

    if [ -d /tmp/pkgbase ] ; then
        /bin/rm -rf /tmp/pkgbase
    fi


}

function UpgradeStatus
{

	ChkPkg
	ChkConfig
	while ( true ); do
	Header
	print "\tInterScan VirusWall 3.7 Upgrade List"

	if [ "$ISBASE" = "Installed" ] ; then
		UPGRBASE="YES"
		print "\tUpgrade InterScan VirusWall Base System\t ${DASH} [ ${BOLD}${UPGRBASE}${UNBOLD} ]"
		print "\tInstallation Path\t${BOLD}${BASEPATH}${UNBOLD}"
	fi

	if [ "$ISADMIN" = "Installed" ] ; then
		UPGRADMIN="YES"
		print "\tUpgrade InterScan VirusWall CGI Admin\t ${DASH} [ ${BOLD}${UPGRADMIN}${UNBOLD} ]"
		print "\tInstallation Path\t${BOLD}${ADMINPATH}${UNBOLD}"
	fi

	if [ "$ISCVP" = "Installed" ] ; then
		UPGRCVP="YES"
		print "\tUpgrade InterScan VirusWall for CVP\t ${DASH} [ ${BOLD}${UPGRCVP}${UNBOLD} ]"
		print "\tInstallation Path\t${BOLD}${CVPPATH}${UNBOLD}"
	else
		if [ "$ISFTP" = "Installed"  ] ; then 
			UPGRFTP="YES"
			print "\tUpgrade InterScan VirusWall for FTP\t ${DASH} [ ${BOLD}${UPGRFTP}${UNBOLD} ]"
			print "\tInstallation Path\t${BOLD}${FTPPATH}${UNBOLD}"
		fi

		if [ "$ISHTTP" = "Installed" ] ; then
			UPGRHTTP="YES"
			print "\tUpgrade InterScan VirusWall for HTTP\t ${DASH} [ ${BOLD}${UPGRHTTP}${UNBOLD} ]"
			print "\tInstallation Path\t${BOLD}${HTTPPATH}${UNBOLD}"
		fi

		if [ "$ISSMTP" = "Installed" ] ; then
			UPGRSMTP="YES"
			print "\tUpgrade InterScan VirusWall for E-Mail\t ${DASH} [ ${BOLD}${UPGRSMTP}${UNBOLD} ]"
			print "\tInstallation Path\t${BOLD}${SMTPPATH}${UNBOLD}"
		fi
	fi

	if [ "$ISTVCS" = "Installed"  ] ; then 
		UPGRTVCS="YES"
		print "\tUpgrade TVCS Agent for InterScan\t ${DASH} [ ${BOLD}${UPGRTVCS}${UNBOLD} ]"
		print "\tInstallation Path\t${BOLD}${TVCSPATH}${UNBOLD}"
	fi

	print "\tInterScan VirusWall Package Language\t ${DASH} [ ${BOLD}${IS_LANG}${UNBOLD} ]"
	print
	{
	 print "\t1.\tModify Package Language."
	 print "\t2.\tStart Upgrade."
	 print "\t3.\tBack to Main Menu."
	} >&2
	print 
	print -n "		Select a number [   ]\b\b\b" ; read RESP

	case $RESP in
	1 ) ChangeLang ;;
	2 ) StartUpgrade ; Main ;;
	3 ) Main ;;
	* ) print "${BELL}\t\tPlease type a valid choice"
	esac
	done
}

# NKO CHANGE
function PatchUpgradeStatus
{

	ChkPkg
	ChkConfig
	while ( true ); do
	Header
	print "\tInterScan VirusWall 3.7 Upgrade List"

	if [ "$ISBASE" = "Installed" ] ; then
		UPGRBASE="YES"
		print "\tUpgrade InterScan VirusWall Base System\t ${DASH} [ ${BOLD}${UPGRBASE}${UNBOLD} ]"
		print "\tInstallation Path\t${BOLD}${BASEPATH}${UNBOLD}"
	fi

	if [ "$ISADMIN" = "Installed" ] ; then
		UPGRADMIN="YES"
		print "\tUpgrade InterScan VirusWall CGI Admin\t ${DASH} [ ${BOLD}${UPGRADMIN}${UNBOLD} ]"
		print "\tInstallation Path\t${BOLD}${ADMINPATH}${UNBOLD}"
	fi

	if [ "$ISCVP" = "Installed" ] ; then
		UPGRCVP="YES"
		print "\tUpgrade InterScan VirusWall for CVP\t ${DASH} [ ${BOLD}${UPGRCVP}${UNBOLD} ]"
		print "\tInstallation Path\t${BOLD}${CVPPATH}${UNBOLD}"
	else
		if [ "$ISFTP" = "Installed"  ] ; then 
			UPGRFTP="YES"
			print "\tUpgrade InterScan VirusWall for FTP\t ${DASH} [ ${BOLD}${UPGRFTP}${UNBOLD} ]"
			print "\tInstallation Path\t${BOLD}${FTPPATH}${UNBOLD}"
		fi

		if [ "$ISHTTP" = "Installed" ] ; then
			UPGRHTTP="YES"
			print "\tUpgrade InterScan VirusWall for HTTP\t ${DASH} [ ${BOLD}${UPGRHTTP}${UNBOLD} ]"
			print "\tInstallation Path\t${BOLD}${HTTPPATH}${UNBOLD}"
		fi

		if [ "$ISSMTP" = "Installed" ] ; then
			UPGRSMTP="YES"
			print "\tUpgrade InterScan VirusWall for E-Mail\t ${DASH} [ ${BOLD}${UPGRSMTP}${UNBOLD} ]"
			print "\tInstallation Path\t${BOLD}${SMTPPATH}${UNBOLD}"
		fi
	fi

	if [ "$ISTVCS" = "Installed"  ] ; then 
		UPGRTVCS="YES"
		print "\tUpgrade TVCS Agent for InterScan\t ${DASH} [ ${BOLD}${UPGRTVCS}${UNBOLD} ]"
		print "\tInstallation Path\t${BOLD}${TVCSPATH}${UNBOLD}"
	fi

	#print "\tInterScan VirusWall Package Language\t ${DASH} [ ${BOLD}${IS_LANG}${UNBOLD} ]"
	print
	{
	 print "\t1.\tStart Patch upgrade."
	 print "\t2.\tBack to Main Menu."
	} >&2
	print 
	print -n "		Select a number [   ]\b\b\b" ; read RESP

	case $RESP in
	1 ) StartPatchUpgrade ; Main ;;
	2 ) Main ;;
	* ) print "${BELL}\t\tPlease type a valid choice"
	esac
	done
}

function ChkISVWVersion
{

	if [ -s /etc/iscan/pkg/ISBASE ] ; then
	    Ch_Base_dir=`cat /etc/iscan/pkg/ISBASE`
	    Ch_Base_ver=`pkginfo -R $Ch_Base_dir -l | grep VERSION | cut -d' ' -f6`
#FOR 3.7    if [ $Ch_Base_ver = "3.5" ] ; then
	    if [[ $Ch_Base_ver = "3.5" || $Ch_Base_ver = "3.6" ]] ; then
		Upgrade="YES"
		PATCHUPGRADE="NO"
		Ch_Lang=`grep web_virinfo_url /etc/iscan/intscan.ini`
		if [ $Ch_Lang = "web_virinfo_url=http://www.trendmicro.co.jp/virusnews/database/" ] ; then
			export IS_LANG="JP"
		else
			export IS_LANG="EN"
		fi
	    elif [ $Ch_Base_ver = "3.7" ] ; then
		Upgrade="NO"
		PATCHUPGRADE="YES"
	    else
		Upgrade="NO"
		PATCHUPGRADE="NO"
	    fi
	else
	  Upgrade="NO"
	  PATCHUPGRADE="NO"
	fi

# license check for  patch upgrade
	if [ $PATCHUPGRADE = "YES" ] ; then

		if [ ! -s /etc/iscan/license ]
		then
			PATCHUPGRADE="NO"
			return
		fi
		if [ ! -s /etc/iscan/intscan.ini ]
		then
			PATCHUPGRADE="NO"
			return
		fi
		SERIAL_LIC=`awk -F"=" '/^Serial.*/ { print $2 }' < /etc/iscan/intscan.ini`
		echo $SERIAL_LIC | /etc/iscan/license > /dev/null
		if [ "$?" != "0" ] ; then
			PATCHUPGRADE="NO"
		fi

		if [ ! -r ./Changes ] ; then

			if [ ! $CHANGESFILELOC ] ; then
				PATCHUPGRADE="NO"
			else
				if [ ! -r $CHANGESFILELOC ] ; then
					PATCHUPGRADE="NO"
				fi
			fi
		fi
	fi

}

# this function is not used anymore, just keep it here as a placeholder
function UpgradeMain
{
	typeset loop=true

	clear
	ISINST=`basename $0`
	ChkConfig
	while [[ $loop = true ]] ; do
	loop=false
	Header
	print
	print
	print "\t1.\tInterScan Viruswall for CVP."
	print "\t2.\tInterScan VirusWall for FTP, SMTP, HTTP."
	print "\t3.\tInterScan VirusWall Upgrade from Version 3.5/3.6 to Version 3.7."
	print "\t4.\tExit." 
	print
	print -n "               Select an option[   ]\b\b\b" ; read RESP

	 case $RESP in
	 1 ) 
		INSTALLCVP="YES" ;FirstPageCVP ;; 
	 2 ) 
		INSTALLCVP="NO" ;FirstPage ;;
	 3 ) 
		 UpgradeStatus ;;
	 4 ) 	Exit ;; 
	 * )	print "${BELL}\t\tAn invalid choice was entered. Please try again." ; loop=true ;; 
	 esac
	done 
}

# NKO CHANGE 
function PatchUpgradeMain
{
	typeset loop=true

	clear
	ISINST=`basename $0`
	ChkConfig
	while [[ $loop = true ]] ; do
	loop=false
	Header
	print
	print
	print "\t1.\tInterScan VirusWall for FTP, SMTP, HTTP."
	print "\t2.\tInterScan VirusWall Patch Upgrade from Version 3.7."
	print "\t3.\tExit." 
	print
	print -n "               Select an option[   ]\b\b\b" ; read RESP

	 case $RESP in
	 1 ) 
		INSTALLCVP="NO" ;FirstPage ;;
	 2 ) 
		checkpath ; PatchUpgradeStatus ;;
	 3 ) 	Exit ;; 
	 * )	print "${BELL}\t\tAn invalid choice was entered. Please try again." ; loop=true ;; 
	 esac
	done 
}


function Main
{

    typeset loop=true

    clear
    ISINST=`basename $0`
    ChkConfig
    ChkISVWVersion
# NKO CHANGE
    rootgrp=`id |  awk ' { print $2 } ' |  cut  -d "(" -f2 | cut -d ")" -f1`
    if [ $PATCHUPGRADE = "YES" ] ; then
	PatchUpgradeMain
    elif [ $Upgrade = "NO" ] ; then
	    while [[ $loop = true ]] ; do
	     loop=false
	     Header
	     print
	     print
	     print "\t1.\tInterScan Viruswall for CVP."
	     print "\t2.\tInterScan VirusWall for FTP, SMTP, HTTP."
	     print "\t3.\tExit." 
	     print
	     print -n "               Select an option[   ]\b\b\b" ; read RESP

	      case $RESP in
	      1 ) 
	     	INSTALLCVP="YES" ;FirstPageCVP ;; 
	      2 ) 
	     	INSTALLCVP="NO" ;FirstPage ;;
	      3 ) 	Exit ;; 
	      * )	print "${BELL}\t\tAn invalid choice was entered. Please try again." ; loop=true ;; 
	      esac
	    done 
    else
	#UpgradeMain
	print "Please remove the old version V3.5 or V3.6 before proceeding."
	PressAnyKey
    fi
}
#=========================================================
# Printing removing message
#=========================================================
function Print_RM_Msg
{
    print "\tPlease remove or rename this existing id (iscan) and then re-install InterScan." | fmt -60

    exit 1
}

#=========================================================
# Checking UID/GID on the system
#=========================================================
function Check_UID {

   grep iscan /etc/passwd >/dev/null 2>&1

      if [ "$?" = "0" ] ; then
	 Use_Exist_ID "User"
         if [ "$ADDUID" = "YES" ] ; then
	   Print_RM_Msg
         fi
      fi
}
#=========================================================
# Checking UID/GID on the system
#=========================================================
function Account_Checking
{
    ## Checking group id
	grep iscan /etc/group >/dev/null 2>&1
	if [ "$?" = "0" ] ; then
	   Use_Exist_ID "Group"
	   if [ "$ADDGID" = "YES" ] ; then
	      Print_RM_Msg
	   fi
	   Check_UID
	else
	   Check_UID
	fi                  
}
function Account_Check
{
    ## Checking group id
    grep iscan /etc/group >/dev/null 2>&1
    if [ "$?" = "0" ] ; then
       print "Group ID (iscan) required by InterScan already exists on the system."
       print
       ADDGID="NO"
    else
       ADDGID="YES"
    fi
    grep iscan /etc/passwd >/dev/null 2>&1
    if [ "$?" = "0" ] ; then
       print "User ID (iscan) required by InterScan already exists on the system."
       print
       ADDUID="NO"
    else
       ADDUID="YES"
    fi
}
#=========================================================
# Add UID/GID (iscan/iscan) in UNIX system
#=========================================================
function Add_Iscan_user
{
    # check if gid/uid: iscan/iscan exist.
    Account_Check
    ## ADD group id
    if [ "$ADDGID" = "YES" ] ; then
	print  "\t Adding the new group: iscan in your UNIX system..."
	groupadd iscan > /dev/null 2>&1
	
	if [ "$?" != "0" ] ; then
	   print  "\t fail to create the new group 'iscan' in your system."
	   print  "\t please manually creat a new group 'iscan'  then install Interscan again."
	   exit 1
	fi
    fi       
    ## ADD user id
    if [ "$ADDUID" = "YES" ] ; then
       print  "\t Adding the new user: iscan in your UNIX system..."
       useradd -g iscan iscan >/dev/null 2>&1
       if [ "$?" != "0" ] ; then
	  print  "\t fail to create the new user 'iscan' in your system."
	  print  "\t please manually creat a new user 'iscan', then install Interscan again."
	  exit 1
       fi
    fi
}
#=========================================================
# Remove UID/GID after remove InterScan admin package
#=========================================================
function Remove_ID
{
    print -n "Do you want to remove $1 ID:iscan in your system[     ]\b\b\b\b\b" ; read RESP
    ChkResp $RESP "error"
    
    if [ "$1" = "group" ] ; then
	IDDEL="groupdel"
    elif [ "$1" = "user" ] ; then
	IDDEL="userdel"
    fi
    
    if [ "$RESP" = "YES" ] ; then
       print  "\t Deleting the $1 ID:iscan in your system..."
       $IDDEL iscan > /dev/null 2>&1
       
       if [ "$?" != "0" ] ; then
	  print  "\t fail to delete the $1 ID:iscan in your system."
	  print "\t please manually delete the ID from your system."
	  PressAnyKey
       fi
    elif [ "$RESP" = "error" ] ; then
	  print "\t Invalid input."
	  PressAnyKey
	  Remove_ID $1
    fi          
}  
#=========================================================
# Remove UID/GID (iscan/iscan) from UNIX system
#=========================================================
function Remove_Iscan_user
{
    #Remove GID
    Remove_ID "group"
    #Remove UID
    Remove_ID "user"
}

#=========================================================
# Changing the ownership for base programs.
#=========================================================
function chmodbase_root_to_iscan
{
    ### Action for base package
    base=`cat /etc/iscan/pkg/ISBASE`
    basepath=$base/IScan.BASE
    #basefile=`ls $basepath`
    #for i in $basefile
    #do
    #   chmod 555 $basepath/$i
    #   chown iscan $basepath/$i
    #   chgrp iscan $basepath/$i
    #done
    chmod 600 /etc/iscan/intscan.ini
    chown -R iscan $basepath 
    chgrp -R iscan $basepath

    chown -R iscan /etc/iscan
    chgrp -R iscan /etc/iscan

    chmod 4550  $basepath/prescan.cgi
    chown iscan $basepath/prescan.cgi
    chgrp iscan $basepath/prescan.cgi
    chmod 4555 $basepath/isdelvd
    chown root $basepath/isdelvd
    chgrp $rootgrp $basepath/isdelvd
    chmod 4555 $basepath/purgefile
    chown root $basepath/purgefile
    chgrp $rootgrp $basepath/purgefile
}
#=========================================================
# Changing the ownership for admin programs.
#=========================================================
function chmodadmin_root_to_iscan
{
    ### Action for admin package.
    admin=`cat /etc/iscan/pkg/ISADMIN`
    adminpath=$admin/IScan.adm
    #cgiprg=`ls $adminpath/cgi-bin`
    
    #changing owner and group for admindir
    #for i in $admindir
    #   do
    #     chown -R iscan $adminpath/$i
    #     chgrp -R iscan $adminpath/$i
    #   done                      
    # changing ower as root for cgiprg
    #for i in $cgiprg
    #do
    #  chmod 755 $adminpath/cgi-bin/$i
    #  chown iscan $adminpath/cgi-bin/$i
    #  chgrp iscan $adminpath/cgi-bin/$i
    #done
    if [ ! -d  $adminpath/conf/ssl.prm ] ; then 
       mkdir $adminpath/conf/ssl.prm
    fi
    if [ ! -d  $adminpath/conf/ssl.csr ] ; then 
       mkdir $adminpath/conf/ssl.csr
    fi
    chown -R iscan $admin 
    chgrp -R iscan $admin
    chmod 4550  $adminpath/cgi-bin/scannow.cgi
    chown iscan $adminpath/cgi-bin/scannow.cgi
    chgrp iscan $adminpath/cgi-bin/scannow.cgi
    chmod 4550  $adminpath/cgi-bin/start.cgi
    chown iscan $adminpath/cgi-bin/start.cgi
    chgrp iscan $adminpath/cgi-bin/start.cgi
    chmod 4550  $adminpath/cgi-bin/shutdown.cgi
    chown iscan $adminpath/cgi-bin/shutdown.cgi
    chgrp iscan $adminpath/cgi-bin/shutdown.cgi
    chmod 4550  $adminpath/cgi-bin/getptn_net.cgi
    chown iscan $adminpath/cgi-bin/getptn_net.cgi
    chgrp iscan $adminpath/cgi-bin/getptn_net.cgi

    chmod 4550  $adminpath/cgi-bin/scanning
    chown iscan $adminpath/cgi-bin/scanning
    chgrp iscan $adminpath/cgi-bin/scanning

    chmod 400 $adminpath/conf/ssl.key/server.key
    chown root $adminpath/conf/ssl.key/server.key
    chgrp $rootgrp $adminpath/conf/ssl.key/server.key

    # so user can turn on/off daemons thru web  #
    chmod 4550  $adminpath/cgi-bin/turnoff_on.cgi
    chown root  $adminpath/cgi-bin/turnoff_on.cgi
    chgrp iscan $adminpath/cgi-bin/turnoff_on.cgi
}

#=========================================================
# Changing the ownership for tvcs programs.
#=========================================================
function chmodtvcs_root_to_iscan
{
    tvcs=`cat /etc/iscan/pkg/ISTVCS`
    chown -R iscan $tvcs 
    chgrp -R iscan $tvcs

    chmod 4550  $tvcs/IScan.TVCS/SolarCommand
    chown iscan $tvcs/IScan.TVCS/SolarCommand
    chgrp iscan $tvcs/IScan.TVCS/SolarCommand
    
    chmod 4550  $tvcs/IScan.TVCS/tvcs_unint.sh
    chown iscan $tvcs/IScan.TVCS/tvcs_unint.sh
    chgrp iscan $tvcs/IScan.TVCS/tvcs_unint.sh

    chmod 4550  $tvcs/IScan.TVCS/prescan.cgi
    chown iscan $tvcs/IScan.TVCS/prescan.cgi
    chgrp iscan $tvcs/IScan.TVCS/prescan.cgi

    chmod 4550  /etc/iscan/vcagt
    chown iscan /etc/iscan/vcagt
    chgrp iscan /etc/iscan/vcagt
    chmod 4550 /etc/rc2.d/S99IStvcs
}
											 
#######        Main Program    ########


# NKO CHANGE
    if [ "$1" = "-i" ] ; then
        ASKYESNO="YES"
    fi


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
