#!/bin/sh
PATH=/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/ucb:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

PKG_VERSION="3.8"
DIS_TYPE="redhat"
DIS_LIB="libc"
DIS_LIB_VER="2.1"
INSTALLTYPE="Tar"
BASEFILES="isdelvd cleanscan intscan.ini config prescan.cgi srvscan vscan intscan.ini.orig license perfmon perfmonhttp arglist upgrade uplog iscanpsw gentrial libvsapi.so macr\$gen.600 macro.lst getconf purgefile isfunctions"
ADMINFILES="eoiscan.input daemonhup.sh start.cgi shutdown.cgi isswitch.cgi geteng libtmactupdate.so AuPatch aucfg.ini"
ADMINDIRS="bin cgi-bin conf icons images msg Java logs"
FTPFILES="iscanftps isftpd isftpd.trial"
HTTPFILES="iscanhttpproxys  ishttpd ishttpd.trial"
SMTPFILES="iscansmtps issmtpd issmtpd.trial"
TVCSFILES="vcagt solar.ini tvcs_unint.sh ip"
silent="no"

TVCS_CGI="Register SolarCommand tvcscfg.cgi tvcsinfo.cgi tvcsreg.cgi tvcsun_set.cgi tvcsunint.cgi"
TVCS_IMG="uninstall.gif register.gif"

ISBASE_ENV="/tmp/isbase.env"

case "$LANG" in
  "ja")
	export IS_LANG="JP" ;;
  "ja_JP")
	export IS_LANG="JP" ;;
  "ja_JP.eucJP")
	export IS_LANG="JP" ;;
  "ja_JP.ujis")
	export IS_LANG="JP" ;;
  *)
	export IS_LANG="EN" ;;
esac

# set DIS_TYPE to the correct LINUX distribution
function GuessLinuxPlatform
{
if [ -f /etc/SuSE-release ] ; then
    DIS_TYPE="SuSE"
    DIS_VERSION=`cat /etc/SuSE-release`
    DIS_LIB="shlibs"
    DIS_LIB_VER="2.1"
    RC_D="/etc"
else
    if [ -f /etc/redhat-release ] ; then
       DIS_TYPE="redhat"
       DIS_VERSION=`cat /etc/redhat-release`
       RC_D="/etc/rc.d"
    else
       if [ -f /etc/turbolinux-release ] ; then
           DIS_TYPE="turbolinux"
	   DIS_VERSION=`cat /etc/turbolinux-release`
           RC_D="/etc/rc.d"
       else
           DIS_TYPE=`ls /etc/*release`
	   DIS_VERSION='cat /etc/*release'
           RC_D="/etc/rc.d"
       fi
    fi
fi
}

# The following depends on OS.
SYSNAME=`uname -s`
echo "SYSNAME=$SYSNAME"
case ${SYSNAME} in
   "Linux")
	RC_D="/etc/rc.d"
	PS_ALL="ps ax"
	GuessLinuxPlatform
	;;
   "SunOS")
	RC_D="/etc/rc2.d"
	PS_ALL="ps -ef"
	;;
#   "HP-UX")
#   "OSF1")
#	RC_D="/sbin"
#	PS_ALL="ps -e"
#	;;
   *)
	echo "${SYSNAME} is not supported this release."
	exit 1
	;;
esac

RC_HEAD=$RC_D
case $DIS_TYPE in 
            turbolinux ) ;;
            SuSE       ) RC_HEAD=/etc/init.d;;
            redhat     ) ;;
            * ) printf "Installation doesn't support this platform\n";;
esac

INIT_D="$RC_D/init.d"
#RUN_D="/etc/rc.d/rc2.d"
RC_0D="$RC_HEAD/rc0.d"
RC_1D="$RC_HEAD/rc1.d"
RC_2D="$RC_HEAD/rc2.d"
RC_3D="$RC_HEAD/rc3.d"
RC_4D="$RC_HEAD/rc4.d"
RC_5D="$RC_HEAD/rc5.d"
RC_6D="$RC_HEAD/rc6.d"
DEF_RC_STOP_DIR="$RC_0D $RC_1D $RC_2D $RC_6D"
if [ "$DIS_TYPE" = "SuSE" ] ; then
	DEF_RC_STOP_DIR="$RC_0D $RC_1D $RC_2D $RC_3D $RC_6D"
fi

# each daemon start/stop script
CALDERA="no"
if [ -f $INIT_D/mta ] ; then
	CALDERA="yes"
	ISCANSMTP_RC="$INIT_D/mta"  # OpenLinux
else
	ISCANSMTP_RC="$INIT_D/sendmail"
fi
SMTP_ORIG_RC="/etc/iscan/sendmail.rc"
ISCANSMTPD_RC="$INIT_D/iscansmtps"
ISCANFTPD_RC="$INIT_D/iscanftps"
ISCANHTTPD_RC="$INIT_D/iscanhttpproxys"
ISCANCVP_RC="$INIT_D/iscancvps"
ADMHTTP_RC="$INIT_D/iscanhttpds"
TVCS_RC="$INIT_D/iscantvcsagts"

ISCANSMTPDI_RC="/etc/iscan/iscansmtps"
ISCANFTPDI_RC="/etc/iscan/iscanftps"
ISCANHTTPDI_RC="/etc/iscan/iscanhttpproxys"
TVCSI_RC="/etc/iscan/iscantvcsagts"

# for Linux doesn't have gettxt command
#LOCAL_GETTXT=/usr/local/bin/gettxt
#LOCAL_GETTXT=/etc/iscan/gettxt
TRIAL_EXT="evl"

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

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

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

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

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

# CZ, add for system upgrade 
UPGRFTP="NO"
UPGRHTTP="NO"
UPGRADMIN="NO"
UPGRSMTP="NO"
UPGRBASE="NO"
UPGRTVCS="NO"
UPGRCVP="NO"

Upgrade="NO"
backpath=""

VIRUSLOGPATH="/opt/trend/virus"
ISVWROOT="/opt/trend"
PLUGINPATH="/opt/trend/Plug-Ins"
PLUGINSPATH="/etc/iscan_plugins"
PLUGEMRESTORE="/opt/trend/Plug-Ins/EM/restore.sh"
FTPPATH="/opt/trend/ISFTP"
BASEPATH="/opt/trend/ISBASE"
SMTPPATH="/opt/trend/ISSMTP"
HTTPPATH="/opt/trend/ISHTTP"
ADMINPATH="/opt/trend/ISADMIN"
TVCSPATH="/opt/trend/ISTVCS"
CVPPATH="/opt/trend/ISCVP"
UPGRADE="NO"
OLDBASE=""
OLDHTTP=""
FTPPATHD="/opt/trend/ISFTP/IScan.FTP"
BASEPATHD="/opt/trend/ISBASE/IScan.BASE"
SMTPPATHD="/opt/trend/ISSMTP/IScan.SMTP"
HTTPPATHD="/opt/trend/ISHTTP/IScan.HTTP"
ADMINPATHD="/opt/trend/ISADMIN/IScan.adm"
TVCSPATHD="/opt/trend/ISTVCS/IScan.TVCS"

RESP=""
ISPATH=""
INETD=/etc/inetd.conf

LICENSE="NOTOK"
Installed="NO"

# Administration parameter
NOTIFY_SERVER="localhost"
NOTIFY_PORT="25"


#NKO CHANGE
PATCHUPGRADE="NO"
ASKYESNO="NO"
RESTARTFLG="YES"
STRINGSCMDFOUND="NO"

ISCAN_TMP="/tmp/iscan_old"

function ShowLogFilePath
{
	echo $smtplogfile
	echo $httplogfile
	echo $ftplogfile
	echo $adminlogfile
	echo $cvplogfile
	echo $updatelogfile
	echo $notifylogfile
	echo $viruslogfile
}

function MakeIscanOldTmpFile
{
  if [ ! -d $ISCAN_TMP ] ; then
	 mkdir -p $ISCAN_TMP >/dev/null 2>&1
  fi
}

function BackupExistingIntscanIniFile
{
   MakeIscanOldTmpFile 
   cp /etc/iscan/intscan.ini  $ISCAN_TMP/INTSCAN.INI >/dev/null 2>&1
}

#
# Backup a log file to the tmp folder
# $1 the file name prefix of the given log file
# $2 the folder name of under the tmp[ folde3r
function BackupOneLogFile
{
    if [ $1 != "" ] ; then
      if [ ! -d $ISCAN_TMP/$2 ]; then
           mkdir -p  $ISCAN_TMP/$2
      fi
      cp $1* $ISCAN_TMP/$2 >/dev/null 2>&1
   fi

}


#
# Recover a log file to the path
# $1 target path
# $2 tmp folder name for the recovering files
# $3 the full path prefix of the targetpath
function RecoverOneLogFile
{
   if [ $1 != "" ] ; then
      if [ ! -d $1 ] ; then
          mkdir -p $1
      fi    
      
      if [  -d $ISCAN_TMP/$2 ] ; then
         cp $ISCAN_TMP/$2/*  $1 >/dev/null 2>&1
  	chown iscan $3* >/dev/null 2>&1
     	chgrp iscan $3* >/dev/null 2>&1
     fi
      
    fi

}

#
# Recover a general file to the path
# $1 target full path
# $2 FILE name for the recovering files
function RecoverOneGeneralFile
{
   if [ $1 != "" ] && [ -f /tmp/iscan_old/$2 ] ; then
	pathName=`/etc/iscan/sedini -path $1`
   	if [ $pathName != "" ] ; then
       		if [ ! -d $pathName ] ; then
            		mkdir $pathName
       		fi
       	fi
  	cp  /tmp/iscan_old/$2 $1
  	chown iscan $1 >/dev/null 2>&1
     	chgrp iscan $1 >/dev/null 2>&1
    fi
}
   
function UpgradeBackup
{
		   # SUSTAIN_RL
		   # Add the disclaimer.txt and direction.ini to the tmp folder
		   #
		   if [ -f /etc/iscan/disclaimer.txt ] ; then
		  	 cp /etc/iscan/disclaimer.txt /tmp/iscan_old
		   fi
		   
		   if [ -f /etc/iscan/direction.ini ] ; then
		  	 cp /etc/iscan/direction.ini /tmp/iscan_old
		   fi
		   #
		   # END OF SUSTAIN
		   #
		   
		   #
		   # Now let us back the proxy_acl files
		   #
		   # SMTP proxy_acl file named as SMTP_PROXY_ACL
		   # HTTP proxy_acl file named as HTTP_PROXY_ACL
		   # FTP proxy_acl file named  as FTP_PROXY_ACL
   		   # SMTP proxy_acl file named as SMTP_PROXY_ACL
   		   # The function will copy all the file to the tmp folder
   		   #
   		   
  		   httpProxyAclFile=`./sedini -r /etc/iscan/intscan.ini http proxy_acl`
    
  		   if  [ "$httpProxyAclFile" != "" ] && [ -f "$httpProxyAclFile" ] ; then
 		   	cp $httpProxyAclFile /tmp/iscan_old/HTTP_PROXY_ACL
  		   fi
 
  		   smtpProxyAclFile=`./sedini -r /etc/iscan/intscan.ini smtp proxy_acl`
  		   
  		   if  [ "$smtpProxyAclFile" != ""  ] && [ -f "$smtpProxyAclFile" ] ; then
 		   	cp $smtpProxyAclFile /tmp/iscan_old/SMTP_PROXY_ACL
  		   fi
 
  		   ftpProxyAclFile=`./sedini -r /etc/iscan/intscan.ini ftp proxy_acl`
  		   
  		   if  [ "$ftpProxyAclFile" != ""  ] && [ -f "$ftpProxyAclFile" ] ; then
 		   	cp $ftpProxyAclFile /tmp/iscan_old/FTP_PROXY_ACL
  		   fi
 
 		   localDomainFile=`./sedini -r /etc/iscan/intscan.ini smtp local_domain`
 		   
  		   if  [ "$localDomainFile" != "" ] && [ -f "$localDomainFile" ] ; then
		   	cp $localDomainFile /tmp/iscan_old/LOCAL_DOMAIN_FILE
  		   fi


                   accept_recpt_file=`./sedini -r /etc/iscan/intscan.ini smtp accept_rcpt`
  		   
  		   if  [ "$accept_recpt_file" != "" ] && [ -f "$localDomainFile" ] ; then
 		   	cp $accept_recpt_file /tmp/iscan_old/ACCEPT_RCPT_FILE
  		   fi

                   mkdir -p /tmp/iscan_old/PATTERNFILES >/dev/null 2>&1
                   cp /etc/iscan/lpt$vpn*  /tmp/iscan_old/PATTERNFILES   >/dev/null 2>&1   
#
#                  BACK UP THE VIRUS FILES
#
                   httpVirusFiles=`./sedini -r /etc/iscan/intscan.ini http movedir`
  		   if  [ "$httpVirusFiles" != "" ] && [ -d "$httpVirusFiles" ]; then
                       mkdir -p "$ISCAN_TMP/HTTPVIRUSFILE"           > /dev/null 2>&1
		   	   cp $httpVirusFiles/* "$ISCAN_TMP/HTTPVIRUSFILE"   > /dev/null 2>&1
  		   fi

                   ftpVirusFiles=`./sedini -r /etc/iscan/intscan.ini ftp movedir`
  		   if  [ "$ftpVirusFiles" != "" ] && [ -d "$ftpVirusFiles" ]; then
                       mkdir -p "$ISCAN_TMP/FTPVIRUSFILE"           > /dev/null 2>&1
		   	   cp $ftpVirusFiles/* "$ISCAN_TMP/FTPVIRUSFILE"   > /dev/null 2>&1
  		   fi

                   smtpVirusFiles=`./sedini -r /etc/iscan/intscan.ini smtp movedir`
  		   if  [ "$smtpVirusFiles" != "" ] && [ -d "$smtpVirusFiles" ]; then
                       mkdir -p "$ISCAN_TMP/SMTPVIRUSFILE"           > /dev/null 2>&1
		   	   cp $smtpVirusFiles/* "$ISCAN_TMP/SMTPVIRUSFILE"   > /dev/null 2>&1
  		   fi
}
#
# The function read the log file information from the intscan.ini file and copy them to the tmp
# iscan folder. 
#

function Upgrade_back_log
{
   # get all logfile location
   smtplogfile=`./sedini -r /etc/iscan/intscan.ini smtp logfile`
   httplogfile=`./sedini -r /etc/iscan/intscan.ini http logfile`
   ftplogfile=`./sedini -r /etc/iscan/intscan.ini ftp logfile`
   adminlogfile=`./sedini -r /etc/iscan/intscan.ini admin logfile`
   cvplogfile=`./sedini -r /etc/iscan/intscan.ini iscvp logfile`
   updatelogfile=`./sedini -r /etc/iscan/intscan.ini Pattern-Update logfile`
   notifylogfile=`./sedini -r /etc/iscan/intscan.ini notification deliverlogfile`
   viruslogfile=`./sedini -r /etc/iscan/intscan.ini Scan-configuration virus_log`
   
   
   # Now copy all the log files to the TMP folders
   # SUSTAIN _RL
   BackupOneLogFile $smtplogfile 	SMTPLOGFILE
   BackupOneLogFile $httplogfile 	HTTPLOGFILE
   BackupOneLogFile $ftplogfile  	FTPLOGFILE
   BackupOneLogFile $adminlogfile 	ADMINLOGFILE
   BackupOneLogFile $cvplogfile 	CVPLOGFILE
   BackupOneLogFile $updatelogfile 	UPDATELOGFILE
   BackupOneLogFile $notifylogfile 	NOTIFYLOGFILE
   BackupOneLogFile $viruslogfile 	VIRUSLOGFILE
}

#
# Function
# RecoverTheLogFileBack
#

function RecoverTheLogFileBack
{
   # get all logfile location
   smtplogfile=`./sedini -r /etc/iscan/intscan.ini smtp logfile`
   httplogfile=`./sedini -r /etc/iscan/intscan.ini http logfile`
   ftplogfile=`./sedini -r /etc/iscan/intscan.ini ftp logfile`
   adminlogfile=`./sedini -r /etc/iscan/intscan.ini admin logfile`
   cvplogfile=`./sedini -r /etc/iscan/intscan.ini iscvp logfile`
   updatelogfile=`./sedini -r /etc/iscan/intscan.ini Pattern-Update logfile`
   notifylogfile=`./sedini -r /etc/iscan/intscan.ini notification deliverlogfile`
   viruslogfile=`./sedini -r /etc/iscan/intscan.ini Scan-configuration virus_log`

   thispath=`./sedini -path $smtplogfile`
   RecoverOneLogFile $thispath SMTPLOGFILE $smtplogfile
   

   thispath=`./sedini -path $httplogfile`
   RecoverOneLogFile $thispath HTTPLOGFILE $httplogfile
   

   thispath=`./sedini -path $ftplogfile`
   RecoverOneLogFile $thispath FTPLOGFILE $ftplogfile
   

   thispath=`./sedini -path $adminlogfile`
   RecoverOneLogFile $thispath ADMINLOGFILE $adminlogfile
   

   thispath=`./sedini -path $cvplogfile`
   RecoverOneLogFile $thispath CVPLOGFILE $cvplogfile
   

   thispath=`./sedini -path $updatelogfile`
   RecoverOneLogFile $thispath UPDATELOGFILE updatelogfile
   

   thispath=`./sedini -path $notifylogfile`
   RecoverOneLogFile $thispath NOTIFYLOGFILE $notifylogfile
   

   thispath=`./sedini -path $viruslogfile`
   RecoverOneLogFile $thispath VIRUSLOGFILE $viruslogfile
   
   
}

function RestoreGeneralConfigurationFiles
{

  
  RecoverOneGeneralFile /etc/iscan/direction.ini  direction.ini
  RecoverOneGeneralFile /etc/iscan/disclaimer.txt disclaimer.txt
 
 
  ProxyAclFile=`/etc/iscan/sedini -r /etc/iscan/intscan.ini http proxy_acl`
  RecoverOneGeneralFile $ProxyAclFile HTTP_PROXY_ACL

  ProxyAclFile=`/etc/iscan/sedini -r /etc/iscan/intscan.ini smtp proxy_acl`
  RecoverOneGeneralFile $ProxyAclFile SMTP_PROXY_ACL

  ProxyAclFile=`/etc/iscan/sedini -r /etc/iscan/intscan.ini ftp proxy_acl`
  RecoverOneGeneralFile $ProxyAclFile FTP_PROXY_ACL

  localDomainFile=`/etc/iscan/sedini -r /etc/iscan/intscan.ini smtp local_domain`
  RecoverOneGeneralFile $localDomainFile LOCAL_DOMAIN_FILE

  
  accept_recpt_file=`/etc/iscan/sedini -r /etc/iscan/intscan.ini smtp accept_rcpt`
  RecoverOneGeneralFile $accept_recpt_file ACCEPT_RCPT_FILE

  cp  /tmp/iscan_old/PATTERNFILES/lpt$vpn* /etc/iscan/   >/dev/null 2>&1   

#
#                  RESTORE VIRUS FILES
#
                   httpVirusFiles=`/etc/iscan/sedini -r /etc/iscan/intscan.ini http movedir`
                   if [ -d "$ISCAN_TMP/HTTPVIRUSFILE" ]; then
                        if [ ! -d $httpVirusFiles ]; then
                               mkdir -p "$httpVirusFiles" >/dev/null 2>&1   
                        fi
 		   	    cp  $ISCAN_TMP/HTTPVIRUSFILE/*   $httpVirusFiles  >/dev/null 2>&1  
                   fi
                   
                   ftpVirusFiles=`/etc/iscan/sedini -r /etc/iscan/intscan.ini ftp movedir`
                   if [ -d "$ISCAN_TMP/FTPVIRUSFILE" ]; then
                        if [ ! -d $ftpVirusFiles ]; then
                               mkdir -p "$ftpVirusFiles"  >/dev/null 2>&1  
                        fi
 		   	    cp  $ISCAN_TMP/FTPVIRUSFILE/*   $ftpVirusFiles  >/dev/null 2>&1  
                   fi
                     
                   smtpVirusFiles=`/etc/iscan/sedini -r /etc/iscan/intscan.ini smtp movedir`
                   if [ -d "$ISCAN_TMP/SMTPVIRUSFILE" ]; then
                        if [ ! -d $smtpVirusFiles ]; then
                               mkdir -p "$smtpVirusFiles"  >/dev/null 2>&1  
                        fi
 		   	    cp  $ISCAN_TMP/SMTPVIRUSFILE/*   $smtpVirusFiles  >/dev/null 2>&1  
                   fi
}

function Merge_intscanIniAndOthers
{
  #upgrade intscan.ini
  if [ -f $ISCAN_TMP/INTSCAN.INI ] ; then
      echo "Merging intscan.ini file"
      cp /etc/iscan/intscan.ini /etc/iscan/intscan.ini.orig
	  #SUSTAIN_RL
	  #
	  # Some entry must stick with 3.8 definitions while others could be migrated from older version:q
	  #
	  
	  #
	  # Migrate the older values while keep the version information
	  # 
	  result=`/etc/iscan/sedini -addentry /etc/iscan/intscan.ini $ISCAN_TMP/INTSCAN.INI`
	  result=`/etc/iscan/sedini /etc/iscan/intscan.ini $ISCAN_TMP/INTSCAN.INI ok failed Registration Version "3.8 for linux"`

       if [ "$result" != "ok" ] ; then
         cp /etc/iscan/intscan.ini.orig /etc/iscan/intscan.ini
         echo "Upgrade intscan.ini failed."
      else
         rm -f /tmp/iscan_old/intscan.ini
         chgrp iscan /etc/iscan/intscan.ini
         chown iscan /etc/iscan/intscan.ini
      fi

      
       #
	  # Keey the Pattern Update path to 3.8 (case 7883)
	  #
		result=`/etc/iscan/sedini /etc/iscan/intscan.ini /etc/iscan/intscan.ini ok failed Registration download_path  "/etc/iscan/actupdate "`		  
	    if [ "$IS_LANG" = "EN" ] ; then                                                                              
		  result=`/etc/iscan/sedini /etc/iscan/intscan.ini /etc/iscan/intscan.ini ok failed Registration hostname  "http://isux-t.activeupdate.trendmicro.com/activeupdate"`		 
		fi

		if [ "$IS_LANG" = "JP" ] ; then
		  result=`/etc/iscan/sedini /etc/iscan/intscan.ini /etc/iscan/intscan.ini ok failed Registration hostname  "http://isux-t.activeupdate.trendmicro.com/activeupdate/japan"`		 
		fi

       if [ "$result" != "ok" ] ; then
         cp /etc/iscan/intscan.ini.orig /etc/iscan/intscan.ini
         echo "Upgrade intscan.ini failed, please manually merge /tmp/iscan_dir/intscan.ini to /etc/iscan/intscan.ini."
       else
          rm -f /tmp/iscan_old/intscan.ini
       fi

  else
     echo "Unable to find old intscan.ini in /tmp/iscan_old, upgrade intscan.ini stop"
  fi
 
}

function UpgradeNew
{
  #Only upgrade intscan.ini, all binarary will be remove and reinstall
  if [ -f ./sedini ] ; then
    cp sedini /etc/iscan
  fi
  if [ -f /etc/iscan/pkg/ISVWROOT ] ; then
     pkgroot=`cat /etc/iscan/pkg/ISVWROOT`
     if [ ! -d $pkgroot ] ; then
         echo "$pkgroot is not a valid directory,upgrade exit."
         return -1
     fi
  else
     echo "Unable to find file /etc/iscan/pkg/ISVWROOT, upgrade exit."
     return -1
  fi
  #back up log file
   #
   # SUSTAIN RL
   #  Add the special code to backup the installed files that
   # need to upgrade next time
   #
   # SUSTAIN RL
   # Copy all the log files to /tmp/iscan_old
   #   
   MakeIscanOldTmpFile
   BackupExistingIntscanIniFile
   Upgrade_back_log
   UpgradeBackup 

  ishttpup="no"
  issmtpup="no"
  isftpup="no"
  iscvpup="no"
  isadminup="no"
  istvcsup="no"
  #check how many package installed
  #and remove these package
  echo "Start Remove Package ..."
  silent="yes"
  if [ -f /etc/iscan/pkg/ISFTP ] ; then
     isftpup="yes"
     ISFTP="Installed" 
     StartRemove "FTP"
  fi
  if [ -f /etc/iscan/pkg/ISHTTP ] ; then
     ishttpup="yes"
     ISHTTP="Installed" 
     StartRemove "HTTP" 
  fi
  if [ -f /etc/iscan/pkg/ISSMTP ] ; then
     issmtpup="yes"
     ISSMTP="Installed" 
     StartRemove "SMTP"
  fi
  if [ -f /etc/iscan/pkg/ISCVP ] ; then
     iscvpup="yes"
     ISCVP="Installed" 
     StartRemove "CVP" 
  fi
  if [ -f /etc/iscan/pkg/ISADMIN ] ; then
     isadminup="yes"
     ISADMIN="Installed" 
     StartRemove "ADMIN"  
  fi
  if [ -f /etc/iscan/pkg/ISTVCS ] ; then
     istvcsup="yes"
     ISTVCS="Installed" 
     StartRemove "TVCS"  
  fi
  if [ -f /etc/iscan/pkg/ISBASE ] ; then
     isbaseup="yes"
     ISBASE="Installed" 
     StartRemove "BASE"  
  fi
  
  #install these package
  #base package
  silent="no"
  checkpath 
  if [ "$isbaseup" = "yes" ] ; then
      ISBASE="None"
      INSTBASE="YES"
  fi
  #admin package
  if [ "$isadminup" = "yes" ] ; then
      ISADMIN="None"
      INSTADMIN="YES"
  fi
  #SMTP package
  if [ "$issmtpup" = "yes" ] ; then
      ISSMTP="None"
      INSTSMTP="YES"
  fi
  #HTTP package
  if [ "$ishttpup" = "yes" ] ; then
      ISHTTP="None"
      INSTHTTP="YES"
  fi
  #FTP package
  if [ "$isftpup" = "yes" ] ; then
      ISFTP="None"
      INSTFTP="YES"
  fi
  #CVP package
  if [ "$iscvpup" = "yes" ] ; then
      ISCVP="None"
      INSTCVP="YES"
  fi
  #TVCS package
  if [ "$istvcsup" = "yes" ] ; then
      ISTVCS="None"
      INSTTVCS="YES"
  fi
  
  StartInstall
  Merge_intscanIniAndOthers
  RecoverTheLogFileBack
  RestoreGeneralConfigurationFiles 
  Exit
}


debug ()
{
	printf "this is debug $1 message from matt."
}

PressAnyKey ()
{
	printf "\n"
	printf "Press Enter to continue ..... " ; read
}

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  	
}

ChkConfig ()
{
	CheckSW ISBASE 
	CheckSW ISFTP 
	CheckSW ISADMIN 
	CheckSW ISHTTP
	CheckSW ISSMTP
	CheckSW ISTVCS
	CheckSW ISCVP
}

Header ()
{
	tput clear
	printf "\n"
	printf "\t\t\tInterScan VirusWall $PKG_VERSION\n"
	printf "\n"
	printf "\t\t\t    Setup Script\n"
	printf "\n"
	printf " ---------------------------------------------------------------------\n"
	printf "\n"
}

ChkPath ()
{
	firstchar=""

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

	   if [ "$firstchar" != "/" ] ; then
		printf "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.
checkpath ()
{
	if [ -s /etc/iscan/pkg/ISVWROOT ] ; then
	    ISPATH=`cat /etc/iscan/pkg/ISVWROOT`
	    printf "\tInterScan is installed in ${ISPATH} "
            PressAnyKey
	else 
	    printf "\tBy default,InterScan Installs in ${ISVWROOT} \n"
            printf "\n"
	    printf "\tChoose new path or hit ENTER to use default "
            printf "\n"
	    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.
#
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

	sed "s/^#$__line=.*/$__param=$__value/g" < /etc/iscan/intscan.ini > /tmp/upgr.ini.$$
	cat /tmp/upgr.ini.$$ > /etc/iscan/intscan.ini
	rm -f /tmp/upgr.ini.$$ 

	return 0
}

ChkResp ()
{
	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
}

## Setup RC environment
SetupRCEnv()
{

	if [ ! -f $RC_SRC ] ; then
		return 1
	fi

	# Save orignal if set $SAVE_RC
	if [ $SAVE_RC"x" != "x" ] ; then
	    if [ ! -e $SAVE_RC ] ; then
		/bin/cp -p $INIT_RC	$SAVE_RC
	    fi
	fi

       	/bin/cp -p $RC_SRC	${INIT_RC}
      	chmod 4750	${INIT_RC}
	chown root	${INIT_RC}
	chgrp iscan	${INIT_RC}

	# set start rc script
	for dir in $RC_START_DIR ; do
	    if [ ! -e $dir/$START_RC ] ; then
		ln -s $INIT_RC $dir/$START_RC
	    fi
	done

	# set stop rc script
	for dir in $RC_STOP_DIR ; do
	    if [ ! -e $dir/$STOP_RC ] ; then
		ln -s $INIT_RC $dir/$STOP_RC
	    fi
	done

	return 0
}

RemoveRCEnv()
{

	# operation INIT_RC 
	if [ $SAVE_RC"x" != "x" ] ; then
		/bin/cp -p $SAVE_RC	$INIT_RC
	else
	    if [ -f $INIT_RC ] ; then
		/bin/rm -f $INIT_RC
	    fi
	fi

	# remove start rc script
	for dir in $RC_START_DIR ; do
	    # if [ -e $dir/$START_RC ] ; then
		/bin/rm -f $dir/$START_RC
	    # fi
	done

	# remove stop rc script
	for dir in $RC_STOP_DIR ; do
	    # if [ -e $dir/$STOP_RC ] ; then
		/bin/rm -f $dir/$STOP_RC
	    # fi
	done

	return 0
}

Modify ()
{

	printf "	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
}

FailMsg ()
{
	echo "${BOLD}"
	printf "\t\tInterScan $1 has been installed but not properly setup in your system, please ask your support channel \n"
	echo "${UNBOLD}"
}

StartInstall ()
{
    if [ "$ISBASE" != "Installed" ] && [ "$INSTBASE" != "YES" ] ; then
	echo "${BOLD}"
	printf "\t\tYou have to install InterScan Virus Base system.\n"
	echo "${UNBOLD}"
	PressAnyKey
	return 
    fi
    if [ "$INSTBASE" = "YES" ] && [ "$ISBASE" = "Installed" ] ; then
	printf "\t\tI${BOLD}Scan BASE has been installed in your system${UNBOLD}\n"
	PressAnyKey
	INSTBASE="NO"
    fi
    if [ "$INSTADMIN" = "YES" ] && [ "$ISADMIN" = "Installed" ] ; then
	printf "\t\t${BOLD}InterScan ADMIN has been installed in your system${UNBOLD}\n"
	PressAnyKey
	INSTADMIN="NO"
    fi

    # if install CVP will not do the following stuff.
    if [ $INSTALLCVP != "YES" ] ; then
	##### Install ISBASE #############################################
	if [ "$INSTBASE" = "YES" ] ; then
	    if [ -d /etc/iscan ] ; then
		if [ -s /etc/iscan/pkg/BASE ] ; then
		    OLDBASE=`cat /etc/iscan/pkg/ISBASE`
		fi
		if [ -d "$OLDBASE" ] ; then
		    echo "${BOLD}"
		    printf "\t\tFound older $OLDBASE installed.\n"
		    echo "${UNBOLD}"
		fi
		printf "\n"
		printf "                Do you want to upgrade to InterScanVirusWall $PKG_VERSION ( yes ) [     ]\b\b\b\b\b" ; read RESP
		ChkResp $RESP "YES"
		if [ "$RESP" = "NO" ] ; then
		    return
		fi
		UPGRADE="YES"
		printf "                Please remove the old InterScan first"
		PressAnyKey
		mkdir /tmp/iscan_dir
		/bin/cp /etc/iscan/intscan.ini /tmp/iscan_dir
		/bin/cp /etc/iscan/iscan.log.* /tmp/iscan_dir
		rm -rf /etc/iscan
	    fi

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

	    Header

	    # add on Sep 29th, 1999.
	    if [ -d /tmp/pkgbase ] ; then
		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

	    if [ "$INSTALLTYPE" = "Tar" ] ; then
		BaseInstallUsingTar
	    else
		pkgadd -d /tmp/pkgbase -R "$BASEPATH" ISBASE
		if [ $? -ne 0 ] ; then
		    Installed="NO"
		else
		    Installed="YES"
		fi
	    fi
	    if [ "$Installed" = "NO" ] ; 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 -p $VIRUSLOGPATH
		    chgrp iscan $VIRUSLOGPATH
		    chmod 775 $VIRUSLOGPATH
		    #chown iscan $VIRUSLOGPATH
		fi
		ln -s $VIRUSLOGPATH /etc/iscan/virus

		if [ ! -d $PLUGINPATH ] ; then
		    mkdir -p $PLUGINPATH
		fi
		if [ ! -d $PLUGINSPATH ] ; then
		    mkdir -p $PLUGINSPATH
		fi
	    # SUSTAIN_RL
	    # Some parameters will be configured according to the language options
	    # 7583
	    #
		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.$$

			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("web_virinfo_url=http://www.antivirus.com/vinfo/\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("web_virdata_url=http://www.antivirus.com/vinfo/virusencyclo/default5.asp?VName=VIRUS_NAME\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Registration]$/ { print $0; printf("hostname=http://isux-t.activeupdate.trendmicro.com/activeupdate\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$
		fi

		if [ "$IS_LANG" = "JP" ] ; then
			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("jp_func=yes\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("web_virinfo_url=http://www.trendmicro.co.jp/virusnews/database/\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("web_virdata_url=http://inet.trendmicro.co.jp/virusinfo/default3.asp?VName=VIRUS_NAME\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Registration]$/ { print $0; printf("hostname=http://isux-t.activeupdate.trendmicro.com/activeupdate/japan\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$
		fi
	    
	    fi


# 7661
# RL notes: Now it is time to assign all the files with iscan users. Some of the file 
# should be asigned with root user mode. After running the following statement(s) the 
# base path user account should be well configured
# 
	chmodbase_root_to_iscan
#
# end of case 7661
#

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

	    rm -f $ISBASE_ENV


	    PressAnyKey
	    rm -rf /tmp/pkgbase
	    INSTBASE="NO"
	fi

	##### Install ISADMIN #############################################
	InstallADMOnly



	 # change the ftp server location for turbolinux #
	    
	    if [ $DIS_TYPE = "turbolinux" ] ; then
		vim -e /etc/iscan/intscan.ini << __EOF__ > /dev/null
%s/in.ftpd/in.proftpd
.
wq
__EOF__
       	    fi	
	

	# songmei 3/8/2000 mergerv3.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 [ "$Upgrade" = "YES" ] ; then
		LICENSE="OK"
            else
	       if [ ! -s /etc/iscan/license ] ; then
		   printf " Can not find your license check program"
		   PressAnyKey
		   return
	       fi
	       Header
	       printf "\tPlease input your serial number for InterScan "
	       printf "\n"
	       printf "\tOr hit ENTER to install a 30-day trial version:"
	       echo -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
	       echo -n ${UNBOLD}
	    fi
	fi

	####		FINISH LICENSE CHECKING
	#songmei merger code end 

	##### Install ISFTP #############################################
	if [ "$INSTFTP" = "YES" ] ; then
	    if [ "$ISFTPTRIAL" = "1" ] ; then
		Header
		echo ${BOLD}
		printf "\tYou have installed TRIAL VERSION in the system.\n"
		echo ${UNBOLD}
		printf "\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 "Removing the TRIAL VERSION."
		    # pkgrm -R `cat /etc/iscan/pkg/ISFTP` ISFTP
		    StartRemove "FTP" 
		    FTPPKG="isftp.tz"
		else
		    echo -n ${UNBOLD}
		    return
		fi
		ISFTPTRIAL=0
	    fi
	    # If installed, current system remove first.
	    #    (fix lost sendmail.rc)   10/31/2000
	    if [ "$ISFTP" = "Installed" ] ; then
		printf "\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 "Removing the current FTP system."
		    StartRemove "FTP" 
		else
		    echo -n ${UNBOLD}
		    return
		fi
	    fi
	    Header
	    if [ "$LICENSE" != "OK" ] ; then
		printf "\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
		    echo -n ${UNBOLD}
		    return
		fi
	    fi
	    echo -n ${UNBOLD}

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

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

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

	    if [ "$INSTALLTYPE" = "Tar" ] ; then
		FTPInstallUsingTar
	    else
		pkgadd -d /tmp/pkgftp -R "$FTPPATH" ISFTP
		if [ $? -ne 0 ] ; then
		    Installed="NO"
		else
		    Installed="YES"
		fi
	    fi
	    if [ "$Installed" = "NO" ] ; then 
		echo $ERROR_LINE >> /usr/tmp/iscan_install_log
		rm -rf $FTPPATH
	    fi

	    PressAnyKey
	    rm -rf /tmp/pkgftp
	    INSTFTP="NO"
	fi

	##### Install ISHTTP #############################################
	if [ "$INSTHTTP" = "YES" ] ; then
	    if [ "$ISHTTPTRIAL" = "1" ] ; then
		Header
		echo ${BOLD}
		printf  "\tYou have installed TRIAL VERSION in the system.\n"
		echo ${UNBOLD}
		printf "\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 "Removing the TRIAL VERSION."
		    # pkgrm -R `cat /etc/iscan/pkg/ISHTTP` ISHTTP
		    StartRemove "HTTP" 
		    HTTPPKG="ishttp.tz"
		else
		    echo -n ${UNBOLD}
		    return
		fi
		ISHTTPTRIAL=0
	    fi
	    # If installed, current system remove first.
	    #    (fix lost sendmail.rc)   10/31/2000
	    if [ "$ISHTTP" = "Installed" ] ; then
		printf "\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 "Removing the current HTTP system."
		    StartRemove "HTTP" 
		else
		    echo -n ${UNBOLD}
		    return
		fi
	    fi
	    Header
	    if [ "$LICENSE" != "OK" ] ; then
		printf "\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"
		else
		    echo -n ${UNBOLD}
		    return
		fi
	    fi
	    echo -n ${UNBOLD}
	    if [ ! -s ./$HTTPPKG ] ; then
		printf "\t\tCan not find InterScan HTTP ( $HTTPPKG ) in current directory.\n"
		PressAnyKey
		return
	    fi
	    # add on Sep 29th, 1999.
	    if [ -d /tmp/pkghttp ] ; then
		rm -rf /tmp/pkghttp
	    fi

	    ( cd /tmp ; mkdir pkghttp )
	    /bin/zcat < ./$HTTPPKG | ( cd /tmp/pkghttp ; tar xf - )  
	    if [ "$INSTALLTYPE" = "Tar" ] ; then
		HTTPInstallUsingTar
	    else
		pkgadd -d /tmp/pkghttp -R "$HTTPPATH" ISHTTP
		if [ $? -ne 0 ] ; then
		    Installed="NO"
		else
		    Installed="YES"
		fi
	    fi
	    if [ "$Installed" = "NO" ] ; then 
		echo $ERROR_LINE >> /usr/tmp/iscan_install_log
		rm -rf $HTTPPATH
	    fi

	    PressAnyKey
	    rm -rf /tmp/pkghttp
	    INSTHTTP="NO"
	fi

	##### Install ISSMTP #############################################
	if [ "$INSTSMTP" = "YES" ] ; then
	    if [ "$ISSMTPTRIAL" != "0" ] ; then
		Header
		echo ${BOLD}
		printf  "\tYou are currently running SMTP Trial Version.\n\n"
		echo ${UNBOLD}
		printf "\tDo you want to re-install InterScan VirusWall for SMTP?[  ]\b\b" ; read RESP
		ChkResp $RESP "no"
		if [ "$RESP" = "YES" ] ; then
		    printf "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
		printf "\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 "Removing the current SMTP system."
		    StartRemove "SMTP" 
		else
		    echo -n ${UNBOLD}
		    return
		fi
	    fi
	    Header
	    if [ "$LICENSE" != "OK" ] ; then
		printf "\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
		    echo -n ${UNBOLD}
		    return
		fi
	    fi

	    echo -n ${UNBOLD}
	    if [ ! -s ./$SMTPPKG ] ; then
		printf "\t\tCan not find InterScan E_MAIL ( $SMTPPKG ) in current directory.\n"
		PressAnyKey
		return
	    fi
	    # add on Sep 29th, 1999.
	    if [ -d /tmp/pkgsmtp ] ; then
		rm -rf /tmp/pkgsmtp
	    fi

	    ( cd /tmp ; mkdir pkgsmtp )
	    /bin/zcat < ./$SMTPPKG | ( cd /tmp/pkgsmtp ; tar xf - )  
	    if [ "$INSTALLTYPE" = "Tar" ] ; then
		SMTPInstallUsingTar
	    else
		pkgadd -d /tmp/pkgsmtp -R "$SMTPPATH" ISSMTP
		if [ $? -ne 0 ] ; then
		    Installed="NO"
		else
		    Installed="YES"
		fi
	    fi
	    if [ "$Installed" = "NO" ] ; then 
		echo $ERROR_LINE >> /usr/tmp/iscan_install_log
		rm -rf $SMTPPATH
	    fi

	    PressAnyKey
	    rm -rf /tmp/pkgsmtp
	    INSTSMTP="NO"
	fi

	##### Install TVCS #############################################
	InstallTVCSOnly  

    else
	##### Install ISCVP #############################################
	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"
    mailq="$ISVWROOT/ISBASE/IScan.BASE/mailq"

    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

    
    if [ ! -d $mailq ] ; then
	mkdir $mailq	
	chown iscan $mailq
	chgrp iscan $mailq
    	ln -s $mailq /etc/iscan/mailq
    fi

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

	PressAnyKey
	ADDRESS=root

	if [ "$UPGRADE" = "YES" ] ; then
	    grep "license=" /etc/iscan/intscan.ini
            # CZ, us-7106
	    if [ "$?" != "0" ] ; then
sed -e '/HttpScan=/i\
license=xxxxxx' < /etc/iscan/intscan.ini > /tmp/iscan$$
cp /tmp/iscan$$ /etc/iscan/intscan.ini
rm -f /tmp/iscan$$
	    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
	    echo ${BOLD}
	    printf "\t----------------------------------------------------------\n"
	    printf  "\tYour old intscan.ini has been saved in the                \n"
	    printf  "\t/etc/iscan/old_log_ini directory. The new intscan.ini     \n"
	    printf  "\tcontains default values. To retain your customized        \n"
	    printf  "\tintscan.ini values, you MUST manually replace the default \n" 
	    printf  "\tvalues in the new intscan.ini file with your customized values!\n\n" 
	    printf "\t----------------------------------------------------------\n"
	    echo ${UNBOLD}
	    PressAnyKey
	    rm -rf /tmp/iscan_old
	fi
	#songmei 3/29/2000 add end

	IS_PWD=`pwd`
	cd /
	echo "echo \"The trial version of InterScan VirusWall you have installed will expire in: 28 DAYS. For information 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 information 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 information 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 information 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 | 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
#
SetAdmin ()
{
	Header

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

	# 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

	# CZ, merge v36 code, use standard sed for editing	
	# server 
	sed "s/^server=.*/server=$NOTIFY_SERVER/g" < /etc/iscan/intscan.ini > /tmp/upgr.ini.$$
	cat /tmp/upgr.ini.$$ > /etc/iscan/intscan.ini
	rm -f /tmp/upgr.ini.$$ 

	# port 
	sed "s/^port=.*/port=$NOTIFY_PORT/g" < /etc/iscan/intscan.ini > /tmp/upgr.ini.$$
	cat /tmp/upgr.ini.$$ > /etc/iscan/intscan.ini
	rm -f /tmp/upgr.ini.$$ 
	
	PressAnyKey
}

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

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

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

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

    done
}

#
# Change Language paramter "IS_LANG"
#
ChangeLang ()
{
	Header
	printf "\t1.\tSet ${BOLD}Japanese${UNBOLD} Package to install.\n"
	printf "\t2.\tSet ${BOLD}English${UNBOLD}  Package to install.\n"
	printf "\n"

	printf "		Select a number [   ]\b\b\b" ; read RESP

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

}

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

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

	printf "\tInstall TVCS Agent for InterScan\t ${DASH} [ ${BOLD}${INSTTVCS}${UNBOLD} ]\n"
	printf "\tInstallation Path\t${BOLD}${TVCSPATH}${UNBOLD}\n"
	printf "\tInterScan VirusWall Package Language\t ${DASH} [ ${BOLD}${IS_LANG}${UNBOLD} ]\n"
	printf "\n"
	{
	 printf "\t1.\tModify option for InterScan VirusWall for BASE.\n"
	 printf "\t2.\tModify option for InterScan VirusWall for ADMIN.\n"
	 printf "\t3.\tModify option for InterScan VirusWall for FTP.\n"
	 printf "\t4.\tModify option for InterScan VirusWall for HTTP.\n"
	 printf "\t5.\tModify option for InterScan VirusWall for SMTP.\n"
	 printf "\t6.\tModify option for InterScan VirusWall for TVCS.\n"
	 printf "\t7.\tAdministration.\n"
	 printf "\t8.\tModify Package Language.\n"
	 printf "\t9.\tStart installation.\n"
	 printf "\t10.\tBack to Main Menu.\n"
	} >&2
	printf "\n"
	printf "		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 ;;
	* ) printf "${BELL}\t\tPlease type a valid choice\n"
	esac
	done
}



StartRemove ()
{
	case $1 in 
	BASE )  if [ "$ISBASE" = "Installed" ] ; then
		   for i in $ISFTP $ISHTTP $ISADMIN $ISSMTP $ISCVP $ISTVCS; do
		       if [ "$i" = "Installed" ] ; then
			   if [ "$silent" != "yes" ] ; then
			   echo "${BOLD}"
		           printf "\t\tYou have to remove other InterScan sub-system first if you really want to remove InterScan $1 System\n"
			   echo "${UNBOLD}"
			   PressAnyKey
			   fi
			   return ;
		       fi
		   done
	   if [ "$silent" != "yes" ] ; then
		   Header
		   echo ${BOLD}
		   printf  "\tRemoving the InterScan $1 package means no functionality\n"
		   printf "\twill exist on the system.\n"
                   printf "\n"
                   printf "\tDo you want to remove this package? [   ]\b\b\b" 
		   read RESP
                   echo ${UNBOLD}
                   ChkResp $RESP "NO"
                   if [ "$RESP" = "NO" ] ; then
                      return
                   fi
           fi
                   #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
    		   # remove BASE for HP
		   if [ "$INSTALLTYPE" = "Tar" ] ; then
	              if [ "$silent" = "yes" ] ; then
		          BaseRemoveUsingTar "yes"
                      else 
		          BaseRemoveUsingTar 
                      fi
	         # remove BASE for Solaris
		   else
	             pkgrm -R `cat /etc/iscan/pkg/ISBASE` ISBASE
                     if [ "$?" = "0" ] && [ ! -r /etc/iscan ] ; then
				Removed="YES"
                     else
				Removed="NO"
		     fi
		   fi
               if [ "$Removed" = "YES" ] ; 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
                   echo ${BOLD}
                   printf "\t------------------------------------------------------------\n" 
               printf "\tYour old intscan.ini has been temporarily saved in the\n" 
                   printf "\t/tmp/iscan_old directory. \n" 
                   printf "\t------------------------------------------------------------\n" 
                   echo ${UNBOLD}        
		   #songmei add end
             
		else
		   echo ${BOLD}
		   printf "\t\tPlease install the InterScan Base package first.\n"
		   echo ${UNBOLD}
		fi
		if [ "$silent" != "yes" ] ; then
	            PressAnyKey 
		fi
		;;
	ADMIN ) if [ "$ISADMIN" = "Installed" ] ; then
		   if [ "$silent" != "yes" ] ; then
		   Header
		   fi
		   ## if CVP installed can't remove this pkages
			if [ "$ISCVP" = "Installed" ] ; then 
				echo "${BOLD}"
				printf "\t\tYou have to remove InterScan CVP first\n"
				echo "${UNBOLD}"
		                if [ "$silent" != "yes" ] ; then
                       		   PressAnyKey
                                fi
                           	return ;
                        fi
		   ## if there is no CVP installed than remove ADMIN
	   if [ "$silent" != "yes" ] ; then
		   echo ${BOLD}
		   printf "\tRemoving the InterScan $1 package means you will not be able\n"
		   printf "\tto configure InterScan from a web browser.\n"
                   printf "\n"
                   printf "\tDo you want to remove this package? [   ]\b\b\b" 
		   read RESP
                   echo ${UNBOLD}
                   ChkResp $RESP "NO"
                   if [ "$RESP" = "NO" ] ; then
                      return
                   fi
           fi
 
                    
		   if [ "$INSTALLTYPE" = "Tar" ] ; then
		      if [ "$silent" = "yes" ] ; then
		          AdminRemoveUsingTar "yes"
		      else
		          AdminRemoveUsingTar
		      fi
		      rm -r $ADMINPATH
		   else
		   	pkgrm -R `cat /etc/iscan/pkg/ISADMIN` ISADMIN
		   	if [ "$?" = "0" ] && [ ! -s /etc/rc2.d/S99IScanHttpd ] ; then
				Removed="YES"
			        rm -r $ADMINPATH
                        else
				Removed="NO"
			fi
		   fi
               if [ "$Removed" = "YES" ] ; then
 			ISADMIN="None"	
			INSTADMIN="YES"
		   fi 
		else
		   echo ${BOLD}
		   printf "\t\tPlease install the InterScan ADMIN package first.\n"
		   echo ${UNBOLD}
		fi
		if [ "$silent" != "yes" ] ; then
	           PressAnyKey  
		fi
		;;
	FTP ) if [ "$ISFTP" = "Installed" ] ; then
	   if [ "$silent" != "yes" ] ; then
		Header
		echo ${BOLD}
		   printf  "\tRemoving the InterScan $1 package means your network user\n"
		   printf "\twill lose virus protection on their network file transfers.\n"
                   printf "\n"
                   printf "\tDo you want to remove this package? [   ]\b\b\b" 
		   read RESP
                   echo ${UNBOLD}
                   ChkResp $RESP "NO"
                   if [ "$RESP" = "NO" ] ; then
                      return
                   fi
           fi
		   if [ "$INSTALLTYPE" = "Tar" ] ; then
		      if [ "$silent" = "yes" ] ; then
		         FTPRemoveUsingTar "yes"
		      else
		         FTPRemoveUsingTar
		      fi
		   else
			pkgrm -R `cat /etc/iscan/pkg/ISFTP` ISFTP
			if [ "$?" = "0" ] && [ ! -s /etc/iscan/isftpd ] ; then
				Removed="YES"
			else
				Removed="NO"
			fi
		   fi
               if [ "$Removed" = "YES" ] ; then
			ISFTP="None"	
			rm -r $FTPPATH
			ISFTPTRIAL=0
		   fi 
	      else
		   echo ${BOLD}
		   printf "\t\tYou haven't install InterScan VirusWall FTP system yet\n"
		   echo ${UNBOLD}
	      fi

ATID=`grep "# notify_id" /etc/iscan/intscan.ini | cut -d' ' -f4`
for ind in ${ATID}
do
	atrm $ind
done
sed -e '/# notify_id/d' /etc/iscan/intscan.ini > /tmp/iscan$$
mv /tmp/iscan$$ /etc/iscan/intscan.ini
              if [ "$silent" != "yes" ] ; then
	         PressAnyKey 
	      fi
	      ;;
	SMTP ) if [ "$ISSMTP" = "Installed" ] ; then
	   if [ "$silent" != "yes" ] ; then
		  Header
		  echo ${BOLD}
		   printf "\tRemoving the InterScan $1 package means your network user\n"
		   printf "\twill lose virus protection on their e-mail transmissions.\n"
                   printf "\n"
                   printf "\tDo you want to remove this package? [   ]\b\b\b" 
		   read RESP
                   echo ${UNBOLD}
                   ChkResp $RESP "NO"
                   if [ "$RESP" = "NO" ] ; then
                      return
                   fi
           fi
		   if [ "$INSTALLTYPE" = "Tar" ] ; then
		      if [ "$silent" != "yes" ] ; then
		          SMTPRemoveUsingTar
		      else
		          SMTPRemoveUsingTar "yes"
		      fi
		   else
		  	pkgrm -R `cat /etc/iscan/pkg/ISSMTP` ISSMTP
		  	if [ "$?" = "0" ] && [ ! -s /etc/iscan/sendmail ] ; then
				Removed="YES"
                  else
				Removed="NO"
			fi
		   fi
               if [ "$Removed" = "YES" ] ; then
			ISSMTP="None"	
			rm -r $SMTPPATH
			ISSMTPTRIAL=0
		   fi 
		 else
		   echo ${BOLD}
		   printf "\t\tYou haven't install InterScan VirusWall SMTP system yet\n"
		   echo ${UNBOLD}
		fi
ATID=`grep "# notify_id" /etc/iscan/intscan.ini | cut -d' ' -f4`
for ind in ${ATID}
do
	atrm $ind
done
sed -e '/# notify_id/d' /etc/iscan/intscan.ini > /tmp/iscan$$
mv /tmp/iscan$$ /etc/iscan/intscan.ini
                if [ "$silent" != "yes" ] ; then
	           PressAnyKey 
		fi
		;;
	HTTP ) if [ "$ISHTTP" = "Installed" ] ; then
	   if [ "$silent" != "yes" ] ; then
		Header
		echo ${BOLD}
		   printf  "\tRemoving the InterScan $1 package means your network user\n"
		   printf "\twill lose virus protection on their Internet file transfers.\n"
                   printf "\n"
                   printf "\tDo you want to remove this package? [   ]\b\b\b" 
		   read RESP
                   echo ${UNBOLD}
                   ChkResp $RESP "NO"
                   if [ "$RESP" = "NO" ] ; then
                      return
                   fi
           fi
		   if [ "$INSTALLTYPE" = "Tar" ] ; then
		      if [ "$silent" != "yes" ] ; then
		          HTTPRemoveUsingTar
		      else
		          HTTPRemoveUsingTar "yes"
		      fi
		   else
			pkgrm -R `cat /etc/iscan/pkg/ISHTTP` ISHTTP
			if [ "$?" = "0" ] && [ ! -s /etc/iscan/ishttpd ] ; then
				Removed="YES"
			else
				Removed="NO"
			fi
		   fi
               if [ "$Removed" = "YES" ] ; then
			ISHTTP="None"	
			rm -r $HTTPPATH
			ISHTTPTRIAL=0
	       fi 

	      else
		echo ${BOLD}
		printf "\t\tYou haven't install InterScan VirusWall Base system yet\n"
		echo ${UNBOLD}
	       fi
ATID=`grep "# notify_id" /etc/iscan/intscan.ini | cut -d' ' -f4`
for ind in ${ATID}
do
	atrm $ind
done
sed -e '/# notify_id/d' /etc/iscan/intscan.ini > /tmp/iscan$$
mv /tmp/iscan$$ /etc/iscan/intscan.ini
               if [ "$silent" != "yes" ] ; then
	          PressAnyKey 
	       fi
	       ;;
	TVCS ) if [ "$ISTVCS" = "Installed" ] ; then
	   if [ "$silent" != "yes" ] ; then
		   Header
		   echo ${BOLD}
		   printf "\tPlease have your TVCS administrator remove\n"
		   printf "\tthis InterScan registration from TVCS console.\n"
                   printf "\tDo you want to remove this package? [   ]\b\b\b" 
		   read RESP
		   echo ${UNBOLD}
                   ChkResp $RESP "NO"
                   if [ "$RESP" = "NO" ] ; then
                      return
                   fi
	   fi
		   if [ "$INSTALLTYPE" = "Tar" ] ; then
		      if [ "$silent" != "yes" ] ; then
		      TVCSRemoveUsingTar
		      else
		      TVCSRemoveUsingTar "yes"
		      fi
			rm -rf $TVCSPATH
		   else
		   	pkgrm -R `cat /etc/iscan/pkg/ISTVCS` ISTVCS
		   	if [ "$?" = "0" ] ; then
				Removed="YES"
		        	rm -rf $TVCSPATH
                  else
				Removed="NO"
			fi
		   fi
               if [ "$Removed" = "YES" ] ; then
			ISTVCS="None"
			INSTTVCS="YES"
		   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
                        awk 'BEGIN { tvcs=0 } $1 ~ /^\[TVCS\]$/ { tvcs=1 } { if ( tvcs != 1 ) print $0 }' < /etc/iscan/intscan.ini > /tmp/tvcs.$$
                        cat /tmp/tvcs.$$ > /etc/iscan/intscan.ini
                        rm -f /tmp/tvcs.$$
		   fi
		else
		   echo ${BOLD}
		   printf "\t\tPlease install the Trend VCS Agent first.\n"
		   echo ${UNBOLD}
		fi
		if [ "$silent" != "yes" ] ; then
	           PressAnyKey  
		fi
		;;
	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
		echo ${BOLD}
                printf "\t\tYou haven't install InterScan CVP yet \n"
		echo ${UNBOLD}
		return 
              fi
ATID=`grep "# notify_id" /etc/iscan/intscan.ini | cut -d' ' -f4`
for ind in ${ATID}
do
        atrm $ind
done
sed -e '/# notify_id/d' /etc/iscan/intscan.ini > /tmp/iscan$$
mv /tmp/iscan$$ /etc/iscan/intscan.ini
	      PressAnyKey  ;;	
	
	esac
	RESP=""
}

Remove ()
{
	RRESP=""

	while ( true ) ; do

	Header
	printf "\n"
	printf "\t1.\tRemove InterScan VirusWall Base System.\n"
	printf "\t2.\tRemove InterScan VirusWall Admin System.\n"
	printf "\t3.\tRemove InterScan VirusWall FTP System.\n"
	printf "\t4.\tRemove InterScan VirusWall HTTP System.\n"
	printf "\t5.\tRemove InterScan VirusWall E-Mail System.\n"
	printf "\t6.\tRemove InterScan VirusWall TVCS System.\n"
	printf "\t7.\tRemove All InterScan VirusWall System.\n"
	printf "\t8.\tBack to Main Menu.\n"
	printf "\n"
	printf "		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 ;;
	* ) printf "${BELL}\t\tAn invalid choice was entered. Please try again.\n"
	esac

	done
}

RemoveCVP ()
{
	RESPCVP

	while (true) ; do 
	Header
	printf "\n"
	printf "\t1.\tRemove InterScan VirusWall Base System.\n"
	printf "\t2.\tRemove InterScan VirusWall Admin System.\n"
	printf "\t3.\tRemove InterScan VirusWall CVP System.\n"
	printf "\t4.\tRemove InterScan VirusWall TVCS System.\n"
	printf "\t5.\tRemove All InterScan VirusWall System.\n"
	printf "\t6.\tBack to Main Menu.\n"
	printf "\n"
        printf "              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 ;; 
	* ) printf "${BELL}\t\tAn invalid choice was entered. Please try again.\n"
	esac
	done
}	

Exit ()
{
    if [ ! -s /etc/iscan ] ; then
	exit 0
    fi

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

    printf "\tDo you want to start InterScan VirusWall now? [     ]\b\b\b\b\b" ; read RESP
    ChkResp $RESP "yes"

    # stop the default daemons anyway #

    b_if_xinetd=0
    case $DIS_TYPE in 
            turbolinux ) cat /etc/turbolinux-release | grep 7 > /dev/null 2>&1
			 if [ $? -eq 0 ] ; then
			    b_if_xinetd=1
			 fi;;
            SuSE       ) ;;
            redhat     ) cat /etc/redhat-release | grep 7 > /dev/null 2>&1
			 if [ $? -eq 0 ] ; then
			    b_if_xinetd=1
			 fi;;
            * ) printf "Installation doesn't support this platform\n";;
    esac

    if [ $b_if_xinetd -eq 0 ] ; then
      if [ -s /etc/iscan/pkg/ISFTP ] ; then
	sed -e "s/^\(ftp[ 	]*stream[ 	]*tcp[ 	]\)/#_ISCAN_ \1/" $INETD > /tmp/tmp$$
	cat /tmp/tmp$$ > $INETD
	INETDPID=`ps -e | grep inetd | grep -v grep | awk '{ print $1}'`
	if [ "$INETDPID" ] ; then
	    kill -HUP $INETDPID
	    sleep 3
	fi
      fi
    else  # using xinetd mechanism #
      ftp_file="/etc/xinetd.d/wu-ftpd"  
      if [ -s $ftp_file ] ; then  
        sed -e "s/\(disable[ 	]*=[ ]*\)no/\1yes/" \
	        $ftp_file > /tmp/tmp$$		    
	cat /tmp/tmp$$ > $ftp_file	    
	/etc/rc.d/init.d/xinetd restart > /dev/null 2>&1
      #else # may use proftpd #		
	#pro_ftp_pid=`ps -e | grep proftpd | grep -v grep | awk '{ print $1}'`
	#if [ "$pro_ftp_pid" ] ; then
	   #kill $pro_ftp_pid
	   #sleep 3
	#fi
      fi
    fi

    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
	    $ISCANFTPD_RC stop > /dev/null
	    echo 1 > /etc/iscan/pkg/ISFTPON
	    $ISCANFTPD_RC start > /dev/null
	fi
    
	### Turn on ISHTTP #####

	if [ -s /etc/iscan/pkg/ISHTTP ] ; then
	    $ISCANHTTPD_RC stop > /dev/null
	    echo 1 > /etc/iscan/pkg/ISHTTPON
	    $ISCANHTTPD_RC start > /dev/null
	fi

	#### Turn on ISSMTP #####

	if [ -s /etc/iscan/pkg/ISSMTP ] ; then
         # CZ, supress the warning message from sendmail
          
 	    $INIT_D/iscansmtps stop >/dev/null 2>&1

	    $INIT_D/sendmail stop >/dev/null 2>&1
 

	    echo 1 > /etc/iscan/pkg/ISSMTPON

	    $INIT_D/iscansmtps start > /dev/null
	    $INIT_D/sendmail start > /dev/null
  	fi

	#### Turn on ISCVP #####

	if [ -s /etc/iscan/pkg/ISCVP ] ; then 
	    $ISCANCVP_RC stop > /dev/null
	    echo 1 > /etc/iscan/pkg/ISCVPON
	    $ISCANCVP_RC start > /dev/null
	fi
PressAnyKey
	Header
	printf "\n"
	printf "\tUpdate your pattern file and scan engine\n"
	printf "\n"
    else
	if [ -s /etc/iscan/pkg/ISCVP ] ; then
	    echo 0 > /etc/iscan/pkg/ISCVPON         
	fi
           
	Header
	printf "\n"
	printf "\tYou could browse InterScan configuration page later\n"
	printf "\tAnd turn on InterScan VirusWall then.\n"
	printf "\n"
	printf "\tUpdate your pattern file and scan engine\n"
	printf "\n"
    fi
    chown -R iscan /etc/iscan/pkg
    chgrp -R iscan /etc/iscan/pkg
    exit 0
}

BringupBrowser ()
{
	NETSCAPE
	BROWSER
	BROWSERPATH
	firstchar
	HOSTNAME

	Header
	if [ "$ISADMIN" != "Installed" ] ; then
		echo ${BOLD}
		printf "\t\tPlease install the InterScan ADMIN package first.\n"
		echo ${UNBOLD}
		PressAnyKey
		return
	fi
	printf "\tPlease identify the browser you use(e.g. netscape): " ; read BROWSER
	NETSCAPE=${BROWSER:-"netscape"}
	BROWSER=`/usr/bin/which $NETSCAPE`
	if [ ! -x $BROWSER ] ; then
		printf "\tEnter the path where your browser is located: " ; read BROWSERPATH	
		if [ ! -x $BROWSERPATH/$NETSCAPE ] ; then
		   echo ${BOLD}
		   printf "\t\tNo executable browser program in the directory.\n"
		  # printf "\t\tBringup text configure menu...?\n"
		   echo ${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 > /dev/null &
	sleep 3
	Exit
}

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

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

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

CheckINSTCVP ()
{
    # Check if allready installed CVP and remove all of then
    clear
    CheckSW "ISCVP"
    Header 
    if [ "$ISCVP" = "Installed" ] ; then 
	echo ${BOLD}
	if [ "$ISCVPTRIAL" = "1" ] ; then 
	    printf "\t\tYou are currently running CVP Trial Version.\n" 
	else 
	    printf "\t\tYou are currently running InterScan for CVP.\n"
	fi
	printf "\t\tPlease remove it before installing this version.\n"
	echo ${UNBOLD}
	printf "\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
}

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

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

VCCINFOCHANGE ()
{
    PVCCINFO
    printf "  Specify the item number to modify or press Enter to accept:[   ]\b\b\b";read infnum
    case $infnum in
    1 ) printf "\tInterScan host:[          ]\b\b\b\b\b\b\b\b\b\b" ; read host;;
    2 ) printf "\t Site name:[                ]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" ; read LO ;;
    3 )printf "\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"; read VCC ;;
    * ) printf "\n"
    ;;
    esac
    PressAnyKey
    return
}

VCCINFO ()
{
    printf "\n"
    printf "\n"
    host=`hostname`;
    ipaddr=`/etc/iscan/ip $host`;
    printf "\tEnter the Trend VCS Site name for this server:[                ]\b\b\b\b\b\b\b\b\b\b\b\b\b\b" ; read LO
    printf "\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"; read VCC
    printf "\t Trend VCS Information:\n" ;
    PVCCINFO
    printf "\tCorrect?[    ]\b\b\b\b" ; read RESP
    ChkResp $RESP ""
}

DoRegister ()
{

    ADMINPATHD=$ADMINPATH/IScan.adm

    rg=`$ADMINPATHD/cgi-bin/Register /etc/iscan/intscan.ini` ;
    if [ $? -eq 1 ] ; then
#      cat /etc/iscan/solar.tmp >>/etc/iscan/intscan.ini;
	rm /etc/iscan/solar.tmp
	echo "Registration successful."
	$TVCS_RC start > /dev/null 2>&1
    else
	sed -e 's/VccServer=*.*.*.*/VccServer=0/' < /etc/iscan/intscan.ini > /tmp/solar ;
	cp /tmp/solar /etc/iscan/intscan.ini ;
	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
}

VCCRegister ()
{
    clear
    grep "TVCS" /etc/iscan/intscan.ini > /dev/null 2>&1;
    if [ $? -ne 0 ] ; then
	printf "Please install TVCS package, and register again!\n"
	PressAnyKey
    else
	rc=`grep "VccServer=0" /etc/iscan/intscan.ini`;
	if [ $? -ne 0 ] ;then
	    printf "Registration already done!\n"
	    PressAnyKey
	else
	    if [ -s /etc/iscan/ip ] ; then
		VCCINFO
		while (true) ; do
		    if [ "$RESP" = "YES" ] ; then
			break;
		    else
			clear
			VCCINFOCHANGE
			PVCCINFO
			printf "\tCorrect? (Enter y/Y to accept, n/N to reject)[    ]\b\b\b\b" ; read RESP
			ChkResp $RESP ""
		    fi
		done
		LO=`echo $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
	    fi
	fi
    fi
}

InstallCVPOnly ()
{
    # start install cvp pkg and check the licence
    if [ "$INSTCVP" = "YES" ] ; then 
	# check cvp pkg
	if [ ! -s ./$CVPPKG ] ; then
	    printf "\t\tCan not find InterScan CVP ($CVPPKG) in current directory.\n"
	    PressAnyKey
	    return
	fi
	# check license program exist or not
	if [ ! -s /etc/iscan/license ] ; then
	    printf " Can not find your license check program"
	    PressAnyKey
	    return
	fi

	Header

	printf "\tEnter serial number for InterScan VirusWall CVP:"
	echo -n ${BOLD}
	/etc/iscan/license CVP
	# change pkg into trail version if serial number not match
	if [ $? != 0 ] ; then
	    printf "\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
		echo -n ${UNBOLD}
		return
	    fi
	fi
	echo -n ${UNBOLD}

	# add on Sep 29th, 1999.
	if [ -d /tmp/pkgcvp ] ; then
	    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"
	fi
	PressAnyKey
	rm -rf /tmp/pkgcvp
	INSTCVP="NO"
    fi 
} 

InstallTVCSOnly ()
{
    Header

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

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

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

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

	if [ "$INSTALLTYPE" = "Tar" ] ; then
	    TVCSInstallUsingTar
	else
	    pkgadd -d /tmp/pkgtvcs -R "$TVCSPATH" ISTVCS
	    if [ $? -ne 0 ] ; then
		Installed="NO"
	    else
		Installed="YES"
	    fi
	fi
	if [ "$Installed" = "NO" ] ; then 
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $TVCSPATH
	else
	    printf "\n"
	    printf "\tNote: Be sure to register this InterScan Agent.\n"
	    ISTVCS="Installed" 
	    INSTTVCS="NO" 
	fi
	printf "\n"
	PressAnyKey
	rm -rf /tmp/pkgtvcs
    fi
}

InstallADMOnly ()
{
    Header

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

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

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

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

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

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

	if [ "$INSTALLTYPE" = "Tar" ] ; then
	    AdminInstallUsingTar
	else
	    pkgadd -d /tmp/pkgadmin -R "$ADMINPATH" ISADMIN
	    if [ $? -ne 0 ] ; then
		Installed="NO"
	    else
		Installed="YES"
	    fi
	fi
	if [ "$Installed" = "NO" ] ; then 
	    echo $ERROR_LINE >> /usr/tmp/iscan_install_log
	    rm -rf $ADMINPATH
	else
	    ISADMIN="Installed" 
            
            # RL notes: The following statements rebuild the UI links for eManager GUI
            #
            #
#
# SUSTAIN_RL_7833
#           Dynamically add the version information            
 	  SUSTAIN_7833=`/etc/iscan/sedini /etc/iscan/intscan.ini /etc/iscan/intscan.ini ok failed Registration Version "3.8 for linux"`
#end of sustain
#


	    #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
   
            # RL notes: 7661
            # Now it is time to modify the ownership of adm folder
            #
            chmodadmin_root_to_iscan

	fi
	PressAnyKey
	rm -rf /tmp/pkgadmin
	INSTADMIN="NO"
    fi
} 

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

	# add on Sep 29th, 1999.
	if [ -d /tmp/pkgbase ] ; then
	    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 -p $VIRUSLOGPATH
	    fi
	    ln -s $VIRUSLOGPATH /etc/iscan/virus

	    #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 -p /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

	    # SUSTAIN_RL
	    # Some parameters will be configured according to the language options
	    # 7583
	    #
		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.$$

			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("web_virinfo_url=http://www.antivirus.com/vinfo/\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("web_virdata_url=http://www.antivirus.com/vinfo/virusencyclo/default5.asp?VName=VIRUS_NAME\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Registration]$/ { print $0; printf("hostname=http://isux-t.activeupdate.trendmicro.com/activeupdate\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$
		fi

		if [ "$IS_LANG" = "JP" ] ; then
			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("jp_func=yes\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("web_virinfo_url=http://www.trendmicro.co.jp/virusnews/database/\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Scan-configuration]$/ { print $0; printf("web_virdata_url=http://inet.trendmicro.co.jp/virusinfo/default3.asp?VName=VIRUS_NAME\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$

			awk '$1 ~ /^\[Registration]$/ { print $0; printf("hostname=http://isux-t.activeupdate.trendmicro.com/activeupdate/japan\n"); next; } { print $0 }' < /etc/iscan/intscan.ini > /tmp/jpfunc.$$
			cat /tmp/jpfunc.$$ >| /etc/iscan/intscan.ini
			rm -f /tmp/jpfunc.$$
		fi
	fi
	PressAnyKey
	rm -rf /tmp/pkgbase
	INSTBASE="NO"
	# checking admin pkg
	if [ ! -s ./$ADMINPKG ] ; then
	    printf "\t\tCan not find InterScan Admin ( iscanhtp.tz ) in current directory.\n"
	    PressAnyKey
	    return
	fi
    fi
}

StartInstallCVP ()
{
    # if install CVP do the following command.
    # Check if ADMIN pkg installed
    if [ "$ISADMIN" != "Installed" ] && [ "$INSTADMIN" != "YES" ] ; then
	echo "${BOLD}"
	printf "\t\tYou have to install InterScan Virus ADMIN system.\n"
	echo "${UNBOLD}"
	PressAnyKey
	return
    fi
    if [ $ISBASE != "Installed" ] ; then 
	InstallBASEOnly 
	InstallADMOnly
	InstallCVPOnly
	InstallTVCSOnly	
    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
		echo ${BOLD}
		printf "\tYou are currently running CVP Trial Version.\n\n"
		echo ${UNBOLD}
		printf "\tDo you want to re-install InterScan VirusWall for CVP?[  ]\b\b" ; read RESP
		ChkResp $RESP "no"
		if [ "$RESP" = "YES" ] ; then
		    printf "Removing the TRIAL VERSION."
		    # pkgrm -R `cat /etc/iscan/pkg/ISCVP` ISCVP
		    StartRemove "CVP" 
		    CVPPKG="iscvp.tz"
		else
		    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
		echo ${BOLD} 
		printf "\t\tYou are currently running InterScan for CVP.\n"
		printf "\t\tPlease remove it before installing this version.\n"
		echo ${UNBOLD} 
		printf "\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
		echo ${BOLD} 
		printf "\tIf you are running InterScan VirusWall version $PKG_VERSION or earlier, \n"
		printf "\tyou must remove ALL packages before installing the CVP version.\n"
		printf "\tDo you want to do this now?\n" 
		printf "\n"
		printf "\t\tyes -- remove all packages \n"
		printf "\t\tno -- remove smtp, http, ftp only\n"
		printf "\t\tquit \n" 
		echo ${UNBOLD}
		printf "\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
		    printf "\n" 
		    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
    fi
}

InstallCVP ()
{
    ChkPkg
    ChkConfig 

    while ( true ); do
	Header
	printf "\t\tInstall InterScan VirusWall Base System\t${DASH}[ ${BOLD}${INSTBASE}${UNBOLD}]\n"
	printf "\t\tInstallation Path\t${BOLD}${BASEPATH}${UNBOLD}\n"
	printf "\t\tInstall InterScan VirusWall CGI Admin\t${DASH}[ ${BOLD}${INSTADMIN}${UNBOLD}]\n"
	printf "\t\tInstallation Path\t${BOLD}${ADMINPATH}${UNBOLD}\n"
	printf "\t\tInstall InterScan VirusWall CVP System\t${DASH}[ ${BOLD}${INSTCVP}${UNBOLD}]\n"
	printf "\t\tInstallation Path\t${BOLD}${CVPPATH}${UNBOLD}\n"
	printf "\t\tInstall InterScan VirusWall for TVCS\t${DASH}[ ${BOLD}${INSTTVCS}${UNBOLD}]\n"
	printf "\t\tInstallation Path\t${BOLD}${TVCSPATH}${UNBOLD}\n"
	printf "\t\tInterScan VirusWall Package Language\t${DASH}[ ${BOLD}${IS_LANG}${UNBOLD}]\n"
	printf "\n"
	{
	    printf "\t1.\tModify option for InterScan VirusWall for BASE.\n"
	    printf "\t2.\tModify option for InterScan VirusWall for ADMIN.\n"
	    printf "\t3.\tModify option for InterScan VirusWall for CVP. \n"
	    printf "\t4.\tModify option for InterScan VirusWall for TVCS.\n"
	    printf "\t5.\tAdministration.\n"
	    printf "\t6.\tModify Package Language.\n"
	    printf "\t7.\tStart installation.\n"
	    printf "\t8.\tBack to Main Menu.\n"
	} >&2
	printf "\n"
	printf "              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 ;;
	* ) printf "${BELL}\t\tAn invalid choice was entered. Please try again.\n"
	esac
    done
}	

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 
}

BaseInstallUsingTar ()
{
    Installed="NO"
    BASEPATHD=$BASEPATH/IScan.BASE

    printf "\tStart installation of BASE system.\n"
    Add_Iscan_user
    if [ ! -d $ISVWROOT ] ; then
	mkdir -p $ISVWROOT
    fi
    if [ ! -d $BASEPATH ] ; then
   	mkdir -p $BASEPATH
	if [ ! -d $BASEPATHD ] ; then
	    mkdir -p $BASEPATHD
	fi
    fi
    
    # set file ownership and modes
    chown -R root  /tmp/pkgbase/*
    chgrp -R iscan /tmp/pkgbase/*
    chmod -R 550   /tmp/pkgbase/*
    
    # copy files to final destination
    mv -f /tmp/pkgbase/* $BASEPATHD
    
    #======================#
    # Postinstall for BASE #
    #======================#
    
    if [ -s /etc/iscan ] ; then
	rm -rf /etc/iscan/*
    else
	mkdir /etc/iscan
    fi
    chmod 0755 /etc/iscan
    chown root /etc/iscan
    chgrp bin /etc/iscan
    
    if [ "$IS_LANG" = "EN" ] ; then
	VIRINFO_URL="http://www.trend.com/vinfo/virusencyclo/default.asp"
	VIRDATA_URL="http://www.antivirus.com/vinfo/virusencyclo/default5.asp?VName=VIRUS_NAME"
    else
	VIRINFO_URL="http://www.trendmicro.co.jp/virusnews/database/"
	VIRDATA_URL="http://inet.trendmicro.co.jp/virusinfo/default3.asp?VName=VIRUS_NAME"
    fi
    VIRINFO_URL_SED=`echo $VIRINFO_URL | sed -e 's/\\//\\\\\\//g'`
    VIRDATA_URL_SED=`echo $VIRDATA_URL | sed -e 's/\\//\\\\\\//g'`
    PATTERN="`/bin/ls ${BASEPATHD} |grep lpt`"
    PATTERN_NUM=`echo $PATTERN | sed -e 's/lpt$vpn.//g'`
    PLATFORM=`uname -s`

    TMP_BASE_FILES="$PATTERN ${BASEFILES}"
    
    # create links from target area to /etc/iscan
    for i in ${TMP_BASE_FILES} ; do
	ln -s ${BASEPATHD}/$i /etc/iscan/$i
    done

    chgrp -R iscan ${BASEPATHD}
    chmod 4550 ${BASEPATHD}/getconf 

    chown iscan ${BASEPATHD}/intscan.ini
    chmod 644 ${BASEPATHD}/intscan.ini 

    chmod 444 /etc/iscan/intscan.ini.orig /etc/iscan/lpt* /etc/iscan/mac*
  #  for file in intscan.ini
  #  do
	   chmod 660 /etc/iscan/intscan.ini  
	
#RICHARD_LIN_7106
# use sed command to modify the etc/iscan/intscan.ini 
     sed -e 's/__VIRINFO_URL__/'$VIRINFO_URL_SED'/' /etc/iscan/intscan.ini >/tmp/intscan.tmp
     cp /tmp/intscan.tmp /etc/iscan/intscan.ini
     rm /tmp/intscan.tmp

     sed -e 's/__VIRDATA_URL__/'$VIRDATA_URL_SED'/' /etc/iscan/intscan.ini >/tmp/intscan.tmp
     cp /tmp/intscan.tmp /etc/iscan/intscan.ini
     rm /tmp/intscan.tmp

     sed -e 's/__PATTERN_NUM__/'$PATTERN_NUM'/' /etc/iscan/intscan.ini >/tmp/intscan.tmp
     cp /tmp/intscan.tmp /etc/iscan/intscan.ini
     rm /tmp/intscan.tmp

     sed -e 's/__PLATFORM__/'$PLATFORM'/' /etc/iscan/intscan.ini >/tmp/intscan.tmp
     cp /tmp/intscan.tmp /etc/iscan/intscan.ini
     rm /tmp/intscan.tmp
# END OF RICHARD_LIN_7106

  #  done          
    #sed -e 's/__VIRDATA_URL__/'$VIRDATA_URL_SED'/' < /etc/iscan/intscan.ini > /tmp/iscandd
    #cp /tmp/iscandd /etc/iscan/intscan.ini
    #sed -e 's/__VIRINFO_URL__/'$VIRINFO_URL_SED'/' < /etc/iscan/intscan.ini > /tmp/iscandd
    #cp /tmp/iscandd /etc/iscan/intscan.ini
    #sed -e 's/__PATTERN_NUM__/'$PATTERN_NUM'/' < /etc/iscan/intscan.ini > /tmp/iscandd
    #cp /tmp/iscandd /etc/iscan/intscan.ini
    #rm -f /tmp/iscandd
    

    CRONTMPDIR="/tmp/iscan_tmp.$$"
    mkdir $CRONTMPDIR
    CRONTMPFILE="$CRONTMPDIR/istmp_cron.$$"

    touch $CRONTMPFILE
    chown root $CRONTMPFILE
    chmod 600 $CRONTMPFILE
    cp /dev/null $CRONTMPFILE

    crontab -l > /dev/null 2>&1
    if [ $? = 0 ] ; then # when crontab file doesn't exist, usually return 1.
	crontab -l | awk '$0 ~ /^#.*/ { if ( NR <= 3 ) next } $0 ~ /etc\/iscan/ { next } { print $0 }' 1> $CRONTMPFILE 2> /dev/null
    fi
    echo "0 * * * * /etc/iscan/prescan.cgi" >> $CRONTMPFILE
    echo "30 2 * * * /etc/iscan/cleanscan" >> $CRONTMPFILE
    echo "0 2 * * * /etc/iscan/purgefile" >> $CRONTMPFILE
    crontab $CRONTMPFILE > /dev/null 2>&1
    rm -rf $CRONTMPFILE
    
    #ln -s $BASEPATHD/S99ISmaild $INIT_D/iscanmaild
    #ln -s $BASEPATHD/S99ISmaild $RUN_D/iscanmaild

    # start the notification mail delivery daemon #
    
    $BASEPATHD/S99ISmaild stop   > /dev/null
    $BASEPATHD/S99ISmaild start  > /dev/null
      
    # Setup RC environment

    RC_SRC=$BASEPATHD/S99ISmaild
    INIT_RC=$INIT_D/iscanmaild
    SAVE_RC=""
    START_RC="S99ISmaild"
    STOP_RC="K99ISmaild"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
    RC_STOP_DIR=$DEF_RC_STOP_DIR

    SetupRCEnv

    chown iscan /etc/iscan
    chgrp iscan /etc/iscan
    # record base installation directory in /etc/iscan/pkg/ISBASE
    mkdir -p /etc/iscan/pkg
    echo $BASEPATH > /etc/iscan/pkg/ISBASE
    chmod 0755 /etc/iscan/pkg
    chown -R iscan /etc/iscan/pkg
    chgrp -R iscan /etc/iscan/pkg
    Installed="YES"
    if [ ! -d /etc/iscan/pids ] ; then
        mkdir -p /etc/iscan/pids
	chown -R iscan  /etc/iscan/pids
	chgrp -R iscan  /etc/iscan/pids
    fi                
    printf "\tFinish installation of Base system.\n"
}

BaseRemoveUsingTar ()
{
    Removed="NO"
    if [ -f /etc/iscan/pkg/ISBASE ] ; then
	BASEPATH=`cat /etc/iscan/pkg/ISBASE`
	BASEPATHD=$BATHPATH/IScan.BASE
    else
	echo $BOLD
	printf "\tCannot remove BASE; /etc/iscan/pkg/ISBASE not found.\n"
	echo $UNBOLD
	if [ "$silent" != "yes" ] ; then
	   PressAnyKey
	fi
	return
    fi
    
    printf "\tStart removal of Base system.\n"

    # remove cron jobs (by removing all lines with cleanscan in them)
    crontab -l | awk '$0 ~ /^#.*/ { if ( NR <= 3 ) next } $0 ~ /cleanscan/ { next } $0 ~ /prescan\.cgi/ { next } $0 ~ /purgefile/ { next } { print $0 }' 1> /tmp/crontab.$$ 2> /dev/null
    crontab /tmp/crontab.$$ > /dev/null 2>&1
    rm -f /tmp/crontab.$$
    ATID=`grep "# notify_id" /etc/iscan/intscan.ini | cut -d' ' -f4`
    for ind in $ATID ; do
	atrm $ind
    done
    rm -rf /etc/iscan

    # remove installed files
    for i in ${BASEFILES} ; do
	rm -f $BASEPATHD/$i
    done

    # kill isdelvd process
    isdelvd_pid=`$PS_ALL | grep isdelvd | grep -v grep | awk '{ print $1 }'`
    if [ $isdelvd_pid ] ; then
	    kill $isdelvd_pid
    fi

    if [ ! -r /etc/iscan ] ; then
	ISBASE="None"
	INSTBASE="YES"
    fi

    Remove_Iscan_user
    rm -rf /etc/iscan
    #rm -rf $INIT_D/iscanmaild
    #rm -rf $RUN_D/iscanmaild
    
    # Remove RC environment

    RC_SRC=$BASEPATHD/S99ISmaild
    INIT_RC=$INIT_D/iscanmaild
    SAVE_RC=""
    START_RC="S99ISmaild"
    STOP_RC="K99ISmaild"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
    RC_STOP_DIR=$DEF_RC_STOP_DIR
    
    RemoveRCEnv

    Removed="YES"

    printf "\tFinish removal of Base system.\n"
}

AdminInstallUsingTar ()
{
    Installed="NO"
    ADMINPATHD=$ADMINPATH/IScan.adm
    printf "\tStart installation of ADMIN system.\n"

    if [ ! -d $ADMINPATH ] ; then
	mkdir -p $ADMINPATH
	if [ ! -d $ADMINPATHD ] ; then
	    mkdir -p $ADMINPATHD
	fi
    fi

    # set file ownership and modes
    chown -R root /tmp/pkgadmin/*
    chgrp -R bin /tmp/pkgadmin/*
    chmod -R 555 /tmp/pkgadmin/*

    # copy files to final destination
    mv -f /tmp/pkgadmin/* $ADMINPATHD

    # replace xxxxxxxx with hostname.domainname in the httpd.conf
    if [ -s /usr/bin/domainname ] ; then
	NAME=`/bin/hostname`.`/usr/bin/domainname`
    else 
	NAME=`/bin/hostname`
    fi

    #echo "Your server name $NAME is changed at $ADMINPATHD/conf/httpd.conf"
    sed -e 's/__SERVER_NAME__/'$NAME'/'  ${ADMINPATHD}/conf/httpd.conf > /tmp/pp$$
    cp /tmp/pp$$ ${ADMINPATHD}/conf/httpd.conf

    # replace globally all / with \/
    echo $ADMINPATHD | sed -e 's/\//\\\//g' > /tmp/tmpvar$$

    # TMPVAR has the same path as $ADMINPATH but with the /'s escaped
    TMPVAR=`cat /tmp/tmpvar$$` ; rm -f /tmp/tmpvar$$

    # replace all PKG_INSTALL_ROOT with the install path in $ADMINPATH
    for i in httpd.conf ;  do
	sed -e 's/PKG_INSTALL_ROOT/'${TMPVAR}'/g'  ${ADMINPATHD}/conf/$i > /tmp/pp$$
	cp /tmp/pp$$ ${ADMINPATHD}/conf/$i
    done
    for i in httpd.conf ; do
	chmod 444 ${ADMINPATHD}/conf/$i
    done

    sed -e 's/PKG_INSTALL_ROOT/'${TMPVAR}'/g'  ${ADMINPATHD}/bin/iscanhttpds  > /tmp/pp$$
    cp /tmp/pp$$ ${ADMINPATHD}/bin/iscanhttpds

    # Setup RC environment
    RC_SRC=/tmp/pp$$
    INIT_RC=$ADMHTTP_RC
    SAVE_RC=""
    START_RC="S99IScanHttpd"
    STOP_RC="K99IScanHttpd"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
	RC_STOP_DIR=$DEF_RC_STOP_DIR

    SetupRCEnv

    #ln -s $ADMINPATHD/bin/iscanhttpds $INIT_D/iscanhttpds
    #ln -s $ADMINPATHD/bin/iscanhttpds $RUN_D/
    
    ln -s ${ADMINPATHD}/cgi-bin/virinfo /etc/iscan/virinfo
    if [ -f  ${ADMINPATHD}/cgi-bin/sedini  ] ; then
        ln -s ${ADMINPATHD}/cgi-bin/sedini /etc/iscan/sedini
    fi
    ln -s ${ADMINPATHD}/conf/.htpasswd /etc/iscan/.htpasswd

    # Add by Jessica Chang link some cgi programs to /etc/iscan  
    for i in ${ADMINFILES} ; do
	ln -s ${ADMINPATHD}/cgi-bin/$i /etc/iscan/$i
	chmod 544 /etc/iscan/$i
	chown bin /etc/iscan/$i
	chgrp bin /etc/iscan/$i
    done
    if [ ! -d /etc/iscan/actupdate ] ; then
       mkdir /etc/iscan/actupdate
 	#
	# SUSTAIN_RICHARD_LIN_7708
	# change the owner and the group of the /etc/iscan/actupdate
	#  
	chown iscan /etc/iscan/actupdate
	chgrp iscan /etc/iscan/actupdate
  
	#
	# end of 7708
	#
    fi

    ln -s  ${ADMINPATHD}/cgi-bin/libaction.so /etc/iscan/actupdate
    # for Linux dones has gettxt command.
    # TBD : it seems that we don't use this anymore #
    #if [ ! -f $LOCAL_GETTXT ]; then
    #ln -s ${ADMINPATHD}/cgi-bin/gettxt $LOCAL_GETTXT
    #fi
   
    echo ${ADMINPATH} > /etc/iscan/pkg/ISADMIN
    rm -rf /tmp/pp$$
    
    # start the Web Configuration Server
    $ADMHTTP_RC start > /dev/null 2>&1
    
    Installed="YES"

    chgrp -R iscan ${ADMINPATHD}
#    chmod -R 4550 ${ADMINPATHD}/cgi-bin
    printf "\tFinish installation of Admin system.\n"
}

AdminRemoveUsingTar ()
{
    Removed="NO"
    if [ -f /etc/iscan/pkg/ISADMIN ] ; then
	ADMINPATH=`cat /etc/iscan/pkg/ISADMIN`
	ADMINPATHD=$ADMINPATH\IScan.adm
    else
	echo $BOLD
	printf "\tCannot remove ADMIN; /etc/iscan/pkg/ISADMIN not found.\n"
	echo $UNBOLD
	if [ "$silent" != "yes" ] ; then
   	   PressAnyKey
	fi
	return
    fi

    printf "\tStart removal of Admin system.\n"

    # Stop the Web Configuration Server
    $ADMHTTP_RC stop > /dev/null 2>&1

    # Remove RC environment
    INIT_RC=$ADMHTTP_RC
    SAVE_RC=""
    START_RC="S99IScanHttpd"
    STOP_RC="K99IScanHttpd"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
	RC_STOP_DIR=$DEF_RC_STOP_DIR

    RemoveRCEnv

    rm -f /etc/iscan/.htpasswd   \
	  /etc/iscan/virinfo     \
	  $LOCAL_GETTXT          \
	  /etc/iscan/pkg/ISADMIN \
	  /etc/iscan/actupdate/libaction.so

    # remove the adm files
    for i in ${ADMINFILES} ; do
	rm -f /etc/iscan/$i
    done

    # remove the adm directories
    for i in ${ADMINDIRS} ; do 
	rm -rf $ADMINPATHD/$i
    done

    rm -rf  $INIT_D/iscanhttpds
    #rm -rf  $RUN_D/iscanhttpds
    ISADMIN="None"
    INSTADMIN="YES"

    Removed="YES"
    printf "\tFinish removal of Admin system.\n"
}

FTPInstallUsingTar ()
{
    Installed="NO"
    FTPPATHD=$FTPPATH/IScan.FTP

    printf "\tStart installation of FTP system.\n"
    if [ ! -d $FTPPATH ] ; then
	mkdir -p $FTPPATH
	if [ ! -d $FTPPATHD ] ; then
	    mkdir -p $FTPPATHD
	fi
    fi

    # set file ownership and modes
    chown -R root  /tmp/pkgftp/*
    chgrp -R iscan /tmp/pkgftp/*
    chmod -R 550   /tmp/pkgftp/*

    # copy files to final destination
    mv -f /tmp/pkgftp/* $FTPPATHD

    if [ "$FTPPKG" = "isftp.$TRIAL_EXT" ] ; then
	FTP_ORIG=${FTPPATHD}/isftpd.trial
    else
	FTP_ORIG=${FTPPATHD}/isftpd
    fi

    FTP_ISCAN=/etc/iscan/isftpd
    
    rm -f $FTP_ISCAN ; ln -s $FTP_ORIG $FTP_ISCAN
    chown root  $FTP_ISCAN
    chgrp iscan $FTP_ISCAN
    chmod 4555  $FTP_ISCAN

    # Setup RC environment
    RC_SRC="${FTPPATHD}/iscanftps"
    INIT_RC=$ISCANFTPD_RC
    SAVE_RC=""
    START_RC="S99ISftp"
    STOP_RC="K99ISftp"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
	RC_STOP_DIR=$DEF_RC_STOP_DIR

    SetupRCEnv

    echo 0 > /etc/iscan/pkg/ISFTPON
    echo ${FTPPATH} > /etc/iscan/pkg/ISFTP
    #ln -s $FTPPATHD/ISftp $ISCANFTPD_RC
    #ln -s $FTPPATHD/ISftp $RUN_D/iscanftps
    ln -s $FTPPATHD/iscanftps  /etc/iscan/iscanftps 
    chown root  $FTPPATHD/iscanftps
    chgrp iscan $FTPPATHD/iscanftps
    chmod 4555  $FTPPATHD/iscanftps
    
    ISFTP="Installed"
    INSTFTP="NO"
    Installed="YES"
    printf "\tFinish installation of FTP system.\n"
}

FTPRemoveUsingTar ()
{
    Removed="NO"

    if [ -f /etc/iscan/pkg/ISFTP ] ; then
	FTPPATH=`cat /etc/iscan/pkg/ISFTP`
	FTPPATHD=$FTPPATH/IScan.FTP
    else
	echo $BOLD
	printf "\tCannot remove FTP; /etc/iscan/pkg/ISFTP not found.\n"
	echo $UNBOLD
	if [ "$silent" != "yes" ] ; then
	PressAnyKey
	fi
	return
    fi

    printf "\tStart removal of FTP system.\n"

    # Stop FTP daemon
    $ISCANFTPD_RC stop > /dev/null 2>&1

    # Remove RC environment
    INIT_RC=$ISCANFTPD_RC
    SAVE_RC=""
    START_RC="S99ISftp"
    STOP_RC="K99ISftp"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
	RC_STOP_DIR=$DEF_RC_STOP_DIR

    RemoveRCEnv
 	
    b_if_xinetd=0
    case $DIS_TYPE in 
        turbolinux ) cat /etc/turbolinux-release | grep 7 > /dev/null 2>&1
		     if [ $? -eq 0 ] ; then
			b_if_xinetd=1
		     fi;;
	SuSE       ) ;;
        redhat     ) cat /etc/redhat-release | grep 7 > /dev/null 2>&1
       		     if [ $? -eq 0 ] ; then
		        b_if_xinetd=1
		     fi;;
        * ) printf "Installation doesn't support this platform\n";;
    esac

    FTPON=`cat /etc/iscan/pkg/ISFTPON`

    if [ $b_if_xinetd -eq 0 ] ; then  
      if [ "$FTPON" = "1" ] ; then
	status=`grep "^#_ISCAN_" $INETD | grep "in.ftpd"`
	if [ $? -eq 0 ] ; then
	    sed -e "s/^#_ISCAN_[ 	]*\(ftp[ 	]*stream[ 	]*tcp[ 	]\)/\1/" $INETD > /tmp/tmp$$
	    # NKO CHANGE
	    #/bin/mv -f /tmp/tmp$$ $INETD
	    cat /tmp/tmp$$ > $INETD
	else
	    #may be old version, we should modify it
	    status=`grep "^#" $INETD | grep "in.ftpd"`
	    if [ $? -eq 0 ] ; then
		sed -e "s/^#[ 	]*\(ftp[ 	]*stream[ 	]*tcp[ 	]\)/\1/" $INETD > /tmp/tmp$$
		# NKO CHANGE 
		#/bin/mv -f /tmp/tmp$$ $INETD
		cat /tmp/tmp$$ > $INETD

	    else
		printf "\tA problem was encountered programmatically while trying to restore /etc/inetd.conf file, please manually restore its FTP section.\n"
	    fi
	fi

	# Send HUP signal to the inetd process
	INETDPID=`$PS_ALL | grep inetd | grep -v grep | awk '{ print $1 }'`
	if [ $INETDPID ] ; then
	    kill -HUP $INETDPID
	fi
      fi
    else # using xinetd mechanism #
	if [ "$FTPON" = "1" ] ; then
	  ftp_file="/etc/xinetd.d/wu-ftpd"  
	  if [ -s $ftp_file ] ; then
       	    sed -e "s/\(disable[ 	]*=[ ]*\)yes/\1no/" \
		    $ftp_file > /tmp/tmp$$		    
	    cat /tmp/tmp$$ > $ftp_file	    
	    /etc/rc.d/init.d/xinetd restart > /dev/null 2>&1
	  #else # may use proftpd #	
	    #/etc/rc.d/init.d/proftpd start > /dev/null 2>&1
	  fi  
       	fi
    fi  

    rm -f   /etc/iscan/isftpd      \
	    /etc/iscan/pkg/ISFTP   \
	    /etc/iscan/pkg/ISFTPON  \
	    /etc/iscan/iscanftps  
	    #$INIT_D/iscanftps
	
    # Remove the ftp file
    for i in ${FTPFILES} ; do
	rm -f $FTPPATHD/$i
    done

    rm -rf $ISCANFTPD_RC
    #rm -rf $RUN_D/iscanftps

    ISFTP="None"
    INSTFTP="YES"
    Removed="YES"
    printf "\tFinish removal of FTP system.\n"
}

SMTPInstallUsingTar ()
{
    Installed="NO"
    SMTPPATHD=$SMTPPATH/IScan.SMTP

    ISPORS="issmtp"
    printf "\tStart installation of SMTP system.\n"
    if [ ! -d $SMTPPATH ] ; then
	mkdir -p $SMTPPATH
	if [ ! -d $SMTPPATHD ] ; then
	    mkdir -p $SMTPPATHD
	fi
    fi

    # Set file ownership and modes
    chown -R root  /tmp/pkgsmtp/*
    chgrp -R iscan /tmp/pkgsmtp/*
    chmod -R 550   /tmp/pkgsmtp/*

    # Copy files to final destination
    mv -f /tmp/pkgsmtp/* $SMTPPATHD

    rm -f /etc/iscan/sendmail
    if [ "$SMTPPKG" = "issmtp.$TRIAL_EXT" ] ; then
      ln -s "${SMTPPATHD}/issmtpd.trial" /etc/iscan/sendmail
    else
      ln -s "${SMTPPATHD}/issmtpd" /etc/iscan/sendmail
    fi

    chown root  /etc/iscan/sendmail
    chgrp iscan /etc/iscan/sendmail
    chmod 4550  /etc/iscan/sendmail

    # Setup RC environment
    RC_SRC="${SMTPPATHD}/iscansmtps"
    #INIT_RC=$ISCANSMTP_RC
    SAVE_RC=$SMTP_ORIG_RC
    RC_START_DIR=""
    RC_STOP_DIR=""



    echo 0 > /etc/iscan/pkg/ISSMTPON
    echo ${SMTPPATH} > /etc/iscan/pkg/ISSMTP
    
    #keep original sendmail script
    #RL WARNING for SUSE:the $INIT_D/sendmail is not available under the SUSE, thus the
    # installation script will complain in the SUSE
    #
    
    if [ -f $INIT_D/sendmail ]; then
    	cp $INIT_D/sendmail /etc/iscan/sendmail.rc
    	mv $INIT_D/sendmail $INIT_D/sendmail.orig
    fi
    #

    ln -s $SMTPPATHD/iscansmtps.rc $INIT_D/sendmail
    ln -s $SMTPPATHD/ISsmtp $INIT_D/iscansmtps
    #ln -s $SMTPPATHD/ISsmtp $RUN_D/iscansmtps
    ln -s $SMTPPATHD/iscansmtps  /etc/iscan/iscansmtps
    chown root  $SMTPPATHD/iscansmtps
    chgrp iscan $SMTPPATHD/iscansmtps
    chmod 4550  $SMTPPATHD/iscansmtps
    
    chown root  $SMTPPATHD/iscansmtps.rc   
    chgrp iscan $SMTPPATHD/iscansmtps.rc   
    chmod 4550  $SMTPPATHD/iscansmtps.rc

    chown root  $SMTPPATHD/ISsmtp   
    chgrp iscan $SMTPPATHD/ISsmtp   
    chmod 4550  $SMTPPATHD/ISsmtp

    ISSMTP="Installed"
    INSTSMTP="NO"
    Installed="YES"
    printf "\tFinish installation of SMTP system.\n"
}

SMTPRemoveUsingTar ()
{
    Removed="NO"

    if [ -f /etc/iscan/pkg/ISSMTP ] ; then
	SMTPPATH=`cat /etc/iscan/pkg/ISSMTP`
	SMTPPATHD=$SMTPPATH/IScan.SMTP
    else
	echo $BOLD
	printf "\tCannot remove SMTP; /etc/iscan/pkg/ISSMTP not found.\n"
	echo $UNBOLD
	if [ "$silent" != "yes" ] ; then
	PressAnyKey
	fi
	return
    fi

    printf "\tStart removal of SMTP system.\n"

    # Stop SMTP daemon
    $ISCANSMTP_RC stop > /dev/null 2>&1

    # Remove RC environment
    RC_SRC="${SMTPPATHD}/iscansmtps"
    INIT_RC=$ISCANSMTP_RC
    SAVE_RC=$SMTP_ORIG_RC
    RC_START_DIR=""
    RC_STOP_DIR=""

    #RemoveRCEnv

    rm -f   /etc/iscan/sendmail     \
	    /etc/iscan/pkg/ISSMTP   \
	    /etc/iscan/pkg/ISSMTPON \
	    /etc/iscan/iscansmtps  \
	    $INIT_D/iscansmtps  \
	    $INIT_D/sendmail


    cp $SMTP_ORIG_RC  $INIT_D/sendmail > /dev/null 2>&1
    mv $INIT_D/sendmail.orig  $INIT_D/sendmail > /dev/null 2>&1

    # Restart sendmail
    $INIT_D/sendmail start > /dev/null 2>&1
    # Remove files
    for i in $SMTPFILES ; do
	rm -f $SMTPPATHD/$i
    done
    rm -rf  $INIT_D/iscansmtps
    #rm -rf  $RUN_D/iscansmtps

    ISSMTP="None"
    INSTSMTP="YES"
    Removed="YES"
    printf "\tFinish removal of SMTP system.\n"
}

HTTPInstallUsingTar ()
{
    Installed="NO"
    HTTPPATHD=$HTTPPATH/IScan.HTTP

    printf "\tStart installation of HTTP system.\n"
    if [ ! -d $HTTPPATH ] ; then
	mkdir -p $HTTPPATH
	if [ ! -d $HTTPPATHD ] ; then
	    mkdir -p $HTTPPATHD
	fi
    fi

    # Set file ownership and modes
    chown -R root  /tmp/pkghttp/*
    chgrp -R iscan /tmp/pkghttp/*
    chmod -R 550   /tmp/pkghttp/*

    # Copy files to final destination
    mv -f /tmp/pkghttp/* $HTTPPATHD

    #if [ "$HTTPPKG" = "ishttp.$TRIAL_EXT" ] ; then
#	HTTP_ORIG=${HTTPPATHD}/ishttpd.trial
#    else
	HTTP_ORIG=${HTTPPATHD}/ishttpd
#    fi

    HTTP_ISCAN=/etc/iscan/ishttpd

    rm -f $HTTP_ISCAN ; ln -s $HTTP_ORIG $HTTP_ISCAN
    chown root  $HTTP_ORIG
    chgrp iscan $HTTP_ORIG
    chmod 4555  $HTTP_ORIG

    # Setup RC environment
    RC_SRC="${HTTPPATHD}/iscanhttpproxys"
    INIT_RC=$ISCANHTTPD_RC
    SAVE_RC=""
    START_RC="S99ISproxy"
    STOP_RC="K99ISproxy"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
	RC_STOP_DIR=$DEF_RC_STOP_DIR

    SetupRCEnv
    #ln -s $HTTPPATHD/ISproxy $ISCANHTTPD_RC
    #ln -s $HTTPPATHD/ISproxy $RUN_D/iscanhttpproxys
    ln -s $HTTPPATHD/iscanhttpproxys  /etc/iscan/iscanhttpproxys 
    chown root  $HTTPPATHD/iscanhttpproxys   
    chgrp iscan $HTTPPATHD/iscanhttpproxys   
    chmod 4550  $HTTPPATHD/iscanhttpproxys   

    echo 0 > /etc/iscan/pkg/ISHTTPON
    echo ${HTTPPATH} > /etc/iscan/pkg/ISHTTP
    ISHTTP="Installed"
    INSTHTTP="NO"
    Installed="YES"
    printf "\tFinish installation of HTTP system.\n"
}

HTTPRemoveUsingTar ()
{
    Removed="NO"

    if [ -f /etc/iscan/pkg/ISHTTP ] ; then
	HTTPPATH=`cat /etc/iscan/pkg/ISHTTP`
	HTTPPATHD=$HTTPPATH/IScan.HTTP
    else
	echo $BOLD
	printf "\tCannot remove HTTP; /etc/iscan/pkg/ISHTTP not found.\n"
	echo $UNBOLD
	if [ "$silent" != "yes" ] ; then
	PressAnyKey
	fi
	return
    fi

    printf "\tStart removal of HTTP system.\n"

    # Stop HTTP daemon
    $ISCANHTTPD_RC stop > /dev/null 2>&1

    # Remove RC environment
    RC_SRC="${HTTPPATHD}/iscanhttpproxys"
    INIT_RC=$ISCANHTTPD_RC
    SAVE_RC=""
    START_RC="S99ISproxy"
    STOP_RC="K99ISproxy"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
	RC_STOP_DIR=$DEF_RC_STOP_DIR

    RemoveRCEnv

    rm -f   /etc/iscan/ishttpd      \
	    /etc/iscan/pkg/ISHTTP   \
	    /etc/iscan/pkg/ISHTTPON \
	    /etc/iscan/iscanhttpproxys  
	    #$INIT_D/iscanhttpproxys

    # Remove http files
    for i in ${HTTPFILES} ; do
	rm -f $HTTPPATHD/$i
    done
    rm -rf $ISCANHTTPD_RC
    #rm -rf $RUN_D/iscanhttpproxys

    ISHTTP="None"
    INSTHTTP="YES"
    Removed="YES"
    printf "\tFinish removal of HTTP system.\n"
}

TVCSInstallUsingTar ()
{
    Installed="NO"
    TVCSPATHD=$TVCSPATH/IScan.TVCS

    # NKO JP-1198
    ADMINPATHD=$ADMINPATH/IScan.adm

    printf "\tStart installation of TVCS system.\n"
    if [ ! -d $TVCSPATH ] ; then
	mkdir -p $TVCSPATH
	if [ ! -d $TVCSPATHD ] ; then
	    mkdir -p $TVCSPATHD
	fi
    fi

    # Set file ownership and modes
    chown -R root  /tmp/pkgtvcs/*
    chgrp -R iscan /tmp/pkgtvcs/*
    chmod -R 550   /tmp/pkgtvcs/*

    # Copy files to final destination
    mv -f /tmp/pkgtvcs/* $TVCSPATHD

    # link files to cgi-bin directory of admin package
    
    chmod 4550 ${TVCSPATHD}/tvcsunint.cgi
    for tvcs_cgi in ${TVCS_CGI} ; do
	if [ ! -f ${ADMINPATHD}/cgi-bin/$tvcs_cgi ] ; then
	    ln -s ${TVCSPATHD}/$tvcs_cgi ${ADMINPATHD}/cgi-bin/.
	fi
    done

    for tvcs_img in ${TVCS_IMG} ; do
	if [ ! -f ${ADMINPATHD}/images/$tvcs_img ] ; then
	    ln -s ${TVCSPATHD}/$tvcs_img ${ADMINPATHD}/images/.
	fi
    done

    for i in ${TVCSFILES} ; do
	ln -s ${TVCSPATHD}/$i /etc/iscan/$i
	chmod 4544   /etc/iscan/$i
	chown root   /etc/iscan/$i
	chgrp iscan  /etc/iscan/$i
    done
   
    chmod 4550 ${TVCSPATHD}/tvcs_unint.sh
    chmod 4550 ${TVCSPATHD}/vcagt

    ln -s ${TVCSPATHD}/tvcs /etc/iscan/.tvcs
    chmod 4544   /etc/iscan/.tvcs
    chown root   /etc/iscan/.tvcs
    chgrp iscan  /etc/iscan/.tvcs

    # Setup RC environment
    RC_SRC="${TVCSPATHD}/iscantvcsagts"
    INIT_RC=$TVCS_RC
    SAVE_RC=""
    START_RC="S99IScanTVCS"
    STOP_RC="K99IScanTVCS"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
	RC_STOP_DIR=$DEF_RC_STOP_DIR

    SetupRCEnv

    # Append solar.ini to intscan.ini
    cat /etc/iscan/solar.ini >> /etc/iscan/intscan.ini

    echo ${TVCSPATH} > /etc/iscan/pkg/ISTVCS
    echo 1 > /etc/iscan/pkg/ISTVCSON
    
    # TBD #
    #ln -s $TVCSPATHD/IStvcs $TVCS_RC
    #ln -s $TVCS_RC $TVCSPATHD/IStvcs
    #ln -s $TVCSPATHD/iscantvcsagts  $RUN_D/
    ln -s $TVCSPATHD/iscantvcsagts  /etc/iscan/ 
    ISTVCS="Installed"	
    INSTTVCS="NO"
    Installed="YES"
    printf "\tFinish installation of TVCS system.\n"
}

TVCSRemoveUsingTar ()
{
    Removed="NO"

    if [ -f /etc/iscan/pkg/ISTVCS ] ; then
	TVCSPATH=`cat /etc/iscan/pkg/ISTVCS`
	TVCSPATHD=$TVCSPATH/IScan.TVCS
    else 
	echo $BOLD
	printf "\tCannot remove TVCS; /etc/iscan/pkg/ISTVCS not found.\n"
	echo $UNBOLD
	if [ "$silent" != "yes" ] ; then
	PressAnyKey
	fi
	return
    fi

    printf "\tStart removal of TVCS system.\n"

    # Stop TVCS agent
    $TVCS_RC stop > /dev/null 2>&1

    # Remove RC environment
    RC_SRC="${TVCSPATHD}/iscantvcsagts"
    INIT_RC=$TVCS_RC
    SAVE_RC=""
    START_RC="S99IScanTVCS"
    STOP_RC="K99IScanTVCS"
    RC_START_DIR="$RC_3D $RC_4D $RC_5D"
	RC_STOP_DIR=$DEF_RC_STOP_DIR

    RemoveRCEnv

    # remove tvcs links in cgi-bin directory of admin package
    if [ -f /etc/iscan/pkg/ISADMIN ] ; then
	ADMINPATH=`cat /etc/iscan/pkg/ISADMIN`
	ADMINPATHD=$ADMINPATH\IScan.adm
	for i in ${TVCS_CGI} ; do
	    rm -f ${ADMINPATHD}/cgi-bin/$i
	done
	for i in ${TVCS_IMG} ; do
	    rm -f ${ADMINPATHD}/images/$i
	done
    fi

    # Remove TVCS files
    for tvcs_proc in ${TVCSFILES} ; do
	if [ -f /etc/iscan/$tvcs_proc ] ; then
	    rm -f /etc/iscan/$tvcs_proc
	fi
    done

    rm -f   /etc/iscan/pkg/ISTVCS   \
	    /etc/iscan/pkg/ISTVCSON \
	    /etc/iscan/.tvcs \
	    /etc/iscan/iscantvcsagts

    awk 'BEGIN { tvcs=0 } $1 ~ /^\[TVCS\]$/ { tvcs=1 } { if ( tvcs != 1 ) print $0 }' < /etc/iscan/intscan.ini > /tmp/tvcs.$$
    cat /tmp/tvcs.$$ > /etc/iscan/intscan.ini
    rm -f /tmp/tvcs.$$
    rm -rf  $TVCS_RC
    #rm -rf  $RUN_D/iscantvcsagts

    ISTVCS="None"
    INSTTVCS="YES"
    Removed="YES"
    printf "\tFinish removal of TVCS system.\n"
}

FirstPageCVP ()
{
    done=false

    INSTALLCVP="YES"

    while [ $done = false ] ; do
	done=true
	{
	    Header
	    printf "\t\tMain Menu\n"
	    printf "\n"
	    MainStatusCVP 
	    printf "\n"
	    printf "\t1.\tInstall InterScan CVP sub-system.\n"
	    printf "\t2.\tRemove InterScan CVP sub-system.\n"
	    printf "\t3.\tRegister InterScan with a Trend VCS server.\n"
	    printf "\t4.\tConfigure InterScan CVP via web browser (exit Setup).\n"
	    printf "\t5.\tExit.\n"
	} >&2
	printf "\n"
	printf "\n"
	printf " \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 ) Exit ;;
	* ) printf "\t\tAn invalid choice was entered. Please try again.\n"
	    done=false ;;
	esac

    done
}




FirstPage ()
{
    # Check if allready installed CVP

    # NKO CHANGE
    if [ $PATCHUPGRADE = "YES" ] ; then
        PatchFirstPage
    fi


    CheckINSTCVP
    done=false

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

	Header
	printf "\t\tMain Menu\n"
	printf "\n"
	MainStatus

	printf "\t1.\tInstall InterScan VirusWall sub-system.\n"
	printf "\t2.\tRemove InterScan VirusWall sub-system.\n"
	printf "\t3.\tRegister InterScan with a Trend VCS server.\n"
	printf "\t4.\tConfigure InterScan via web browser (exit Setup).\n"
	printf "\t5.\tExit.\n"
	 
	} >&2
	printf "\n"
	printf "		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 ) Exit ;;
	* ) printf "\t\tAn invalid choice was entered. Please try again.\n"
	    done=false ;;
	esac

    done
}

# NKO CHANGE 
function PatchUpgradeConfirm
{
    # Check if allready installed CVP 
    CheckINSTCVP 
    done=false

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

	Header
	printf "\t\tInterScan VirusWall 3.6 Upgrade List\n"
	printf "\n"
	MainStatus

        printf "\t1.\tStart Patch upgrade.\n"
        printf "\t2.\tBack to Main Menu.\n"
	 
	} >&2
	printf "\n"
	printf "		Select a number [   ]\b\b\b";read RESP

	case $RESP in
        1 ) StartPatchUpgrade ; Main ; done=false ;;
	2 ) Main ;;
	* ) printf "\t\tAn invalid choice was entered. Please try again.\n"
	    done=false ;;
	esac

    done
}
function PatchFirstPage
{
    # Check if allready installed CVP 
    CheckINSTCVP 
    done=false

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

	Header
	printf "\t\tMain Menu\n"
	printf "\n"
	MainStatus

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

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

    done
}


# NKO CHANGE
function ChkISVWVersion
{
    if [ -s "/usr/bin/strings" ] ; then
	  STRINGSCMDFOUND="YES"
    else
	  STRINGSCMDFOUND="NO"
    fi

	# CZ modify the logic follow here
    if [ -f /etc/iscan/pkg/ISBASE ] ; then

	  if [ "$STRINGSCMDFOUND" = "NO" ] ; then
		if [ -s "/etc/iscan/sendmail" ] ; then
   	        TARGETVER=`/etc/iscan/sendmail -v | awk '{param=substr($2,1,3); print param;exit}'`
		else
			if [ -s "/etc/iscan/isftpd" ] ; then
       	        TARGETVER=`/etc/iscan/isftpd -v | awk '{param=substr($2,1,3); print param;exit}'`
			else
				if [ -s "/etc/iscan/ishttpd" ] ; then
	       	        TARGETVER=`/etc/iscan/ishttpd -v | awk '{param=substr($2,1,3); print param;exit}'`
				else
					echo "no valid installed modules found  "
					TARGETVER=""
				fi
			fi
		fi

	  else
	        Ch_Base_dir=`cat /etc/iscan/pkg/ISBASE`
	        Ch_Base_dir=$Ch_Base_dir"/IScan.BASE/iscanpsw" 
            TARGETVER=`strings $Ch_Base_dir | grep "Version 3." | awk '{param=substr($3,1,3); print param;exit}'  `
	  fi

      if [ $TARGETVER="3.6" ] || [ $TARGETVER="3.5"] ; then
            PATCHUPGRADE="NO" 
			UPGRADE="YES"
      elif [ $TARGETVER="3.7" ] ; then
            PATCHUPGRADE="NO" 
			UPGRADE="YES"
      else
            PATCHUPGRADE="NO" 
			UPGRADE="NO"	  	  
      fi
    else
        PATCHUPGRADE="NO"
		UPGRADE="NO"
    fi

	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
}


#------------------------------The Main Procedure of this script--------------------------------
#
#     					Main()
# This is the entry point function of this script
#-----------------------------------------------------------------------------------------------
function Main 
{
    loop=true
    
    #
    # Clean up the screen
    #
     clear

    #
    # Get this script's name: isinst
    #
    ISINST=`basename $0`

    #
    # Check what software components are installed in the computer and set the installation status
    # flags
    #
    ChkConfig

            TARGETVER=""   
	 if [ -s /etc/iscan/pkg/ISBASE ] ; then

		if [ -s "/etc/iscan/sendmail" ] ; then
	       	        TARGETVER=`/etc/iscan/sendmail -v | awk '{param=substr($2,1,3); print param;exit}'`
		else
			if [ -s "/etc/iscan/isftpd" ] ; then
		       	        TARGETVER=`/etc/iscan/isftpd -v | awk '{param=substr($2,1,3); print param;exit}'`
			else
				if [ -s "/etc/iscan/ishttpd" ] ; then
			       	        TARGETVER=`/etc/iscan/ishttpd -v | awk '{param=substr($2,1,3); print param;exit}'`
				else
					echo "no valid installed modules found  "
		  		fi
			fi
		fi
                
                needcheckupgrade="NO"
	        if [ "$TARGETVER" = "3.5" ] || [ "$TARGETVER" = "3.6" ] ||  [ "$TARGETVER" = "3.7"  ] ; then
                   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
		   Upgrade=""
                   SerialUp=`/etc/iscan/getconf Registration Serial`
		   echo $SerialUp | /etc/iscan/license > /dev/null
		   if [ "$?" != "0" ] ; then
			Upgrade="NO"
		   fi
		   while test -z "$Upgrade"
		   do
		       Header
		       echo "InterScan VirusWall $TARGETVER has been detected on your machine. It is recommended"
                       echo " that you upgrade to version 3.8. The following tasks will be done:"
		       echo -e "\t1) Version $TARGETVER will be removed."
		       echo -e "\t2) Version $TARGETVER /etc/iscan/intscan.ini will be merged with the version 3.8 intscan.ini file."
		       echo -e "\t3) Version $TARGETVER log file in /etc/iscan will be backed up."
		       echo -e "\t4) Version 3.8 will be installed."
		       echo -e "\tDuring upgrade, Interscan VirusWall service will be stopped."
		       echo -e " Do you want to proceed?[y/n] \c"
		       read ans
		       case $ans in 
		         [Y/y]*)  Upgrade="YES" ;;
		         [N/n]*)  Upgrade="NO" ;;
		         *) ;;
                       esac
                   done
	           if [ "$Upgrade" = "YES" ] ; then
	               UpgradeNew
                       return
                   fi
              fi
       fi
     INSTALLCVP="NO"
     FirstPage
}

 

#=========================================================
# 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           
        ADDGID="NO"
    else
        ADDGID="YES"
    fi
    grep "^iscan:" /etc/passwd >/dev/null 2>&1
    if [ "$?" = "0" ] ; then       
       ADDUID="NO"
    else
       ADDUID="YES"
    fi
}

#
#SUSTAIN_RICAHRD_LIN_7465
# CREATE FUNCTION TO USER NAME WITH A GIVEN PATH
# THE FUCTION NAME: function AddIscanGroupAndUser
# PARAMETERS:
# $1: THE USER NAME TO BE ADDED
# $2: THE DEFAULT HOME DIRECTORY NAME
# $3: THE GROUP NAME
# DESCRIPTIONS:
# THE FUNCITON WILL ADD $1 AS USER NAME WITH THE GIVEN $2 AS THE DEFAULT HOME DIRECTORY
#
function AddIscanUser
{
        GetCorrectPath="no"
	printf "\tAdding the new user: $1 in your UNIX system...\n"

	#check if the user $1 already exists ...
	checkFlag=`grep "^$1" /etc/passwd`

 	if [ "$checkFlag" != "" ] ; then
           return
        fi
	

	useradd -g $2 -M -s /bin/false -d / $1 > /dev/null 2>&1
       			
       	if [ "$?" != "0" ] ; then
            printf"\tUnable to create user $1. You need to manually create a new user $1 in your system.\n"
            PressAnyKey
       fi		  			
 }
#end of SUSTAIN_RICHARD_LIN



#=========================================================               
# 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
       printf  "\t Adding the new group: iscan in your UNIX system...\n"
       groupadd iscan > /dev/null 2>&1 
       if [ "$?" != "0" ] ; then
          printf  "\t fail to create the new group 'iscan' in your system.\n"
	  printf  "\t please manually creat a new group 'iscan'  then install Interscan again.\n"
	  exit 1
       fi
    fi
    ## ADD user id
    if [ "$ADDUID" = "YES" ] ; then
      AddIscanUser iscan iscan   
    fi
}                
#=========================================================
# Remove UID/GID after remove InterScan admin package
#=========================================================
function Remove_ID
{
    if [ "$silent" != "yes" ] ; then
    printf  "Do you want to remove $1 ID:iscan in your system --[y/n]"; read RESP
    ChkResp $RESP "error" 
    fi
    if [ "$1" = "group" ] ; then
       IDDEL="groupdel"
    elif [ "$1" = "user" ] ; then
       IDDEL="userdel"
    fi
    if [ "$RESP" = "YES" ] ; then
        printf  "\t Deleting the $1 ID:iscan in your system...\n"
	#$IDDEL iscan > /dev/null 2>&1 
	$IDDEL iscan 
	if [ "$?" != "0" ] ; then
	   printf  "\t fail to delete the $1 ID:iscan in your system.\n"
	   printf "\t please manually delete the ID from your system.\n"      
          PressAnyKey
        fi
    elif [ "$RESP" = "error" ] ; then
        printf "\t Invalid input."
	if [ "$silent" != "yes" ] ; then
	   PressAnyKey
	   Remove_ID $1
	fi
    fi
}
#=========================================================
# Remove UID/GID (iscan/iscan) from UNIX system
#=========================================================
function Remove_Iscan_user
{   
    #Remove UID
    Remove_ID "user"
    
    # once the iscan user got removed;
    # the group is gone too.
    #Remove GID
    #Remove_ID "group"
}
		           
#=========================================================
# Printing removing message
#=========================================================
function Print_RM_Msg
{
    printf "\tPlease remove or rename this existing id (iscan) and then re-install InterScan."  
    exit 1
}       


#rpm -qa | grep $DIS_LIB | grep $DIS_LIB_VER > /dev/null 2>&1
#if [ $? -ne 0 ] ; then
#    echo "Linux " $DIS_LIB $DIS_LIB_VER "is not supported this distribution."
#    exit 1
#fi

#rpm -qa | grep "libstdc++" > /dev/null 2>&1
#if [ $? -ne 0 ] ; then
#    ls -1 /usr/lib | grep "libstdc++" > /dev/null 2>&1
#    if [ $? -ne 0 ] ; then
#	echo "libstdc++ shared library required this release."
#	exit 1
#    fi
#fi





#=========================================================
# RL notes:
# Changing the ownership for base programs as 'iscan'
# some of the files will assigned as 'root'
#
#=========================================================
function chmodbase_root_to_iscan
{
    ### Action for base package
    base=`cat /etc/iscan/pkg/ISBASE`
    basepath=$base/IScan.BASE
   
    chmod 660 /etc/iscan/intscan.ini
    chown -R iscan $basepath 

    chgrp -R iscan $basepath
    chown -R iscan /etc/iscan
    
    chgrp -R iscan /etc/iscan
 
    chown root $basepath/prescan.cgi
    chmod 4550  $basepath/prescan.cgi

    chown root $basepath/isdelvd
    chmod 4550 $basepath/isdelvd

    chown root $basepath/vscan
    chmod 4555 $basepath/vscan
 
    chown root $basepath/purgefile
    chmod 4555 $basepath/purgefile
 

     
}


#=========================================================
# 
# RL notes:
# 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`
    
    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
    chown root $adminpath/cgi-bin/scannow.cgi
    chmod 4550  $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

    chown root  $adminpath/cgi-bin/mailscan.set
    chgrp iscan $adminpath/cgi-bin/mailscan.set
    chmod 4550  $adminpath/cgi-bin/mailscan.set

    chown root  $adminpath/cgi-bin/ftpscan.set
    chgrp iscan $adminpath/cgi-bin/ftpscan.set
    chmod 4550  $adminpath/cgi-bin/ftpscan.set

    chown root  $adminpath/cgi-bin/httpscan.set
    chgrp iscan $adminpath/cgi-bin/httpscan.set
    chmod 4550  $adminpath/cgi-bin/httpscan.set

    chown root  $adminpath/cgi-bin/getptn_net.cgi
    chgrp iscan $adminpath/cgi-bin/getptn_net.cgi
    chmod 4550  $adminpath/cgi-bin/getptn_net.cgi


    
    chown root $adminpath/cgi-bin/scanning
    chmod 4550  $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
 
    # so user can turn on/off daemons thru web  #
     chown root  $adminpath/cgi-bin/turnoff_on.cgi
     chgrp iscan $adminpath/cgi-bin/turnoff_on.cgi
     chmod 4555  $adminpath/cgi-bin/turnoff_on.cgi

   
     chown root  $adminpath/cgi-bin/mailadv.set 
     chgrp iscan $adminpath/cgi-bin/mailadv.set 
     chmod 4555  $adminpath/cgi-bin/mailadv.set 
  
     chown root  $adminpath/cgi-bin/outsave.cgi 
     chgrp iscan $adminpath/cgi-bin/outsave.cgi 
     chmod 4555  $adminpath/cgi-bin/outsave.cgi 




    chown root  /etc/iscan/start.cgi
    chgrp iscan /etc/iscan/start.cgi
    chmod 4550  /etc/iscan/start.cgi

    chown root  /etc/iscan/shutdown.cgi
    chgrp iscan /etc/iscan/shutdown.cgi
    chmod 4550  /etc/iscan/shutdown.cgi

    chown root  /etc/iscan/daemonhup.sh
    chgrp iscan /etc/iscan/daemonhup.sh
    chmod 4550  /etc/iscan/daemonhup.sh

}



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

ISINST=`basename $0`


########        Main Program    ########

if [ "$1" = "-i" ] ; then
    ASKYESNO="YES"
fi
 
Main


 
 
 


