#!/bin/ksh
###################################################################
#             (C) COPYRIGHT Candle Corporation 1999               #
#                      All Rights Reserved                        #
#                                                                 #
#       Licensed Materials - Property of Candle Corporation       #
#         Duplication or disclosure prohibited without the        #
#        expressed written consent of the Candle Corporation.     #
#                                                                 #
###################################################################

# @(#) install.sh - installs the installer (i.e. CI classes and JRE), and  
# @(#) invokes the Java CandleInstall programs.

############ Last seven mods ######################################
# @39 08/24/05 TR  Feature 14459 remove remote package creation options
# @38 06/21/05 TR  Will put user in CANDLEHOME defect 4437
# @37 05/07/05 LCL Support agent deployment depot install
# @36 04/14/05 LCL Only install 32-bit GSkit; #3357
# @35 04/05/05 LCL Create /keyfiles
# @34 03/16/05 LCL Rm "Candle" from Management Server message.
# @33 03/08/05 LCL Add ITMinstall. to JREEXE invocations
# @32 03/02/05 MTL GSKit support
# @31 02/02/05 LCL QI directories get 777
# @30 01/23/05 LCL Full silent install mode.
# @29 01/22/05 MTL Disable safe-mode (obsolete for JRE 1.4.2)
# @28 12/09/04 LCL Detect/set runtime flag for Candle/IBM titles
# @27 10/28/04 LCL Rm debug writes
# @26 10/12/04 MTL Add LAP tool silent install.
# @25 09/07/04 LCL Copy terms.agr to Candlehome.
# @24 09/01/04 LCL Allow alternateJRE for LAP; use installer JRE
# @23 08/18/04 LCL LAP files moved to under /unix
# @22 07/19/04 LCL Use IBM license acceptance process (LAP).
# @21 09/05/03 LCL Export saveLang so GUI agent starts will work.
# @20 07/08/03 LCL Clarify need to stop LDAP.
# @19 04/24/03 LCL MsgEdit has its own terms.agr
# @18 04/07/03 LCL XB excluded from Roma/CCC lists cuz it's shared
# @17 12/26/02 LCL Final chmod output gets dumped.
# @16 01/03/02 LCL Roma now uses same license confirmation as CCC
# @15 12/15/01 LCL Changed Linux test for SafeMode.
# @14 12/04/01 BRC Changed to support .tdd extensions on ci fixpacks.
###################################################################

#
#  Set alias for OSs without whoami 
#
[ -z "$(whoami 2>/dev/null)" ] && alias whoami='id | cut -d"(" -f2 | cut -d")" -f1' 

# The installer can be installed from any of the following sources:
#   1) old-style CD with external .ver files (read from the registry directory) and a "unix" product
#      directory.
#   2) new-style CD with internal .ver files (extracted from the product packages) and a "unix" product
#      directory.
#   3) Internet download with internal .ver files and no "unix" product directory.

#
# If you want to dpoebug you should uncomment the rest the line with JRE_DEBUG_ARGS not empty.
# Debug mode will suspend your VM which will be waiting for the connection with debugger.
#
JRE_DEBUG_ARGS=
#JRE_DEBUG_ARGS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=8001,suspend=y"
#

Err_report()
{
  #set -x
  case $1 in
    #$NLS-E$ "$PROGNAME warning:  $2, continuing ..."
    warn) print -u2 "$PROGNAME `nls_replace 'KCI0535I'`:  $2, `nls_replace 'KCI0536I'` ..."
          sleep 2
          return
          ;;
	#$NLS-E$ "$PROGNAME failure:  $2."	  
    fail) print -u2 "$PROGNAME `nls_replace 'KCI0537I'`:  $2."
          cleanUp 2
          ;;
    info) [ -n "$VERBOSE" ] && print -u2 "$PROGNAME        :  $2."
          return
          ;;
    msgs) print -u2 "$PROGNAME        :  $2"
          return
          ;;
  esac
}

Use_report()
{
  print -u2 "$PROGNAME [ -h ITM home ] -v"
  #$NLS-E$ "  Displays the version and release levels of the current installer."
  print -u2 "`nls_replace 'KCI1000I'`"
  print -u2 "$PROGNAME [ -h ITM home ] [ -d PRODUCT_PATH ] [ -c ] [ -p PARAMETER_FILE ]"
  #$NLS-E$ "  Specify -c to print diagnostic messages to the console."
  print -u2 "`nls_replace 'KCI1001I' -c`"
  #$NLS-E$ "  Specify -d to indicate the location of the product CD."
  print -u2 "`nls_replace 'KCI1002I' -d`"
  #$NLS-E$ "  Specify -h to indicate the location of the CandleHome."
  print -u2 "`nls_replace 'KCI1003I' -h`"
  #$NLS-E$ "  Specify -j to indicate the JRE installed location. This is available on Tandem system only."
  print -u2 "`nls_replace 'KCI1004I' -j`"
  #$NLS-E$ "  Specify -p for silent mode execution using the specified PARAMETER_FILE."
  print -u2 "`nls_replace 'KCI1005I' -p PARAMETER_FILE`"
  exit 2
}

# Run the License Acceptance Process (LAP) tool to get the user's agreement to the license

run_LAPTool()
{
  #set -x
  lapJar=lapapp.jar			# LAP jar name
  lapStatus=$CANDLEHOME/LAP/license/status.dat	# LAP status code file path
  lapCode=0
# always display license
#  [ -r $lapStatus ] && lapCode=$(grep "Status=" $lapStatus | cut -d"=" -f2)
  
  # Skip LAP if there was a previous acceptance in CandleHome
#  [ $lapCode = 9 ] && return

  # Backup any existing LAP files
  [ -d $CANDLEHOME/LAP ] && mv $CANDLEHOME/LAP $CANDLEHOME/LAP_old

  [ -z "$LAPMode" ] && LAPMode="$1 $2"

  # Prepare the LAP output area and environment
  mkdir $CANDLEHOME/LAP
  
  # Invoke LAP tool (aix requires special LIBPATH changes)
  lapJrePath=${JREEXE%%/bin*}
  [ "$(uname)" = "AIX" ] && export LIBPATH=$lapJrePath/lib:$lapJrePath/bin:$lapJrePath/bin/classic:$LIBPATH

  if [ -n "$silentMode" ]
  then
  #$NLS-E$ "\n\nUse of silent install mode implies license agreement acceptance. You can view the license file details in the $CANDLEHOME/LAP/license directory"  
   print "\n"
   nls_replace 'KCI1006I' $CANDLEHOME/LAP/license
   sleep 5
  fi

  $JREEXE -classpath $PROD_PATH/unix/LAP/LAP_HOME/$lapJar:$lapJrePath/lib/rt.jar:$lapJrePath/lib/i18n.jar $JRE_DEBUG_ARGS com.ibm.lex.lapapp.LAP $silentMode -l $PROD_PATH/unix/LAP/LA_HOME -s $CANDLEHOME/LAP $LAPMode

  # Status code=9 is the only valid acceptance code
  lapCode=$?
  [ -r $lapStatus ] && lapCode=$(grep "Status=" $lapStatus | cut -d"=" -f2)

  if [ $lapCode != 9 ]
  then
    rm -rf $CANDLEHOME/LAP
    [ -d $CANDLEHOME/LAP_old ] && mv $CANDLEHOME/LAP_old $CANDLEHOME/LAP
	#$NLS-E$ "terminating ... license declined"
    Err_report fail "`nls_replace 'KCI1007E'`"
  fi

  # Copy 3rd party license (if one exists)
  [ -f $PROD_PATH/unix/terms.agr ] && cp -p $PROD_PATH/unix/terms.agr $CANDLEHOME
  [ -f $PROD_PATH/unix/TERMS.AGR ] && cp -p $PROD_PATH/unix/TERMS.AGR $CANDLEHOME

}

# Compare the levels (version and release) of two products.  The "new" product (the one to be installed)
# is the basis for the comparison with the "cur" product (the one in CANDLEHOME).

checkLevel()
{
# $1 = the name of the current .ver file.
# $2 (if specified) = the name of the new .ver file.
  #set -x
  typeset -i curRel=0 curVer=0 newRel=0 newVer=0 useVRMF=0

  curFile=$curRegPath/$1
  newFile=$newRegPath/$1
  
  [ -z "$2" ] || newFile=$newRegPath/$2

  # Ensure that both files exist.

  #$NLS-E$ "could not read \"$curFile\""
  [ -r "$curFile" ] || Err_report fail "`nls_replace 'KCI1008E' \\"$curFile\\"`"
  #$NLS-E$ "could not read \"$newFile\""
  [ -r "$newFile" ] || Err_report fail "`nls_replace 'KCI1008E' \\"$newFile\\"`"

  # Get and compare the versions.

  # f32162 - need to use VRMF if present
  curVer=$(grep "^VRMF *=" $curFile | cut -d"=" -f2)
  [ $curVer -ne 0 ] && useVRMF=1
  [ $curVer -ne 0 ] || curVer=$(grep "^ver *=" $curFile | cut -d"=" -f2)
  #$NLS-E$ "could not determine the version number from \"$curFile\""
  [ $curVer -ne 0 ] || Err_report fail "`nls_replace 'KCI1009E' \\"$curFile\\"`"

  newVer=$(grep "^VRMF *=" $newFile | cut -d"=" -f2)
  [ $newVer -ne 0 ] && useVRMF=1
  [ $newVer -ne 0 ] || newVer=$(grep "^ver *=" $newFile | cut -d"=" -f2)
  #$NLS-E$ "could not determine the version number from \"$newFile\""
  [ $newVer -ne 0 ] || Err_report fail "`nls_replace 'KCI1009E' \\"$newFile\\"`"

  # f32162 - need to normalize versions to match VRMF format
  curVer=$(print $curVer | $AWK '{ nval=$1; pad=10^(8-length(nval)); printf("0%d", nval*pad)}')
  newVer=$(print $newVer | $AWK '{ nval=$1; pad=10^(8-length(nval)); printf("0%d", nval*pad)}')

  if [ newVer -lt curVer ]
  then
    levelStrg=Older
    return
  fi

  if [ newVer -gt curVer ]
  then
    levelStrg=Newer
    return
  fi
 
  # If we are not using VRMF, and the versions are identical, compare the releases (pre ITM 6.1 FP5 comparison).

  if [ $useVRMF -ne 1 ]
  then
    curRel=$(grep "^rel *=" $curFile | cut -d"=" -f2)
    newRel=$(grep "^rel *=" $newFile | cut -d"=" -f2)
    #$NLS-E$ "could not determine the release number from \"$curFile\""
    [ -n "$curRel" ] || Err_report fail "`nls_replace 'KCI1010E' \\"$curFile\\"`"
    #$NLS-E$ "could not determine the release number from \"$newFile\""
    [ -n "$newRel" ] || Err_report fail "`nls_replace 'KCI1010E' \\"$newFile\\"`"

    # Same version, older release.

    if [ newRel -lt curRel ]
    then
      levelStrg=Older
      return
    fi

    # Same version, same release.

    if [ newRel -eq curRel ]
    then
      levelStrg=Same
      return
    fi

    # New version
    levelStrg=Newer
    return
  fi

  # Same VRMF version.

  levelStrg=Same
  return
}

# Compare the levels (version and release) of any two products.  The "ref" product is the basis for the 
# comparison with the "cmp" product.

checkLevel2()
{
#set -x
# $1 = the complete pathname of the reference .ver file.
# $2 = the complete pathname of the .ver file to compare with the reference.

  typeset -i refRel=0 refVer=0 cmpRel=0 cmpVer=0

  refFile=$1
  cmpFile=$2
  
  # Ensure that both files exist.

  #$NLS-E$ "could not read \"$refFile\""
  [ -r "$refFile" ] || Err_report fail "`nls_replace 'KCI1008E' \\"$refFile\\"`"
  #$NLS-E$ "could not read \"$cmpFile\""
  [ -r "$cmpFile" ] || Err_report fail "`nls_replace 'KCI1008E' \\"$cmpFile\\"`"

  # Get and compare the versions.

  refVer=$(grep "^ver *=" $refFile | cut -d"=" -f2)
  cmpVer=$(grep "^ver *=" $cmpFile | cut -d"=" -f2)
  #$NLS-E$ "could not determine the version number from \"$refFile\""
  [ -n "$refVer" ] || Err_report fail "`nls_replace 'KCI1009E' \\"$refFile\\"`"
  #$NLS-E$ "could not determine the version number from \"$cmpFile\""
  [ -n "$cmpVer" ] || Err_report fail "`nls_replace 'KCI1009E' \\"$cmpFile\\"`"

  if [ cmpVer -lt refVer ]
  then
    levelStrg2=Older
    return
  fi

  if [ cmpVer -gt refVer ]
  then
    levelStrg2=Newer
    return
  fi
 
  # If the versions are identical, compare the releases.

  refRel=$(grep "^rel *=" $refFile | cut -d"=" -f2)
  cmpRel=$(grep "^rel *=" $cmpFile | cut -d"=" -f2)
  #$NLS-E$ "could not determine the release number from \"$refFile\""
  [ -n "$refRel" ] || Err_report fail "`nls_replace 'KCI1010E' \\"$refFile\\"`"
  #$NLS-E$ "could not determine the release number from \"$cmpFile\""
  [ -n "$cmpRel" ] || Err_report fail "`nls_replace 'KCI1010E' \\"$cmpFile\\"`"

  # Same version, older release.
  
  if [ cmpRel -lt refRel ]
  then
    levelStrg2=Older
    return
  fi

  # Same version, same release.

  if [ cmpRel -eq refRel ]
  then
    levelStrg2=Same
    return
  fi

  # Same version, newer release.

  levelStrg2=Newer
  return
}

cleanUp()
{ # $1 should equal either the word "trap" or a number.
  #set -x

  typeset -i rc=0
  typeset name=""
  
  #$NLS-E$ "caught $1, cleanup"
  [ "$1" = "trap" ] && Err_report info "`nls_replace 'KCI1011I' \"$1\"`"
  [[ "$1" = +([0-9]) ]] && rc=$1
  
  rm -f $CANDLETMP/*.sh $CANDLETMP/*.tbl $refVFile
  
  # EJF (13046) do not remove jr*.ver files as they are used later when install is re-run
  tmpCurrDir=$(pwd)
  cd $CANDLETMP

# defect 31944, exit install we change to 4
  if [[ "$rc" != 4 ]]
  then
    rm -f $(print $(ls *.ver | grep -v '^jr')) > /dev/null 2>&1
  else
    rc=0                # reset to 0
  fi

  cd $tmpCurrDir
  
  rm -f $thisTok
  rm -f $RegBackup/Pre_CT99_Roma

  # Delete backup LAP, or restore it
  if [ -d "$CANDLEHOME/LAP" ]
  then
    [ -d "$CANDLEHOME/LAP_old" ] && rm -rf "$CANDLEHOME/LAP_old"
  else
    [ -d "$CANDLEHOME/LAP_old" ] && mv "$CANDLEHOME/LAP_old" "$CANDLEHOME/LAP"
  fi

  exit $rc  # HP-UX needs the dollar sign.
}

# Display the release level of the current! installer.

dspInstLvl()
{
  #set -x
  typeset curRel="" curVer="" regFile=""
  
  #$NLS-E$ "specify or set CANDLEHOME, and rerun"
  [ -n "$CANDLEHOME" ] || Err_report fail "`nls_replace 'KCI1012E' CANDLEHOME`"

  regFile=$CANDLEHOME/registry/$ciVFile
  #$NLS-E$ "could not read file \"$regFile\""
  [ -r $regFile ] || Err_report fail "`nls_replace 'KCI1013E' \\"$regFile\\"`"

  # Get the version and release numbers.

  curVer=$(grep "^ver *=" $regFile | cut -d"=" -f2)
  #$NLS-E$ "could not determine the version number from \"$regFile\""
  [ -n "$curVer" ] || Err_report fail "`nls_replace 'KCI1009E' \\"$regFile\\"`"
  curRel=$(grep "^rel *=" $regFile | cut -d"=" -f2)
  #$NLS-E$ "could not determine the release number from \"$regFile\""
  [ -n "$curRel" ] || Err_report fail "`nls_replace 'KCI1010E' \\"$regFile\\"`"

  #$NLS-E$ "\nThe version and release levels of the installer are:"
  echo
  nls_replace 'KCI1014I'
  print "  ver = $curVer"
  print "  rel = $curRel \n"
}

# Determine the latest (newest) fixpack for a product.

findLatest()
{ # $1 = list of fixpack .ver file names (e.g. ciux6110.ver)
  #set -x
  typeset allNames name vFile
  typeset -i lateRel=0 lateVer=0 rel=0 ver=0
  
  # Find the latest (largest) version number.
  
  for vFile in $@
  do
    ver=$(grep "^ver *=" $newRegPath/$vFile 2> /dev/null | cut -d"=" -f2)
	#$NLS-E$ "could not determine the version number from \"$newRegPath/$vFile\""
    [ -n "$ver" ] || Err_report fail "`nls_replace 'KCI1009E' \\"$newRegPath/$vFile\\"`"
    [ ver -gt lateVer ] && lateVer=ver
  done
  
  # Find which .ver files specify the latest version.
  
  for vFile in $@
  do
    name=$(grep -l "^ver *= *$lateVer" $newRegPath/$vFile 2> /dev/null)
    name=${name##*/}  # Remove the path.
    allNames="$allNames $name"
  done

  #$NLS-E$ "could not find version number \"$lateVer\" in any .ver file"
  [ -n "$allNames" ] || Err_report fail "`nls_replace 'KCI1015E' \\"$lateVer\\"`"
  
  # Find the latest (largest) release number from the latest (i.e. those with largest version number) .ver files.
  
  for vFile in $allNames
  do
    rel=$(grep "^rel *=" $newRegPath/$vFile 2> /dev/null | cut -d"=" -f2)
	#$NLS-E$ "could not determine the release number from \"$newRegPath/$vFile\""
    [ -n "$rel" ] || Err_report fail "`nls_replace 'KCI1010E' \\"$newRegPath/$vFile\\"`"
    [ rel -gt lateRel ] && lateRel=rel
  done 
  
  # Determine the name of the latest (newest) fixpack.
  
  for vFile in $allNames
  do
    lateVFile=$(grep -l "^rel *= $lateRel" $newRegPath/$vFile 2> /dev/null)
    lateVFile=${lateVFile##*/}  # Remove the path.
  done
  
  #$NLS-E$ "could not find the latest fixpack"
  [ -n "$lateVFile" ] || Err_report fail "`nls_replace 'KCI1016E'`"
}


# Copy and nls_replace to CANDLEHOME/bin and msg directory to CANDLEHOME/config/nls. 

cpMo()
{ 
    [ ! -d $CANDLEHOME/bin ] && mkdir $CANDLEHOME/bin > /dev/null 2>&1
    [ ! -d $CANDLEHOME/bin ] && Err_report fail "`nls_replace 'KCI1091E' \\"$CANDLEHOME/bin\\"`"

    [ ! -d $CANDLEHOME/config ] && mkdir $CANDLEHOME/config > /dev/null 2>&1
    [ ! -d $CANDLEHOME/config ] && Err_report fail "`nls_replace 'KCI1091E' \\"$CANDLEHOME/config\\"`"

    [ ! -d $CANDLEHOME/config/nls ] && mkdir $CANDLEHOME/config/nls > /dev/null 2>&1
    [ ! -d $CANDLEHOME/config/nls ] && Err_report fail "`nls_replace 'KCI1091E' \\"$CANDLEHOME/config/nls\\"`"
	
    cp -R $nls_replace_dir/msg $CANDLEHOME/config/nls > /dev/null 2>&1
	
    [ ! -d $CANDLEHOME/config/nls/msg ] && Err_report warn "`nls_replace 'KCI1018I' \\"msg\\" \\"$CANDLEHOME/config/nls\\"`"

    cp $nls_replace_dir/nls_replace $CANDLEHOME/bin > /dev/null 2>&1
    [ ! -a $CANDLEHOME/bin/nls_replace ] && Err_report warn "`nls_replace 'KCI1018I' \\"nls_replace\\" \\"$CANDLEHOME/bin\\"`"	
		
    chmod 755 $CANDLEHOME/bin/nls_replace > /dev/null 2>&1
	#$NLS-E$ "could not change access permissions on \"$CANDLEHOME/bin/nls_replace\""
    [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI1019I' \\"$CANDLEHOME/bin/nls_replace\\"`"
}

# Unload a single file from an archive's tmp/ directory.

unloadTmpFile()
{ # $1 = name of file to unload.
  # $2 = full pathname of archive.
  #set -x

  typeset ext tFile
  
  #$NLS-E$ "cannot read package \"$2\""
  [ -r "$2" ] || Err_report fail "`nls_replace 'KCI1020E' \\"$2\\"`"
  
  ext=${2##*.}  # Get the extension, either "tar", "ctp" or "zxx".
  
  if [[ "$ext" = t* ]] # Uncompressed tar file.
  then
    tar -$tarOpt $2 tmp/$1 > /dev/null 2>&1
    # do chown and chmod for Linux.  defect 83100
    if [[ "$chownRoot" = y ]]
    then
      for tvf in $(tar tvf $2 tmp/$1 2> /dev/null | $AWK '{print $6}')
      do
        chown root:root $tvf
        chmod 755 $tvf
      done
    fi
	#$NLS-E$ "could not unload file \"$1\""
    [ -r tmp/$1 ] || Err_report fail "`nls_replace 'KCI1021E' \\"$1\\"`"
  else  # Compressed tar file.
    zcat < $2 | tar -$tarOpt - tmp/$1 > /dev/null 2>&1
	#$NLS-E$ "could not unload file \"$1\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1021E' \\"$1\\"`"
    # do chown and chmod for Linux.  defect 83100
    if [[ "$chownRoot" = y ]]
    then
      for tvf in $(zcat < $2 | tar tvf - tmp/$1 2> /dev/null | $AWK '{print $6}')
      do
        chown root:root $tvf
        chmod 755 $tvf
      done
    fi
  fi
}

# Ensure there is enough disk space available.

checkDiskSpace()
{ # $1 contains the name of the directory to check.
  # $2 = the number of kilobytes required.
  #set -x

  typeset thisOS=$(uname -s)

  dfCmd="df -kP"  # AIX and osf1 by default.
  [ "$thisOS" = "HP-UX" ] && dfCmd=bdf
  [ "$thisOS" = "SunOS" ] && dfCmd="df -k"

  $dfCmd $1 > /dev/null 2>&1  # Ensure that the file system is available.
  if [ $? -eq 0 ]
  then
    #$NLS-E$ "calculating available disk space"
    Err_report info "`nls_replace 'KCI1022I'`"

    # This was causing a very obscure problem on HP - the new method is safer and cleaner
    #set -A dfArray $($dfCmd $1 | tail -1)	# local translations cause parsing problems so lose the headers; #5663
    #kbAvail=${dfArray[3]}
    kbAvail=`$dfCmd $1 | grep "%" | $AWK '{if (NF == 5) print $3; else if (NF == 6) print $4}'`

  else
    #$NLS-E$ "df could not determine the available disk space in \"$1\""
    Err_report fail "`nls_replace 'KCI1023E' df \\"$1\\"`"
  fi

  if [ $2 -eq 0 ]  # The value of kbAvail is still needed even if there is nothing to install.
  then
    #$NLS-E$ "\"$kbAvail\" kilobytes available"
    Err_report info "`nls_replace 'KCI1024I' \\"$kbAvail\\"`"
    return
  fi

  if [ kbAvail -gt $2 ]
  then
    #$NLS-E$ "\"$kbAvail\" kilobytes available; only \"$2\" kilobytes required for the package(s)"
    Err_report info "`nls_replace 'KCI1025I' \\"$kbAvail\\" \\"$2\\"`"
	#$NLS-E$ "OK to install"
    Err_report info "`nls_replace 'KCI1026I'`"
  else
    #$NLS-E$ "\"$2\" kilobytes required for the package(s); only \"$kbAvail\" kilobytes available"
    Err_report fail "`nls_replace 'KCI1027E' \\"$2\\" \\"$kbAvail\\"`"
  fi
}

# Determine if there are CCC and/or Roma products available for installation.

findFamilies()
{
  #set -x

  typeset pc1 pkg pTbl=proddsc.tbl tFile=tmp/proddsc.tbl
  
  typeset cccPC=$CANDLETMP/cccPC.$$ romaPC=$CANDLETMP/romaPC.$$ jarPC=$CANDLETMP/jarPC.$$ verPC=$CANDLETMP/verPC.$$
  touch $cccPC $romaPC $jarPC $verPC

  # Get all of the possible product codes from all available product tables.
  
  for pkg in $(ls $PKGLOC/ci*.tar 2> /dev/null)  # Look in the CI packages for a product description table.
  do
    tar -$tarOpt $pkg $tFile > /dev/null 2>&1
    # do chown and chmod for Linux.  defect 83100
    if [[ "$chownRoot" = y ]]
    then
      for tvf in $(tar tvf $pkg $tFile 2> /dev/null | $AWK '{print $6}')
      do
        chown root:root $tvf
        chmod 755 $tvf
      done
    fi
    [ -r $tFile ] || continue  # Forget it.
    # xb is now a product shared between CCC and Roma (LL - 4/2003)
    # CCC product codes.
    cat $CANDLEHOME/$tFile | grep -v "[Rr]oma" | egrep -v "(ax|ci|jr|xb|\#|\*)" | cut -d"|" -f1 >> $cccPC 2> /dev/null
    # Roma product codes.
    cat $CANDLEHOME/$tFile | grep "[Rr]oma" | egrep -v "(ax|ci|jr|xb|\#|\*)" | cut -d"|" -f1 >> $romaPC 2> /dev/null    
    break  # One is enough.
  done
  
  #  Add the codes from the product table in $CANDLEHOME/registry.
  
  if [ -r $curRegPath/$pTbl ]
  then
    # CCC product codes.
    cat $curRegPath/$pTbl | grep -v "[Rr]oma" | egrep -v "(ax|ci|jr|xb|\#|\*)"  | cut -d"|" -f1 >> $cccPC 2> /dev/null 
    # Roma product codes.
    cat $curRegPath/$pTbl | grep "[Rr]oma" | egrep -v "(ax|ci|jr|xb|\#|\*)" | cut -d"|" -f1 >> $romaPC 2> /dev/null    
  fi

  #$NLS-E$ "could not determine product codes"
  [[ -s "$cccPC" || -s "$romaPC" ]] || Err_report fail "`nls_replace 'KCI1028E'`"
    
  # Get the product codes from the available jar files.
  
  ls $PKGLOC/*.j* 2> /dev/null | sed "s?.*/??" | cut -c1-2 > $jarPC
  #$NLS-E$ "could not find any jar files in \"$PKGLOC\""
  [ -s $jarPC ] || Err_report fail "`nls_replace 'KCI1029E' \\"$PKGLOC\\"`"
  sort -u $jarPC -o $jarPC 2> /dev/null  # Keep only unique product codes.
  
  # Get the installed product codes from the Registry
  
  ls $curRegPath/*.ver 2> /dev/null | sed "s?.*/??" | cut -c1-2 > $verPC
  [ -s $verPC ] && sort -u $verPC -o $verPC 2> /dev/null  # Keep only unique product codes.
  
  # See if there are CCC products available.
  
  if [[ -r "$cccPC" && -s "$cccPC" ]]
  then
    sort -u $cccPC -o $cccPC 2> /dev/null  # Keep only unique product codes.
    
    # Search the install media
    for pc1 in $(< $cccPC)
    do
      grep $pc1 $jarPC > /dev/null 2>&1
      if [ $? -eq 0 ]
      then
        hasCCC=true  # hasCCC is declared in Main.
        break
      fi
    done

    # Search the installed products (if any) 
    if [ -s $verPC ]
    then
      for pc1 in $(< $cccPC)
      do
        grep $pc1 $verPC > /dev/null 2>&1
        if [ $? -eq 0 ]
        then
          hadCCC=true  # hadCCC is declared in Main.
          break
        fi
      done
    fi
  fi

  # See if there are Roma products available.
  
  if [[ -r "$romaPC" && -s "$romaPC" ]]
  then
    sort -u $romaPC -o $romaPC 2> /dev/null  # Keep only unique product codes.
    
    # See if this is a RQ bundling of Roma (Candle Application Services Pac)
    grep "rq" $jarPC > /dev/null 2>&1
    [ $? -eq 0 ] && hasCASP=true  # hasCASP is declared in Main.

    # See if this package has an LDAP (for later eBP warning)
    grep "xs" $jarPC > /dev/null 2>&1
    [ $? -eq 0 ] && hasLDAP=true  # hasLDAP is declared in Main.

    # Search the install media
    for pc1 in $(< $romaPC)
    do
      grep $pc1 $jarPC > /dev/null 2>&1
      if [ $? -eq 0 ]
      then
        hasRoma=true  # hasRoma is declared in Main.
        break
      fi
    done

    # Search the installed products (if any) 
    if [ -s $verPC ]
    then
      # See if this is a RQ bundling of Roma (Candle Application Services Pac)
      grep "rq" $verPC > /dev/null 2>&1
      [ $? -eq 0 ] && hadCASP=true  # hadCASP is declared in Main.

      for pc1 in $(< $romaPC)
      do
        grep $pc1 $verPC > /dev/null 2>&1
        if [ $? -eq 0 ]
        then
          hadRoma=true  # hadRoma is declared in Main.
          break
        fi
      done
    fi  
  fi  

  # See if CMS is in the packaging
  grep "ms" $jarPC > /dev/null 2>&1
  [ $? -eq 0 ] && hasCMS=true  # hasCMS is declared in Main.

  rm -f $cccPC $jarPC $romaPC $verPC
}  

# Unload a .tar  or .ctpfile.
# @14

unTarPkg()
{ # $1 = full pathname of the file to untar.

  typeset -i i=0 maxTry=2
  typeset ext rc

  #$NLS-E$ "cannot read package \"$1\""
  [ -r "$1" ] || Err_report fail "`nls_replace 'KCI1030E' \\"$1\\"`"

  ext=${1##*.}  # ext (extension) will be either "ctp", "tar", tdd or "zdd" where d = a digit.
  while [ i -lt maxTry ]
  do
    if [[ "$ext" = t* ]]  # Uncompressed tar file.
    then
      tar -$tarOpt $1 > /dev/null 2>&1
      rc=$? 
      # do chown and chmod for Linux.  defect 83100
      if [[ "$chownRoot" = y ]]
      then
        for tvf in $(tar tvf $1 2> /dev/null | $AWK '{print $6}')
        do
          chown root:root $tvf
          chmod 755 $tvf
        done
      fi
      [ -r $1 ] || rc=-1
    else  # Compressed tar file.
      zcat < $1 | tar -$tarOpt - > /dev/null 2>&1
      rc=$?
      # do chown and chmod for Linux.  defect 83100
      if [[ "$chownRoot" = y ]]
      then
        for tvf in $(zcat < $1 | tar tvf - 2> /dev/null | $AWK '{print $6}')
        do
          chown root:root $tvf
          chmod 755 $tvf
        done
      fi
    fi

    if [ "$rc" = "0" ]
    then
      return
    else
      i=i+1
    fi
  done

  # If we get to here, the untar may have failed.

  #$NLS-E$ "unarchive of \"$1\" may have failed"
  Err_report warn "`nls_replace 'KCI1031I' \\"$1\\"`"
}

# Copy and rename the readme file.

cpRMFile()
{
:
#  typeset docDir=$CANDLEHOME/doc rmName=readme.txt
#  typeset desc rel toName
#  
#  if [ -f $PKGLOC/$rmName ]
#  then
#
#    desc=$(grep "Readme" $PKGLOC/$rmName 2> /dev/null | head -1)
#    if [ -z "$desc" ]
#    then
#      desc=$(grep "README" $PKGLOC/$rmName 2> /dev/null | head -1)
#      if [ -z "$desc" ]
#      then
#        Err_report warn "cannot copy \"$rmName\" file"
#        return
#      fi
#    fi
#
#    # Determine the product name.
#    
#    desc=${desc#*for}  # Remove the boilerplate.
#    desc=${desc%-*}    # Keep just the product name.
#    desc=$(print $desc | sed "s/  */_/g")  # Replace consecutive spaces with a single underscore.
#    desc=$(print $desc | sed "s,/,--,g")  # Replace slash with a two dashes. @12
#    
#    # Determine the release number.
#    
#    rel=$(grep "Release Information:" $PKGLOC/$rmName 2> /dev/null | cut -d":" -f2 | sed "s/  *//g")
#    if [ -z "$rel" ]
#    then
#      Err_report warn "cannot copy \"$rmName\" file"
#      return
#    fi
#    
#    # Copy the readme to the CANDLEHOME/doc directory.
#    
#    cp $PKGLOC/$rmName $docDir/readme_${desc}_$rel.txt > /dev/null 2>&1
#    [ $? -eq 0 ] || Err_report warn "could not copy the \"$rmName\" file"
#  fi
}

# Ask the user what readme file they want to view

execRMDialog()
{
  #set -x
  typeset -i i=1
  
  # Build a list of descriptions.
  
  for rmf in $(ls $CANDLEHOME/doc/readme*.txt)
  do
    desc=${rmf##*/}       # Remove the pathname.
    desc=${desc#readme_}  # Remove the boilerplate.
    desc=${desc%.txt}     # Ditto for the extension.
    desc=$(print $desc 2> /dev/null | sed "s/_/ /g")  # Replace the underscores with blanks.
    desc=$(print $desc 2> /dev/null | sed "s,--,/,g")  # Replace two dashes with slash. @12
    rmDescs[i]="$desc"
    i=i+1
  done
  
  #$NLS-E$ "Exit this menu."
  rmDescs[i]="`nls_replace 'KCI1032I'`"  # Add an escape clause.
  maxVal=$i
  
  # Generate a "select" menu.
  
  i=1
  #$NLS-E$ "\nSelect one of the following readme files: \n"
  echo
  nls_replace 'KCI1033I'
  echo
  while [ i -le maxVal ]
  do
    print "$i) ${rmDescs[i]}"
    i=i+1
  done
  
  # Force the user to make a selection.
  
  while [ anything ]
  do
    #$NLS-E$ "Please enter a valid number:  \c"
    print "`nls_replace 'KCI1034I'` \c"
    read rmIdx
    [[ $rmIdx = +([0-9]) ]] || continue  # Make sure it's a number.
    [[ "$rmIdx" -gt 0 && "$rmIdx" -le maxVal ]] && break  # It's a valid number.
  done
}

# Version all CI elements with respect to the base package.

checkCIElements()
{ # $1 = names of all elements without an extension (e.g. cienv1).

  #set -x
  typeset ele="" ext=tar
  
  for ele in $@
  do
    #$NLS-E$ "cannot read element package \"$PKGLOC/$ele.$ext\""
    [ -r "$PKGLOC/$ele.$ext" ] || Err_report fail "`nls_replace 'KCI1035E' \\"$PKGLOC/$ele.$ext\\"`"

    if [ "$hasRegDir" = "no" ]  # If necessary, extract the .ver file.
    then
      unloadTmpFile $ele.ver $PKGLOC/$ele.$ext 
    fi
    
	#$NLS-E$ "cannot read file \"$newRegPath/$ele.ver\""
    [ -r "$newRegPath/$ele.ver" ] || Err_report fail "`nls_replace 'KCI1036E' \\"$newRegPath/$ele.ver\\"`"
    
    # Compare the level of the element with that of the base package.  Install only if they are the same.
    
    checkLevel2 $newRegPath/$ciVFile $newRegPath/$ele.ver
	#$NLS-E$ "element package \"$ele\" at different level than base package"
    [ "$levelStrg2" = "Same" ] || Err_report fail "`nls_replace 'KCI1037E' \\"$ele\\"`"
  done
}

# Version all CI fixpack elements with respect to the base fixpack.

checkCIFixElements()
{ # $1 = name of base fixpack without an extension (e.g. ciux6110)
  # $2 = names of all element packages with extensions (e.g. ciux6110.t01).

  #set -x
  typeset baseName=$1 ele="" ext=""
  
  shift  # Skip the base.
  for ele in $@
  do
    ext=${ele##*.}  # Get the extension.
    ele=${ele%.*}$ext  # Construct the .ver file name (e.g. ciux6110t01).
	#$NLS-E$ "cannot read file \"$newRegPath/$ele.ver\""
    [ -r "$newRegPath/$ele.ver" ] || Err_report fail "`nls_replace 'KCI1036E' \\"$newRegPath/$ele.ver\\"`"
    
    # Compare the level of the element with that of the base package.  Install only if they are the same.
    
    checkLevel2 $newRegPath/$baseName.ver $newRegPath/$ele.ver
	#$NLS-E$ "element package \"$ele\" at different level than base package"
    [ "$levelStrg2" = "Same" ] || Err_report fail "`nls_replace 'KCI1037E' \\"$ele\\"`"
  done
}

# Version all JR elements with respect to the base package.

checkJRElements()
{ # $1 = names of all elements with an extension (e.g. jraix4.z01).

  #set -x
  typeset bName="" ele="" ext="" verName=""
  
  for ele in $@
  do
    #$NLS-E$ "cannot read element package \"$PKGLOC/$ele\""
    [ -r "$PKGLOC/$ele" ] || Err_report fail "`nls_replace 'KCI1038E' \\"$PKGLOC/$ele\\"`"

    # Construct the name of the .ver file.
    
    ext=${ele##*.}          # ext -> z01
    bName=${ele%.*}         # bName -> jraix4
    verName=$bName$ext.ver  # verName -> jraix4z01.ver
    
	#$NLS-E$ "cannot read file \"$newRegPath/$verName\""
    [ -r "$newRegPath/$verName" ] || Err_report fail "`nls_replace 'KCI1036E' \\"$newRegPath/$verName\\"`"
    
    # Compare the level of the element with that of the base package.  Install only if they are the same.
    
    checkLevel2 $newRegPath/$bName.ver $newRegPath/$verName
	#$NLS-E$ "element package \"$ele\" at different level than base package"
    [ "$levelStrg2" = "Same" ] || Err_report fail "`nls_replace 'KCI1037E' \\"$ele\\"`"
  done
}

# See if there are any fixpacks in the product directory.

lookForFixPacks()
{
  # For now (6/22/2005) make it appear there are no fixpacks because fixpack design isn't complete
  # The test below will think some std packages are fixpacks based on the test for an 8 char name
  # of which the last 4 char must be digits.  However, new platform codes will cause this to 
  # fail, such as axli6243.jar ... the 6243 fits the fixpack test, but is actually the platform code
  # for intel linux (kernel 2.4, 32-bit)
 
  #set -x 
  hasFixes=false
  return

  # Define local variables.
  
  typeset l4 name pkg
  typeset -i len=0
  
  ls $PKGLOC/*.j* > /dev/null 2>&1  # Redundant since this check has already been made.
  [ $? -eq 0 ] || return
  
  # Determine if there are any fixpacks available.
  
  for name in $(ls $PKGLOC/*.j* 2> /dev/null)
  do
    pkg=${name##*/}  # Remove the path.
    pkg=${pkg%.*}    # Remove the .jar extension.
    len=${#pkg}
    [ len -eq 8 ] || continue  # Fixpack names sans extension are always 8 characters.
    l4=$(print $pkg | cut -c5- 2> /dev/null)
    if [[ $l4 = @([0-9][0-9][0-9][0-9]) ]]  # The last 4 characters in a fixpack name are digits.
    then
      hasFixes=true
      return
    fi
  done
}  
  
# Install products or maintenance from the GUI.

startGUI()
{
  #$NLS-E$ "Please set DISPLAY environmental variable, and rerun $PROGNAME"
  [ -n "$DISPLAY" ] || Err_report fail "`nls_replace 'KCI1039E' DISPLAY $PROGNAME`"
    
  cd $CANDLEHOME/bin > /dev/null 2>&1
  #$NLS-E$ "could not cd to \"$CANDLEHOME/bin\" directory"
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0683E' \\"$CANDLEHOME/bin\\"`"
   
  export PATH=$savePath:/usr/bin/X11:/usr/openwin/bin

  $JREEXE -classpath $CLASSPATH $JRE_DEBUG_ARGS $SAFE_MODE $DEPLOY_MODE ${SUSE_VERSION} -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMInstallRAS.properties" ITMinstall.JFrame1 -dsa $kbAvail -ca $cArch -ch $CANDLEHOME -cd $PKGLOC -ad "$archDesc" $DEBUG_CON $instFam $tivoli

  [ $? -eq 0 ] || cleanUp 2
}

# Install support from command Line

startSupport()
{
  typeset -i rc=0

  # Create the reference .ver file.  This file is used to determine if anything was installed.

  touch $refVFile > /dev/null 2>&1
  #$NLS-E$ "could not create reference version file"
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1040E'`"

  cd $CANDLEHOME/bin > /dev/null 2>&1
  #$NLS-E$ "could not cd to \"$CANDLEHOME/bin\" directory"
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0683E' \\"$CANDLEHOME/bin\\"`"

  # Silent mode passes parameter filename to Java
  silentParmFile=""
  [ -n "$silentMode" ] && silentParmFile="-p $PARM_FILE"

  $JREEXE -classpath $CLASSPATH $JRE_DEBUG_ARGS $SAFE_MODE $DEPLOY_MODE ${SUSE_VERSION} -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMInstallRAS.properties" ITMinstall.CandleInstall -ch $CANDLEHOME -dl $PKGLOC -sa $kbAvail -ty supp -ca $cArch $DEBUG_CON $instFam $tivoli  $silentParmFile -i $(print $CDNAME | cut -c1-6) -k $AUTHKEY # Run the command.
  rc=$?
}
# Install products or maintenance from the command line.

startCmdLn()
{ # $1 will be either "fix" or "prod"
  #set -x
  
  typeset -i rc=0

  # Create the reference .ver file.  This file is used to determine if anything was installed.

  touch $refVFile > /dev/null 2>&1
  #$NLS-E$ "could not create reference version file"
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1040E'`"

  cd $CANDLEHOME/bin > /dev/null 2>&1
  #$NLS-E$ "could not cd to \"$CANDLEHOME/bin\" directory"
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0683E' \\"$CANDLEHOME/bin\\"`"

  # Silent mode passes parameter filename to Java
  silentParmFile=""
  [ -n "$silentMode" ] && silentParmFile="-p $PARM_FILE"

  $JREEXE -classpath $CLASSPATH $JRE_DEBUG_ARGS $SAFE_MODE $DEPLOY_MODE ${SUSE_VERSION} -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMInstallRAS.properties" ITMinstall.CandleInstall -ch $CANDLEHOME -dl $PKGLOC -sa $kbAvail -ty $1 -ca $cArch $DEBUG_CON $instFam $tivoli  $silentParmFile -i $(print $CDNAME | cut -c1-6) -k $AUTHKEY # Run the command.

  rc=$?

  # Just for cleanliness, clean up the plugin temp dir
  rm -rf /tmp/plugin_tmp
  #on HP-IA, the temporary directory is /var/tmp
	if [ -d /var/tmp/plugin_tmp ]
	then
		rm -rf /var/tmp/plugin_tmp > /dev/null 2>&1
	fi
  if [ rc -eq 2 ]  # Roma specific processing.
  then
    $CANDLEHOME/bin/cannoxterm.sh romaoa $CANDLEHOME
  else
    [ rc -eq 0 ] || cleanUp 2
  fi

  [ "$instFam" = "-ccc" ] || return
  # Set permissions on certain agents.

  # No SetPerm required for Tandem system
  if [[ "$(uname -s)" != "NONSTOP_KERNEL" ]]
  then
  cmd=$CANDLEHOME/bin/SetPerm
  if [ ! -x $cmd ]
  then
    #$NLS-E$ "command \"$cmd\" not found"
    Err_report warn "`nls_replace 'KCI1041I' \\"$cmd\\"`"

  else
    myID=$(id 2> /dev/null | cut -d"=" -f2 2> /dev/null | cut -d"(" -f1 2> /dev/null)
    # run SetPerm only if root user
    if [ "$myID" = "0" ]
    then
      saveMask="$(umask)"
      umask 0022        # APAR 89533 - Don't create links directory with 777 permission.
      $cmd -a  # Run the command (-a to suppress output)
      umask $saveMask   # APAR 89533 - Don't affect other things
    else 
      # For non-root user, just display a warning
      echo
	  #$NLS-E$ "The root user must run bin/SetPerm from the ITM home to complete the setup"
      Err_report warn "`nls_replace 'KCI1042I' bin/SetPerm`"
    fi
  fi	#end ! -x $cmd
  fi	#end uname -s

  # Only print the CandleConfig message if something was installed.

  for file in $(ls $curRegPath/*.ver)
  do
    if [ "$file" -nt "$refVFile" ]  # Products have been installed.
    then
      #$NLS-E$ "\n As a reminder, you should install product support on each of your TEM"
      #$NLS-E$ " servers for any agents you have just installed. This is done via the"
      #$NLS-E$ " \"[ITM home]/bin/itmcmd support\" command on your TEM servers."
      #$NLS-E$ "\n You may now configure any locally installed IBM Tivoli Monitoring product via"
      #$NLS-E$ " the \"$CANDLEHOME/bin/itmcmd config\" command. \n"
      echo
	  nls_replace 'KCI1043I'
	  nls_replace 'KCI1044I' \""$CANDLEHOME/bin/itmcmd support"\"
	  echo
	  nls_replace 'KCI1045I' \""$CANDLEHOME/bin/itmcmd config"\"
	  echo
	  break
    fi
  done
}

# Create remote packages via GUI.

startGUIRP()
{
  #$NLS-E$ "Please set DISPLAY environmental variable, and rerun $PROGNAME"
  [ -n "$DISPLAY" ] || Err_report fail "`nls_replace 'KCI1046E' DISPLAY $PROGNAME`"
  
  export PATH=$savePath:/usr/bin/X11:/usr/openwin/bin
 
#  print $JREEXE -classpath $SAFE_MODE $CLASSPATH ITMinstall.jclone_agents -ch $CANDLEHOME -dsa $kbAvail -ca $cArch -ad "$archDesc" -pl $PKGLOC -td $tarDir -pm $prodMode $DEBUG_CON
  
  $JREEXE -classpath $JRE_DEBUG_ARGS $SAFE_MODE $CLASSPATH -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMInstallRAS.properties" ITMinstall.jclone_agents -ch $CANDLEHOME -dsa $kbAvail -ca $cArch -ad "$archDesc" -pl $PKGLOC -td $tarDir -pm $prodMode $DEBUG_CON
  [ $? -eq 0 ] || cleanUp 2
  
  cd $CANDLEHOME/bin
  restart_proc start
  cd - 2> /dev/null > /dev/null
  
  cleanUp 0
}

# Create remote packages via the command line.

startCmdLnRP()
{
  #set -x 
#  print $JREEXE -classpath $CLASSPATH $SAFE_MODE ITMinstall.CandleClone -ch $CANDLEHOME -dsa $kbAvail -ca $cArch -pl $PKGLOC -td $tarDir -pm $prodMode $DEBUG_CON
  
  $JREEXE -classpath $CLASSPATH $JRE_DEBUG_ARGS $SAFE_MODE -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMInstallRAS.properties" ITMinstall.CandleClone -ch $CANDLEHOME -dsa $kbAvail -ca $cArch -pl $PKGLOC -td $tarDir -pm $prodMode $DEBUG_CON
  [ $? -eq 0 ] || cleanUp 2

  cd $CANDLEHOME/bin
  restart_proc start
  cd - 2> /dev/null > /dev/null
  
  cleanUp 0
}

# Install packages to the agent depot via the command line.

startCmdLnDepot()
{
  PROPS=-Ddebugcon=true 
  if [ "$DEBUG_CON" = "" ]
  then
     PROPS=-Ddebugcon=false
  fi
  $JREEXE $PROPS -classpath $CLASSPATH $JRE_DEBUG_ARGS -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMInstallRAS.properties" ITMinstall/AgentBundleDepotInstall -ch $CANDLEHOME -dsa $kbAvail -ca $cArch -pl $PKGLOC $DEBUG_CON
  [ $? -eq 0 ] || cleanUp 2

  cd $CANDLEHOME/bin
  restart_proc start
  cd - 2> /dev/null > /dev/null
  
  cleanUp 0
}

# Install packages to the agent depot via the GUI.

startGUIDepot()
{ 
  PROPS=-Ddebugcon=true 
  #set-x
  if [ "$DEBUG_CON" = "" ]
  then
     PROPS=-Ddebugcon=false
  fi
  $JREEXE $PROPS -classpath $CLASSPATH $JRE_DEBUG_ARGS -DGlobalDbgLevel="$TRACE_LEVEL" -DInstallRASConfig="$CANDLEHOME/config/ITMInstallRAS.properties" ITMinstall/AgentBundleDepotInstall -ch $CANDLEHOME -dsa $kbAvail -ca $cArch -pl $PKGLOC -m gui $DEBUG_CON
  [ $? -eq 0 ] || cleanUp 2

  cd $CANDLEHOME/bin
  restart_proc start
  cd - 2> /dev/null > /dev/null
  
  cleanUp 0
}

# Delete old token files, and warn if there is another install running in this <candlehome>.

procTokFiles()
{
  #set -x
  typeset -i maxAge=5  # Remove "remote" token files older than 5 days.
  typeset -i age=0 dot=0 doy=0
  typeset PID name
  
  ls ${baseTok}* | grep -v $thisTok > /dev/null 2>&1  # Other installs?
  [ $? -eq 0 ] || return
  
  doy=$(date +"%j")  # Day of the year (001 - 366)
  
  # Remove token files:
  # 1) created on this machine that are no longer connected to any process.
  # 2) created on other machines that are older than maxAge.
  
  for name in $(ls ${baseTok}* | grep -v $thisTok)
  do
    cat $name | grep "$thisMach" > /dev/null 2>&1 
    if [ $? -eq 0 ]  # The token file was created on this machine.
    then
      PID=${name##*_}
      ps -p $PID | grep $PID > /dev/null 2>&1
      [ $? -ne 0 ] && rm -f $name
    else  
      cat $name | grep "|" > /dev/null 2>&1  # Ensure the day of year field exists.
      [ $? -eq 0 ] || continue
      
      dot=$(cat $name | cut -d"|" -f2 | cut -d"|" -f1)  # Day the token file was created (001 - 366).

      if [ doy -ge dot ]
      then
        age=doy-dot
      else  # This could happen towards the end of a year, so "normalize" the day of the year.
        doy=366+doy
        age=doy-dot
      fi

      [ age -gt maxAge ] && rm -f $name
    fi
  done
  
  # Warn the user about possible simultaneous installs.
  
  ls ${baseTok}* | grep -v $thisTok > /dev/null 2>&1  # Check for other installs.
  if [ $? -eq 0 ] 
  then
    #$NLS-E$ "\nAn install may already be running in \"$CANDLEHOME\" from"
    #$NLS-E$ "the following machine(s): \n"
    echo
	nls_replace 'KCI1047I' \"$CANDLEHOME\"
	echo
	for name in $(ls ${baseTok}* | grep -v $thisTok)
    do
      print "  \c"; cat $name
    done
  
    #$NLS-E$ "\nContinue with this installation [ y or n; \"n\" is default ]?  \c"
    echo
	print "`nls_replace 'KCI1048I'` [1-`nls_replace 'KCI0197I'`, 2-`nls_replace 'KCI0198I'`; \"2\" `nls_replace 'KCI0199I'` ]?  \c"
    read
    case $REPLY in
      y*|Y*|1) ;;
    
          *) rm -f $thisTok
             cleanUp 0
             ;;
    esac
  fi
}


# routine to stop or start process.
restart_proc()
{
	#set -x
	Code=""
	Instance=""
	ret=0
	typeset RestartOSAgent="NO"
	if [ -n "$DEPLOY_MODE" ]
	then
		trap "true" 13 15  # Set trap.
		trap "cleanUp trap" 1 2 3  # Set trap.
	else
		trap "cleanUp trap" 1 2 3 15  # Set trap.
	fi
	for proc in $fld23
	do
		[ -n "$fieldSep" ] && Code=$(print "$proc" | cut -d "$fieldSep" -f1) || Code=$(print $proc | cut -c1-2)
		[ -n "$fieldSep" ] && Instance=$(print "$proc" | cut -d "$fieldSep" -f3) || Instance=$(print $proc | cut -c4-)

		# Get the product description from the proddsc.tbl file.  If there are running processes,
		# then this file should exist.
    
		if [[ -r $pFile ]]  
		then
			desc=$(grep "^$Code|" $pFile |head -1 | cut -d"|" -f2)  # desc -> "NetView/AIX Alert Adapter"
			[ -n "$desc" ] || desc=$Code  # Just in case.
		fi
    
		[ -n "$fieldSep" ] && PID=$(print "$proc" | cut -d "$fieldSep" -f2) || PID=$(print $proc | cut -c3-)
    
	
		# Don't restart TEMS, TEPS and TEP if deploy
		if [[ "$Code" = ms ]]
		then
			if [[ -z "$DEPLOY_MODE" ]] then 
				./CandleServer $1 $Instance
				CandleServerRet=$?
				#defect 54036
				if [[ $CandleServerRet != 0 ]] then
					# when TEMS wasn't stopped/started then we return -1 - this will used only to stop installation in that case. 
					ret=1
				fi
			fi
		else
		    if [[ -n "$DEPLOY_MODE" ]]
		    then
		      [[ "$Code" = @(cq|cj) ]] && continue
		    fi
			
			if [[ $Instance != "None" ]]
			then
				if [[ $Code = "um" ]]
				then
					./CandleAgent -p $Instance $1 $Code
				else
					if [[ $Code = "ud" && $1 = "stop" ]]
					then
						rFile=$CANDLEHOME/config/.ConfigData/RunInfo
						fieldSep=$(grep "FIELDSEP" $rFile | cut -d "=" -f2 2> /dev/null)
						thisMachShort=$(uname -a | cut -d" " -f2 | cut -f1 -d.)
						hostNameInRunInfo=$(cat $rFile | grep "$thisMachShort" | cut -d "$fieldSep" -f1 | head -1)
					fi 
					Instance=${Instance#${hostNameInRunInfo}_}
					./CandleAgent -o $Instance $1 $Code
				fi	
			else
				if [[ "$1" = "start" ]]
				then
					if [[ $Code = "lz" ]]
					then
	                  		RestartOSAgent=$Code
					else
						if [[ $Code = "ux" ]]
						then
      	            			RestartOSAgent=$Code
						else
      	          				./CandleAgent $1 $Code
						fi
					fi
				else
                    # in ITM 6.2 kf cannot be stopped if cq is running
                    # -f option allows also for that
					caOpt=""
				    if [[ "$1" = "stop" ]]
					then
					    if [[ $Code = "kf" ]]
					    then
					       # check if -f option is possible
						   cafFile=$CANDLEHOME/bin/tmp/caf.txt
					       ./CandleAgent 2> $cafFile
						   hasForce=$(grep "\-f" $cafFile)
						   if [[ "$hasForce" != "" ]]
						   then
						      caOpt="-f"
						   fi
					    fi
					fi
					./CandleAgent $caOpt $1 $Code
				fi
			fi
	      fi
	done

	if [[ $RestartOSAgent != "NO" ]]
	then
		./CandleAgent $1 $RestartOSAgent
	fi
	return $ret
}


# See if there is a CMS or if there are any agents that are still running.  If so, warn the user.
# @11

checkProcesses()
{
  #set -x
  typeset pFile=$CANDLEHOME/registry/proddsc.tbl
  typeset rFile=$CANDLEHOME/config/.ConfigData/RunInfo
  typeset PID desc  msg pc proc 
  
  # 37853 - need to use short hostname if long hostname is not in runinfo
  typeset thisMachShort=$(print $thisMach | cut -f1 -d.)
  
  [ -r $rFile ] || return  # It must be a new install if there is no RunInfo file.
  
  # Determine whether it's BigK or dinkySQL.
  
  fieldSep=$(grep "FIELDSEP" $rFile | cut -d "=" -f2 2> /dev/null)
  
  # See if there are any agents/CMS's running from this <candlehome> on this machine.
  
  if [ -n "$fieldSep" ]  # BigK.
  then
    cat $rFile | grep "$thisMachShort" > /dev/null 2>&1
    [ $? -eq 0 ] || return
    fld23=$(cat $rFile | grep "$thisMachShort" | cut -d "$fieldSep" -f2-4)  # fld23 -> ms|35594
  else  # dinkySQL.
    cat $rFile | sed "s/  */ /g" | grep "$thisMachShort" | cut -c1 | grep "N" > /dev/null 2>&1
    [ $? -eq 0 ] || return
    fld23=$(cat $rFile | sed "s/  */ /g" | grep "$thisMachShort" | grep "^N" | cut -d" " -f2)  # fld23 -> ms35594
  fi
  
  # Check to see if the processes are actually running.
  
  for proc in $fld23
  do
    [ -n "$fieldSep" ] && PID=$(print "$proc" | cut -d "$fieldSep" -f2) || PID=$(print $proc | cut -c2-3)
    ps -p $PID | grep $PID > /dev/null 2>&1
    [ $? -eq 0 ] || continue
	#$NLS-E$ "\\nThe following processes are currently running: \\n"
    msg="\\n`nls_replace 'KCI1049I'` \\n"
    break
  done
  
  if [ -n "$msg" ]
  then
    print "$msg"

    for proc in $fld23
    do
      [ -n "$fieldSep" ] && pc=$(print "$proc" | cut -d "$fieldSep" -f1) || pc=$(print $proc | cut -c1-2)
      [ -n "$fieldSep" ] && instance=$(print "$proc" | cut -d "$fieldSep" -f3) || instance=$(print $proc | cut -c4-)
    
      # Get the product description from the proddsc.tbl file.  If there are running processes,
      # then this file should exist.
    
      if [ -r $pFile ]  
      then
        desc=$(grep "^$pc|" $pFile |head -1 | cut -d"|" -f2)  # desc -> "NetView/AIX Alert Adapter"
        [ -n "$desc" ] || desc=$pc  # Just in case.
      fi
    
      [ -n "$fieldSep" ] && PID=$(print "$proc" | cut -d "$fieldSep" -f2) || PID=$(print $proc | cut -c3-)
    
	  #$NLS-E$ "  Product = $desc  PID = $PID"
      print "  `nls_replace 'KCI1050I'` = $desc  PID = $PID"
    done
  
    # Check for silent mode
    if [ -n "$silentMode" ]
    then
      # See if they ask to ignore the running proceses (looking for something like "INSTALL_IGNORE_RUNNING_PROCESSES=YES")
      [ -f "$PARM_FILE" ] && continueInstall=$(grep -i "INSTALL_IGNORE_RUNNING_PROCESSES" $PARM_FILE 2>/dev/null | grep -i "y" 2>/dev/null)

      # Warn and exit if they didn't ask to ignore running processes
      if [ -z "$continueInstall" ]
      then
	    #$NLS-E$ "Silent install aborting due to running processes detected on this CandleHome."
        Err_report msgs "`nls_replace 'KCI1051I'`"
        cleanUp 1	# Exit - cc=1
      fi

      # Otherwise just continue with the install
	  #$NLS-E$ "Silent install option to ignore running processes detected"
      Err_report warn "`nls_replace 'KCI1052I'`"
      cd $CANDLEHOME/bin
      restart_proc stop
	  restart_proc_rc=$?
	  if [[ $restart_proc_rc != 0 ]] then
	    #$NLS-E$ "Silent install aborting due to stopping TEMS failure. Chcek logs for more details."
        Err_report msgs "`nls_replace 'KCI1232I'`"
		#$NLS-E$ "You can try to manually stop TEMS and again run installation."
		Err_report fail "`nls_replace 'KCI1234I'`"
	  fi 
      cd -
      return
    fi

	#$NLS-E$ "Existing products found to be running will be restarted during installation."
    Err_report warn "`nls_replace 'KCI1053I'`"
	#$NLS-E$ "\nContinue with this installation [ y or n; \"y\" is default ]?  \c"
    print "\n`nls_replace 'KCI1054I'` [ 1-`nls_replace 'KCI0197I'`, 2-`nls_replace 'KCI0198I'`; \"1\" `nls_replace 'KCI0199I'` ]?  \c"

    read
    case $REPLY in
      n*|N*|2) cleanUp 0  # Exit.
	     ;;
    
          *) 
     		cd $CANDLEHOME/bin
     		restart_proc stop
			restart_proc_rc=$?
			if [[ $restart_proc_rc != 0 ]] then
				#$NLS-E$ "Install aborting due to stopping TEMS failure. Chcek logs for more details."
				Err_report msgs "`nls_replace 'KCI1233I'`"
				#$NLS-E$ "You can try to manually stop TEMS and again run installation."
				Err_report fail "`nls_replace 'KCI1234I'`"
			fi 
     		cd -
             ;;
    esac
  
    echo
  fi
}

# Warn user about the dangers of installing over an old Roma

BspWarn()
{
  #$NLS-E$ "****************** WARNING ***************************"
  Err_report msgs "`nls_replace 'KCI1055I'`"
  #$NLS-E$ "You are installing eBP over an existing BSP $LDAPVer"
  #$NLS-E$ "installation.   This will migrate your LDAP to the"
  #$NLS-E$ "newer version,  and requires your LDAP server to be"
  #$NLS-E$ "shut down.  Please ensure that there are no remote"
  #$NLS-E$ "BSP applications  using this server.  If this file"
  #$NLS-E$ "system is accessible from other systems,  please"
  #$NLS-E$ "ensure that there are no applications running on"
  #$NLS-E$ "other systems from this CandleHome."
  
  Err_report msgs "`nls_replace 'KCI1056I' $LDAPVer`"  
  Err_report msgs "`nls_replace 'KCI1057I'`"
  Err_report msgs "`nls_replace 'KCI1058I'`"
  Err_report msgs "`nls_replace 'KCI1059I'`"
  Err_report msgs " "
  #$NLS-E$ "Please stop your LDAP server now if it's currently running."
  Err_report msgs "`nls_replace 'KCI1060I' LDAP`"
  #$NLS-E$ "****************** WARNING ***************************"
  Err_report msgs "`nls_replace 'KCI1055I'`"
  sleep 5
}

# Routine renames obsolete Roma 2.1 directory names for a BSP 3.1 install
# This entire routine can be removed when 2.1 is no longer supported.

Bsp21Rename()
{
  #set -x
  RegBackup=$1

  # We don't do any renames except for a prior BSP 2.1
  [ -r "$RegBackup/Pre_CT99_Roma" ] || return

  oldName=$(cat $RegBackup/Pre_CT99_Roma|head -1)
  oldPath=${oldName%/ldap}
  oldArch=${oldPath#$CANDLEHOME/roma/}
  typeset thisOS=$(uname -s)
  #
  # Roma directory remap from BSP 2.1->3.1
  # 2.1	-> 3.1
  # aix4 	-> aix42
  # aix43 	-> aix42
  # hp10 	-> hp11
  # hp102 	-> hp11
  # sol25 	-> sol26
  # sol273 	-> sol26

  # New install paths for BSP 3.1
  [ "$thisOS" = "AIX" ] && newPath=$CANDLEHOME/roma/aix42
  [ "$thisOS" = "HP-UX" ] && newPath=$CANDLEHOME/roma/hp11
  [ "$thisOS" = "SunOS" ] && newPath=$CANDLEHOME/roma/sol26

  # If the new path already exists as a file, rename it
  [ -f $newPath ] && mv $newPath ${newPath}__RenamedFile

  # If the old path matches the new one, we're done
  [ "$oldPath" = "newPath" ]  && return

  # Rename any (known) old path to the new one
  [ "$oldArch" = "aix4" ]  && mv $oldPath $newPath
  [ "$oldArch" = "aix43" ] && mv $oldPath $newPath
  [ "$oldArch" = "hp10" ]  && mv $oldPath $newPath
  [ "$oldArch" = "hp102" ] && mv $oldPath $newPath
  [ "$oldArch" = "sol25" ]  && mv $oldPath $newPath
  [ "$oldArch" = "sol273" ] && mv $oldPath $newPath

  # Reset the tag file to the new name
  find $newPath -name ldap -print|head -1 > $RegBackup/Pre_CT99_Roma
}

# Display the license text in command-line mode

shoPrequis()
{
#$NLS-E$ "\n    Before installing IBM Tivoli Monitoring agents, you must"
#$NLS-E$ "install at least one IBM Tivoli Enterprise Monitoring Server.  You"
#$NLS-E$ "will need the host name or IP address and port number for the"
#$NLS-E$ "monitoring server to configure any agents.\n"
echo
nls_replace 'KCI1061I'  
nls_replace 'KCI1062I'  
echo
sleep 5 
}

shoLicense()
{
  which nroff  2> /dev/null > /dev/null  # See if nroff is available
  if [ $? = 0 ]                          #  we just do "more" if it's not
  then
    nroff $license | more -s
    print ""
  else
    more -s $license
  fi
  print " "
}

getVFNames()
{
  typeset -i i=0
  typeset arch fullName name pc verName

  ls $CANDLEHOME/registry/*.ver > /dev/null 2>&1
  [ $? -eq 0 ] || return  # Nothing to process.

  for name in $(ls $CANDLEHOME/registry/*.ver)
  do
    verName=${name##*/}  # Remove the pathname.
    pc=$(print $verName | cut -c1-2 2> /dev/null)   # Get the product code.
    [[ $pc = @(cz|or|ox|oy|ul|um|ux) ]] || continue   # Only a few products need special permissions.

    arch=$(print $verName | cut -c3- 2> /dev/null)  # Determine the bin arch.
    [[ $arch = @(aix|hp|sol)* ]] || continue  # Skip CMS data pieces.

    vfNames[i]=$verName
    i=i+1
  done

  procNum=${#vfNames[*]}
}

# check if iconv exists in the system 
checkIconv()
{
  iconv_path="$(whence iconv 2>/dev/null)"
  if [ -z "$iconv_path" ]
  then
    # iconv does not exist in the system.
    # This message should not be globalised.
    print "************************* WARNING *************************"
    print "The program iconv is not available and should be installed."
    print "************************* WARNING *************************"
  fi
}

###################################################################
#                          Main                                   #
###################################################################
#set -x

bindir=`pwd`/$(dirname $0)
[ "$(print $0 | grep '\./')" = "" ] && [ "$(print $0 | grep '^/.*')" = "" ] && [ `pwd` = '/' ] && bindir=`pwd`$(dirname $0)
[ "$(print $0 | grep '^/.*')" != "" ] && bindir=$(dirname $0)

 

if [ -d $bindir/unix ] 
then
nls_replace_dir=$bindir/unix/nls
else
nls_replace_dir=$bindir
fi
export PATH=$nls_replace_dir:$PATH

export PATH=/usr/bin:$PATH
UsrCmd="$0 $*"
PROGNAME=$(basename $0)
PROGDIR=$(dirname $0)

cd "$PROGDIR"

typeset -i i=1 idx=0 j=0 kbAvail=0 kbReq=0 kbytes=0 numEle=0 numItems=0
typeset curJVF="" ext="" newJVF="" osn="" toJVF="" AWK="awk"
typeset hasCCC="" hasFixes=false hasReadmes=false hasRoma="" hasCASP="" hasLDAP="" hasCMS=""
typeset hadCCC="" hadRoma="" hadCASP="" hasLDAP=""
typeset parDir prodMode tarDir  # Used by CandleRemote.
typeset license="license.txt"
typeset fld23  fieldSep
typeset hostNameInRunInfo

typeset baseTok thisMach thisOS thisRec thisTok thisUser  # Variables used for the token file.

set -A mainMenu
set -A mainMenu2


CDNAME=oqv621a9
export CDNAME
AUTHKEY=5483a753
DEBUG_CON=""
SAFE_MODE=""
silentMode=""
PARM_FILE=""
CLI_OPTION="installProduct"
DEPLOY_MODE=""
SUSE_VERSION=""
ciTar=cienv.tar  # NOTE:  this file is not compressed.
ciVFile=cienv.ver
instCI=no instCIFix=no instJRE=no
instPkgs="ci*.tar jr*.tar jr*.ctp jr*.z* *.jar *.j0*"
oldJRE=jre1.1.6
reqDirs="JRE bin config doc download logs misc registry tables tmp xfer gskit keyfiles"
tables="archdsc.tbl imdprof.tbl imdver.tbl proddsc.tbl" 

# need to use nawk if it's available
type nawk >/dev/null 2>&1
[[ $? -eq 0 ]] && AWK=nawk

# check if iconv exists in the system 
checkIconv

while getopts :h:j:d:o:p:acqv opt
do
  case $opt in
    a) DEPLOY_MODE="-Ditm.deploy=true"
       ;;
    h) CANDLEHOME=$OPTARG
       CANDLEHOME=$(eval print $CANDLEHOME)  # Process ~ if it was entered.
       ;;
    j) JAVALOC=$OPTARG
       JAVALOC=$(eval print $JAVALOC)  # Process ~ if it was entered.
       ;;
    d) PROD_PATH=$OPTARG
       PROD_PATH=$(eval print $PROD_PATH)
	   nls_replace_dir=$PROD_PATH/unix/nls
       export TEXTDOMAINDIR=$nls_replace_dir/msg
	   export PATH=$nls_replace_dir:$PATH
	   ;;
    c) DEBUG_CON="-debugcon"
       ;;
    o) CLI_OPTION="installProduct"
       [ -n "$(print $OPTARG | grep -i "product" | grep -i "depot")" ] && CLI_OPTION="installProductToDepot"
       ;;
    p) PARM_FILE=$OPTARG
       export PARM_FILE
       silentMode="-t 5"
       ;;
    q) silentMode="-t 5"
       VERBOSE="yes" # by default, verbose in silent mode for deploy
       export VERBOSE
       ;;
    v) VERBOSE="yes"
       export VERBOSE
       ;;
    ?) Use_report
       ;;
    :) Use_report
       ;;
  esac
done
shift OPTIND-1
[ $# -eq 0 ] || Use_report

if [ -n "$DEPLOY_MODE" ]
then
	trap "true" 13 15  # Set trap.
	trap "cleanUp trap" 1 2 3  # Set trap.
else
	trap "cleanUp trap" 1 2 3 15  # Set trap.
fi

# In silent mode, make sure all information is known up front
if [ -n "$silentMode" ]
then
  #$NLS-E$ "ITM home directory must be specified in silent mode (-h)"
  [ -z "$CANDLEHOME" ] && Err_report fail "`nls_replace 'KCI1063E' -h`"
  #$NLS-E$ "Input parameter file must be specified in silent mode (-p)"
  [ -z "$PARM_FILE" ] && Err_report fail "`nls_replace 'KCI1064E' -p`"
  #$NLS-E$ "Valid input parameter file must be specified in silent mode (-p)"
  [ -r $PARM_FILE ] || Err_report fail "`nls_replace 'KCI1065E' -p`"
fi

welcome="INSTALL"
[[ "$AUTHKEY" = "__AUTHKEY__" ]] && welcome="UPGRADE"
print $welcome
grep "IBM TIVOLI MONITORING (\"ITM\")" ./non_ibm_license

# Just for cleanliness, clean up the plugin temp dir
rm -rf /tmp/plugin_tmp
#on HP-IA, the temporary directory is /var/tmp
if [ -d /var/tmp/plugin_tmp ]
then
	rm -rf /var/tmp/plugin_tmp > /dev/null 2>&1
fi
# Set the default for CANDLEHOME.

defaultCH=/opt/IBM/ITM

# Determine CANDLEHOME

while true
do
  repeat=true
  if [ -z "$CANDLEHOME" ]
  then
    CANDLEHOME=$defaultCH
	#$NLS-E$ "\nEnter the name of the IBM Tivoli Monitoring directory"
    echo
	nls_replace 'KCI1066I'
	#$NLS-E$ "[ default = $CANDLEHOME ]:  \c"
    print "`nls_replace 'KCI1067I' $CANDLEHOME` \c"
    read resp
    resp=$(eval print $resp)
    [ -n "$resp" ] && CANDLEHOME=$resp
  fi

  if [ ! -d "$CANDLEHOME" ]
  then # The directory $CANDLEHOME does not exist
    # Silent mode defaults to "yes" to create a new CandleHome
    if [ -n "$silentMode" ]
    then  
      mkdir -p $CANDLEHOME > /dev/null 2>&1
      chmod a-s $CANDLEHOME > /dev/null 2>&1
      created=true
      repeat=true
    else
      if [ "$(print $CANDLEHOME | wc -w)" -ne "1" ]
      then
	    #$NLS-E$ "\n\"$CANDLEHOME\"  - blanks are not permitted in a directory name."
        echo
		nls_replace 'KCI1068I' \"$CANDLEHOME\"
	created=false
	CANDLEHOME=""
      else
	    #$NLS-E$ "\n\"$CANDLEHOME\" does not exist"
        echo
		nls_replace 'KCI1069I' \"$CANDLEHOME\"
		#$NLS-E$ "Try to create it [ y or n; \"y\" is default ]?  \c"
        print "`nls_replace 'KCI1070I'` [ 1-`nls_replace 'KCI0197I'`, 2-`nls_replace 'KCI0198I'`; \"1\" `nls_replace 'KCI0199I'` ]?  \c"
        read
        case $REPLY in
          n*|N*|2) exit 0
             ;;
          y*|Y*|1) 
                MKDIRMSG=$(mkdir -p $CANDLEHOME 2>&1|grep -i permission)
		if [ -n "$MKDIRMSG" ]
		then
		    if [ "$(uname)" = "AIX" ]
		    then
			MKDIRMSG=$(print $MKDIRMSG|grep "The file access permissions do not allow the specified action")
		    else
			MKDIRMSG=$(print $MKDIRMSG|grep "Permission denied")
		    fi
			#$NLS-E$ "You don't have permission to create $CANDLEHOME. \nPlease use another directory for IBM Tivoli Monitoring directory."
    		    [ -n "$MKDIRMSG" ] &&  print "`nls_replace 'KCI1071I' $CANDLEHOME` \n `nls_replace 'KCI1072I'`"
		    created=false
		    repeat=false
		else
                    chmod a-s $CANDLEHOME > /dev/null 2>&1
                    created=true
		fi
             ;;
#          thisisbogusresponsetoquestion) Err_report warn "only a tester would enter that!"
#	     created=false
#	     repeat=true
#             ;;
            *)
             if [ "$REPLY" = "" ] #default answer
             then
                MKDIRMSG=$(mkdir -p $CANDLEHOME 2>&1|grep -i permission)
		if [ -n "$MKDIRMSG" ]
		then
		    if [ "$(uname)" = "AIX" ]
		    then
			MKDIRMSG=$(print $MKDIRMSG|grep "The file access permissions do not allow the specified action")
		    else
			MKDIRMSG=$(print $MKDIRMSG|grep "Permission denied")
		    fi
			#$NLS-E$ "You don't have permission to create $CANDLEHOME. \nPlease use another directory for IBM Tivoli Monitoring directory."
    		    [ -n "$MKDIRMSG" ] && print "`nls_replace 'KCI1073I' $CANDLEHOME` \n `nls_replace 'KCI1074I'`"
		    created=false
		    repeat=false
		else
                    chmod a-s $CANDLEHOME > /dev/null 2>&1
                    created=true
		fi
             else
			   #$NLS-E$ "invalid response, please enter \"y\" or \"n\""
               Err_report warn "`nls_replace 'KCI1075I' \\"1\\" \\"2\\"`"
	     created=false
	     repeat=true
             fi
             ;;
        esac
      fi
    fi
    if [ "$repeat" = "false" ]
    then
	   #$NLS-E$ "please create \"$CANDLEHOME\" and rerun"
       [ -d "$CANDLEHOME" ] || Err_report fail "`nls_replace 'KCI1076E' \\"$CANDLEHOME\\"`"
	   #$NLS-E$ "created ITM home directory \"$CANDLEHOME\""
       Err_report info "`nls_replace 'KCI1077I' \\"$CANDLEHOME\\"`"
    fi
  else # The directory $CANDLEHOME exists
    if [ "$created"  != "true" ]
    then
      [ -n "$silentMode" ] && break
	  #$NLS-E$ "\nITM home directory \"$CANDLEHOME\" already exists."
      print 
	  nls_replace 'KCI1078I' \"$CANDLEHOME\"
	  #$NLS-E$ "OK to use it [ y or n; \"y\" is default ]?  \c"
      print "`nls_replace 'KCI1079I'` [ 1-`nls_replace 'KCI0197I'`, 2-`nls_replace 'KCI0198I'`; \"1\" `nls_replace 'KCI0199I'` ]?  \c"
      read
      case $REPLY in
        n*|N*|2) CANDLEHOME=  # Unset CANDLEHOME, and try again.
               ;;
            *) break  # It's safe to use.
               ;;
      esac
    else
      break  # It's safe to use.
    fi
  fi
done

[[ $CANDLEHOME = @(.|./*) ]] && CANDLEHOME=$(pwd)/$CANDLEHOME  # Provide a full path if "." was entered.
#$NLS-E$ "cannot write to \"$CANDLEHOME\""
[ -w "$CANDLEHOME" ] || Err_report fail "`nls_replace 'KCI1080E' \\"$CANDLEHOME\\"`"

if [ $(print "$CANDLEHOME" | wc -w) -ne 1 ]
then
  #$NLS-E$ "Blanks are not permitted in CANDLEHOME"
  Err_report fail "`nls_replace 'KCI0682E' CANDLEHOME`"
fi

# @10 - ensure that CANDLEHOME is a full pathname.

typeset curDir=$(pwd)
cd $CANDLEHOME > /dev/null 2>&1
#$NLS-E$ "could not determine the full pathname of \"$CANDLEHOME\""
[ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1081E' \\"$CANDLEHOME\\"`"
CANDLEHOME=$(pwd)
cd $curDir > /dev/null 2>&1  # Since this is a retrofit, we'll return to where we started.
#$NLS-E$ "could not change to directory \"$curDir\""
[ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1082E' \\"$curDir\\"`"

# End @10

# See if CANDLEHOME is a soft link.  If so, use the real directory name.

if [ -L $CANDLEHOME ]
then
  set -A linkRec $(ls -l $CANDLEHOME)
  numEle=${#linkRec[*]}
  #$NLS-E$ "could not resolve the link for \"$CANDLEHOME\""
  [ numEle -gt 0 ] || Err_report fail "`nls_replace 'KCI1083E' \\"$CANDLEHOME\\"`"
  CANDLEHOME=${linkRec[numEle-1]}
fi

export CANDLEHOME 
export cArch
export newRegPath


#This is in case we overinstall a JRE.
chmod -R 755 $CANDLEHOME/JRE > /dev/null 2>&1

PROD_PATH=${PROD_PATH:-$(pwd)}  # e.g. /buildi/99r1f2/image
[[ $PROD_PATH = @(.|./*) ]] && PROD_PATH=$(pwd)/$PROD_PATH  # Provide a full path if "." was entered.
#$NLS-E$ "\"$PROD_PATH\" is not a directory"
[ -d $PROD_PATH ] || Err_report fail "`nls_replace 'KCI1084E' \\"$PROD_PATH\\"`"
#$NLS-E$ "cannot read \"$PROD_PATH\""
[ -r $PROD_PATH ] || Err_report fail "`nls_replace 'KCI1085E' \\"$PROD_PATH\\"`"

# Set the package location.  The packages could be in a local directory (if downloaded from the Internet) or
# in the "unix" subdirectory of a CD file system.

PKGLOC=""

for pkg in $instPkgs
do
  if [ -f $PROD_PATH/$pkg ]  # Packages found in a local directory.
  then
    PKGLOC=$PROD_PATH
    break
  fi
done

# If no packages were found in a local directory, then they must be on a CD where they will be stored
# in the "unix" subdirectory.
if [ -z "$PKGLOC" ]
then
  tmp=$PROD_PATH/unix
  #$NLS-E$ "\"$tmp\" is not a directory"
  [ -d $tmp ] || Err_report fail "`nls_replace 'KCI1086E' \\"$tmp\\"`"
  #$NLS-E$ "cannot read \"$tmp\""
  [ -r $tmp ] || Err_report fail "`nls_replace 'KCI1087E' \\"$tmp\\"`"
  for pkgs in $instPkgs
  do
    for pkg in $(ls $tmp/$pkgs 2>/dev/null)
    do
      if [ -f $pkg ]  # Packages found on the CD.
      then
        PKGLOC=$tmp
        break
      fi
    done
  done
fi

#$NLS-E$ "could not find any product packages under directory \"$PROD_PATH\""
[ -n "$PKGLOC" ] || Err_report fail "`nls_replace 'KCI1088E' \\"$PROD_PATH\\"`"

# @10 - removed the following restriction.
#[ "$CANDLEHOME" != "$PKGLOC" ] || Err_report fail "product path should not be set to CANDLEHOME - \"$CANDLEHOME\""

# START - determine the variables needed by CandleRemote.

# Determine the location of the base installation script(s), *install.sh.  This will be either the $PKGLOC
# directory or the parent directory of $PKGLOC.

prodMode=""
tarDir=""

if [[ -f $PKGLOC/install.sh || -f $PKGLOC/cinstall.sh || -f $PKGLOC/ninstall.sh ]]
then
  tarDir=$PKGLOC  # Execute the tar command at the location of *install.sh.
  prodMode="eDelivery"  # The quotes are just for readability.
else
  parDir=$(dirname $PKGLOC)
  if [[ -f $parDir/install.sh || -f $parDir/cinstall.sh || -f $parDir/ninstall.sh ]]
  then
    tarDir=$parDir
    prodMode="newCD"  # Just a guess for now.  See following code.
  fi
fi

#$NLS-E$ "could not locate the base installation script"
[ -n "$prodMode" ] || Err_report fail "`nls_replace 'KCI1089E'`"

# Determine where the .ver files are located.  For "eDelivery," they are always inside the .jar files.

if [ "$prodMode" = "newCD" ]
then
  [ -d $PKGLOC/registry ] && prodMode="oldCD"
fi

# END - determine the variables needed by CandleRemote.

# Backup the registry so we can refer to previous version numbers during the
# install for possible data migration purposes.
# Non-compliant installs like Roma(CT98) will just get a token file in the 
# backup area.
RegPath=$CANDLEHOME/registry
RegBackup=$CANDLEHOME/old_registry
typeset LDAPVer=""
[ -d $RegBackup ] || mkdir $RegBackup

# Check for a pre-CT99 roma.  /roma will exist and ideally /registry
# will not.  However, someone may have aborted an install, so we look
# in the registry for some common Roma ver files, and if there are none
# then we have a pre-CT99 roma for sure, and we create a token file.

# If we do find the common Roma ver files, we clean out the backup registry
# in preparation for copying the ver files.  This also deletes any token file. 
typeset thisOS=$(uname -s)
[ "$thisOS" = "AIX" ] && os="aix"

if [ "$thisOS" = "HP-UX" ]
then
os=hp
[ "$(uname -m)" = "ia64" ] && os=hpi
fi

[ "$thisOS" = "SunOS" ] && os="sol"
[ "$thisOS" = "Linux" ] && os="l"

RomaPath=$(find $CANDLEHOME -name ldap -print | grep "roma/$os" | head -1)
if [ -n "$RomaPath" ]
then
  xx=$(ls $RegPath/bx${os}*.ver 2>/dev/null)
  xx=${xx}$(ls $RegPath/xm${os}*.ver 2>/dev/null)
  xx=${xx}$(ls $RegPath/xc${os}*.ver 2>/dev/null)
  xx=${xx}$(ls $RegPath/xs${os}*.ver 2>/dev/null)
  if [ -z "$xx" ] 
  then
    print $RomaPath > $RegBackup/Pre_CT99_Roma
    chmod 755 $RegBackup/Pre_CT99_Roma > /dev/null 2>&1
    LDAPVer="2.10"
  else	
    # clean out the backup registry
    rm -f $RegBackup/* > /dev/null 2>&1

    # Determine the previous version of LDAP installed (if any)
    ver=$(grep "ver =" $RegPath/xs${os}*.ver 2>/dev/null|head -1|cut -d" " -f3)
    [ -n "$ver" ] && LDAPVer=$(print $ver|cut -c 1).$(print $ver|cut -c 2-3)
  fi
fi

[ -d $RegPath ] && cp $RegPath/*.ver $RegBackup > /dev/null 2>&1

# Copying the mo directory and nls_replace file
cpMo

# Create the CANDLEHOME directories.

cd $CANDLEHOME > /dev/null 2>&1
#$NLS-E$ "could not cd to \"$CANDLEHOME\" directory"
[ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1090E' \\"$CANDLEHOME\\"`"

for dir in $reqDirs
do
  [ -d $dir ] || mkdir $dir > /dev/null 2>&1
  #$NLS-E$ "could not create directory \"$CANDLEHOME/$dir\""
  [ -d $dir ] || Err_report fail "`nls_replace 'KCI1091E' \\"$CANDLEHOME/$dir\\"`"
  [ -w $dir ] || chmod 755 $dir > /dev/null 2>&1
  #$NLS-E$ "could not add write access to directory \"$CANDLEHOME/$dir\""
  [ -w $dir ] || Err_report fail "`nls_replace 'KCI1092E' \\"$CANDLEHOME/$dir\\"`"
done

# The name of the docs directory has been changed to doc for consistency with NT.

if [ -d $CANDLEHOME/docs ] 
then
# Skip the error handling since an empty docs dir will result in an error.
  mv $CANDLEHOME/docs/* $CANDLEHOME/doc/ > /dev/null 2>&1
  rmdir $CANDLEHOME/docs > /dev/null 2>&1
fi

export CANDLETMP=$CANDLEHOME/tmp
curRegPath=$CANDLEHOME/registry
refVFile=$CANDLEHOME/registry/citnt.ver

# LL - start token file stuff.

baseTok=$CANDLETMP/candle_install_

thisOS=$(uname -a | cut -d" " -f1)  # thisOS -> AIX
#

thisUser=$(whoami)

# tar file option for unix and root use oxf. defect 12436
# set flag to do chown and chmod for Linux.  defect 83100
tarOpt=xf
chownRoot=n
if [[ "$thisUser" = "root" ]]
then
  if [[ "$thisOS" != "Linux" ]]
  then
    tarOpt=oxf
  else
    chownRoot=y
  fi
fi

# 17037 if we are root, we can cleanup unused modules and libs
[[ "$thisUser" = "root" &&  "$thisOS" = "AIX" ]] && slibclean

# Create the token file.

thisMach=$(uname -a | cut -d" " -f2)  # thisMach -> vulcan
thisTok=$baseTok${thisMach}_$$
touch $thisTok > /dev/null 2>&1
#$NLS-E$ "could not create token file"
[ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1093E'`"

# Build the description record, and add it to the token file.  This record will look like: 
# "AIX vulcan billy 17440 Friday Jun 08 14:21 2001 |159|".  The number between pipes (|)
# is the day of the year the file was created.

thisRec="$thisOS $thisMach $thisUser $$ $(date +"%A %B %d %H:%M %Y |%j|")"
print "$thisRec" > $thisTok

# Delete old token files, and warn if there is another install running in this <candlehome>.

procTokFiles 

# LL - end token file stuff.

checkProcesses  # LL - look for running agents/CMS.

cpRMFile  # Copy/rename the readme file.

hasCCC=""
hasRoma=""
hasCMS=""
#shoPrequis
#$NLS-E$ "searching for product families; please wait"
Err_report info "`nls_replace 'KCI1094I'`"
findFamilies  # Determine what product families are available for installation.

# RQ (Candle Application Services Pac) is not allowed to install over Roma
# but is allowed to install over RQ (which has Roma components)
if [ -n "$hasCASP" ]
then
  #$NLS-E$ "this product does not install over eBP"
  [[ -z "$hadCASP" && -n "$hadRoma" ]] && Err_report fail "`nls_replace 'KCI1095E' eBP`"
fi

# If packages are available for more than one product family, ask the user to select a family.

instFam=""
#$NLS-E$ "Exit install."
exInst="`nls_replace 'KCI1096I'`"

if [[ -n "$hasCCC" && -n "$hasRoma" ]]
then
  #$NLS-E$ "Install Candle Commmand Center products."
  cccP="`nls_replace 'KCI1097I'`"
  #$NLS-E$ "Install Roma products."
  romaP="`nls_replace 'KCI1098I'`"

  #$NLS-E$ "\nSelect one of the following:  \n"
  echo
  nls_replace 'KCI1099I'
  echo
  #$NLS-E$ "Please enter a valid number:  "
  PS3="`nls_replace 'KCI1100I'`"
  select num in "$cccP" "$romaP" "$exInst"
  do
    case $num in
      $cccP)
        instFam="-ccc"
        break ;;
      $romaP)
        instFam="-roma"
        break ;;
      $exInst)
        cleanUp 0 ;;
    esac
  done
  echo
fi

# Determine what family to install if packages exist for only one family.

if [ -z "$instFam" ]
then
  if [ -n "$hasCCC" ]
  then 
    instFam="-ccc"
  elif [ -n "$hasRoma" ]
  then
    instFam="-roma"
  fi
fi

# IBM/Tivoli or Candle presentation (use Candle whenever a CMS is in the packaging)
tivoli="-tivoli"
# EJF (#6333) remove this line to allow tivoli to remain set
#[ -n "$hasCMS" ] && tivoli=""

# Ensure that product packages exist.  The check against $PKGLOC is needed since findFamilies() excludes
# ax, ci and jr packages.

#$NLS-E$ "could not find any product packages under directory \"$PROD_PATH\""
[[ -n "$instFam" && -n "$PKGLOC" ]] || Err_report fail "`nls_replace 'KCI1101E' \\"$PROD_PATH\\"`"

# See if any fixpacks exist in $PKGLOC.

hasFixes=false
lookForFixPacks  # If fixpacks are available, hasFixes=true.
#print ... hasFixes = $hasFixes

# See if there are any readme's available for viewing.

hasReadmes=false
ls $CANDLEHOME/doc/readme*.txt > /dev/null 2>&1
[ $? -eq 0 ] && hasReadmes=true

# For eBP over-installs, warn them about shutting down running LDAPs
[[ "$instFam" = "-roma" && -n "$LDAPVer" && -n "$hasLDAP" ]] && BspWarn

# All menu items.

#$NLS-E$ "Install products or maintenance via GUI."
gui="`nls_replace 'KCI1102I'`"
#$NLS-E$ "Install products to the local host."
cmdLn="`nls_replace 'KCI1103I'`"
#$NLS-E$ "Install maintenance via command line."
cmdLnM="`nls_replace 'KCI1104I'`"
#$NLS-E$ "Create remote packages via GUI."
guiRP="`nls_replace 'KCI1105I'`"
#$NLS-E$ "Create remote packages via command line."
cmdLnRP="`nls_replace 'KCI1106I'`"
#$NLS-E$ "View readme files."
vRM="`nls_replace 'KCI1107I'`"
#$NLS-E$ "Install products to depot for remote deployment (requires TEMS)."
cmdLnDepot="`nls_replace 'KCI1108I'`"
#$NLS-E$ "Install products to depot via GUI."
guiDepot="`nls_replace 'KCI1109I'`"
#$NLS-E$ "Install product support."
supportCLI="`nls_replace 'KCI1201I'`"

# Build an accurate list of menu items.

if [ "$hasFixes" = "false" ]
then
  #$NLS-E$ "Install products via GUI."
  gui="`nls_replace 'KCI1110I'`"
fi

# EJF (#12006) remove GUI install option
#mainMenu[0]="$gui"
mainMenu[0]="$cmdLn"
mainMenu2[0]="Install products to the local host."
[ "$hasFixes" = "true" ] && mainMenu[${#mainMenu[*]}]="$cmdLnM"
[ "$hasFixes" = "true" ] && mainMenu2[${#mainMenu2[*]}]="Install maintenance via command line."
# Uncomment the next 2 lines to activate GUI remote package creation, feature 14459
#mainMenu[${#mainMenu[*]}]="$guiRP"
#mainMenu2[${#mainMenu2[*]}]="Create remote packages via GUI."  
# Uncomment the next 2 lines to activate command line remote package creation, feature 14459
#mainMenu[${#mainMenu[*]}]="$cmdLnRP"  
#mainMenu2[${#mainMenu2[*]}]="Create remote packages via command line."  

# Uncomment the next 2 lines to activate GUI depot option
# mainMenu[${#mainMenu[*]}]="$guiDepot"  
# mainMenu2[${#mainMenu2[*]}]="Install products to depot via GUI."  

#
# d15022 abstract      DEV: Remove depot install choice from Exchange Unix installer
# d35743   (modifies this code to add hlv410 and vlv410) 
#
# depot install is not valid for the following cds from the
# install.sh shell script : 
#
# m3v410     IBM Tivoli OMEGAMON Data Files for z/OS
# q5v610     ITM for Microsoft Cluster Servers
# exv610     ITM for Messaging and Collaboration
# 3zv610     ITM for Windows Active Directory (ADO)
# vwv525     ITM for NetView on z/OS 5.2.5
# hlv410     OMEGAMON z/OS Management Console  
# vlv410     OMEGAMON XE for z/VM and Linux
#
#
# use the 'tacmd addBundles' CLI to add components from these 
# cds to a depot
if [[ "$CDNAME" != @(m3v4*|q5v*|3zv*|vwv*|hlv*|vlv*) ]]; then
    if [[ "$(uname -s)" != "NONSTOP_KERNEL" ]]
    then
    	mainMenu[${#mainMenu[*]}]="$cmdLnDepot"  
		mainMenu2[${#mainMenu2[*]}]="Install products to depot for remote deployment (requires TEMS)."  
    fi
fi
[ "$hasReadmes" = "true" ] && mainMenu[${#mainMenu[*]}]="$vRM"
[ "$hasReadmes" = "true" ] && mainMenu2[${#mainMenu2[*]}]="View readme files."
mainMenu[${#mainMenu[*]}]="$supportCLI"
mainMenu2[${#mainMenu2[*]}]="Install product support"
mainMenu[${#mainMenu[*]}]="$exInst"  
mainMenu2[${#mainMenu2[*]}]="Exit install."  
numItems=${#mainMenu[*]}  # The number of elements in the array.

# Generate a "select" menu, and ask the user to select an install mode.  It's too early in the script 
# to actually invoke the Java installation routines.  Howevever, displaying this menu later in the script 
# would make the install awkward for the user.

while [ anything ]
do
  guiRep=no cmdLnRep=no cmdLnMRep=no guiRPRep=no cmdLnRPRep=no vRMRep=no cmdLnDepotRep=no guiDepotRep=no supportCLIRep=no

  # Force the user to make a selection, unless we're in silent mode.
  if [ -n "$silentMode" ]
  then
    [ "$CLI_OPTION" = "installProduct" ] && cmdLnRep=yes
    [ "$CLI_OPTION" = "installProductToDepot" ] && cmdLnDepotRep=yes
	#$NLS-E$ "installing products via silent mode"
    Err_report info "`nls_replace 'KCI1111I'`"
  else
    i=1 j=0
	#$NLS-E$ "\nSelect one of the following:  \n"
    echo
	nls_replace 'KCI1112I'
	echo
    while [ j -lt numItems ]
    do
      print "$i) ${mainMenu[j]}"
      i=i+1
      j=j+1
    done
  
    while [ anything ]
    do
	  #$NLS-E$ "\nPlease enter a valid number:  \c"
      print "\n`nls_replace 'KCI1113I'`  \c"
      read 
      [[ $REPLY = +([0-9]) ]] || continue  # Make sure it's a number.
      [[ "$REPLY" -gt 0 && "$REPLY" -le numItems ]] && break  # It's a valid number. 
    done
    idx=$REPLY 

    # Determine what the user wants to do.
  
# EJF (#12006) remove GUI install option
#    [ idx -eq 1 ] && guiRep=yes  # The first item is always GUI mode.
    [ idx -eq numItems ] && cleanUp 4  # The last item is always exit.
  
# EJF (#12006) remove GUI install option (changed "idx -gt 1" to "idx -gt 0")
    if [ idx -gt 0 -a idx -lt numItems ]  # Skip the first and last items since they're known.
    then
      idx=idx-1  # Set the real array index.
      sel=${mainMenu2[$idx]}
#      print ... sel = $sel
      print "$sel" | grep "product" | grep -v "depot" > /dev/null 2>&1  # Install products via command line.
      [ $? -eq 0 ] && cmdLnRep=yes
      print "$sel" | grep "maintenance" > /dev/null 2>&1  # Install maintenance via command line.
      [ $? -eq 0 ] && cmdLnMRep=yes
      print "$sel" | grep "remote" 2> /dev/null | grep "GUI" > /dev/null 2>&1  # Create remote packages via GUI.
      [ $? -eq 0 ] && guiRPRep=yes
      print "$sel" | grep "remote" 2> /dev/null | grep "command" > /dev/null 2>&1  # Create remote packages via command line.
      [ $? -eq 0 ] && cmdLnRPRep=yes
      print "$sel" | grep "readme" > /dev/null 2>&1  # View readme files.
      [ $? -eq 0 ] && vRMRep=yes
      print "$sel" | grep "depot" | grep "GUI" > /dev/null 2>&1  # Install products via GUI to agent depot
      [ $? -eq 0 ] && guiDepotRep=yes
      print "$sel" | grep "depot" > /dev/null 2>&1  # Install products via command line to agent depot
      [ $? -eq 0 ] && cmdLnDepotRep=yes
      print "$sel" | grep "support" > /dev/null 2>&1  # Install product support
      [ $? -eq 0 ] && supportCLIRep=yes
    fi
  fi
  
  if [ "$vRMRep" = "yes" ]
  then
    typeset rmIdx=""
    typeset -i maxVal=0
    set -A rmDescs
        
    execRMDialog  # Execute the readme dialog.
        
    # Convert the description selected in the menu into a file name and then display the readme.

    if [[ -n "$rmIdx" && "$rmIdx" -lt maxVal ]]  # It must be less than maxVal since maxVal is "exit."
    then  
      desc="${rmDescs[$rmIdx]}"  # Get the description.
      desc=$(print $desc 2> /dev/null | sed "s/ /_/g")  # Add the underscores.
      desc="readme_$desc.txt"  # Complete the file name.
      if [ -f $CANDLEHOME/doc/$desc ]
      then
        more $CANDLEHOME/doc/$desc
      else
	    #$NLS-E$ "could not find readme \"$CANDLEHOME/doc/$desc\""
        Err_report warn "`nls_replace 'KCI1114I' \\"$CANDLEHOME/doc/$desc\\"`"
      fi
    fi
  else
    break
  fi
done
echo

# EJF - per defect 9191, if adding to depot ensure that a TEMS is installed
if [[ "$cmdLnDepotRep" = "yes" || "$guiDepotRep" = "yes" ]] && [[ ! -f $CANDLEHOME/config/.ConfigData/kmsenv ]]
then 
   #$NLS-E$ "No Tivoli Enterprise Monitoring Server (TEMS) is installed under $CANDLEHOME"
   Err_report fail "`nls_replace 'KCI1115E' $CANDLEHOME`"
fi

# Determine where the .ver files are located for new packages.  If there is a "registry" subdirectory in 
# $PKGLOC, then look for the files in the $PKGLOC/registry directory.  .ver files in this directory can
# be read directly.  If there is no "registry" directory under $PKGLOC, the .ver files are contained 
# within the product packages, and these files must be extracted from the packages and placed in $CANDLETMP. 
# We cannot extract to $PKGLOC since this directory may be on a read-only CD.

hasRegDir=no

if [ -d $PKGLOC/registry ]
then
  newRegPath=$PKGLOC/registry
  hasRegDir=yes
else
  newRegPath=$CANDLETMP
  hasRegDir=no
fi

# See if there is a installer (i.e. $ciTar) package in $PKGLOC.  If so, then we need to version and possibly
# update the current installer (if we're installing into an existing CANDLEHOME).

instCI=no
if [ -f $PKGLOC/$ciTar ]
then
  #$NLS-E$ Initializing ...
  nls_replace 'KCI1116I'
  #$NLS-E$ "processing base CI package"
  Err_report info "`nls_replace 'KCI1117I'`"
  
  #$NLS-E$ "cannot read package \"$PKGLOC/$ciTar\""
  [ -r $PKGLOC/$ciTar ] || Err_report fail "`nls_replace 'KCI1118E' \\"$PKGLOC/$ciTar\\"`"
  
  if [ "$hasRegDir" = "no" ] 
  then
    unloadTmpFile $ciVFile $PKGLOC/$ciTar  # Extract the .ver file.
  fi
  
  #$NLS-E$ "cannot read file \"$newRegPath/$ciVFile\""
  [ -r "$newRegPath/$ciVFile" ] || Err_report fail "`nls_replace 'KCI1119E' \\"$newRegPath/$ciVFile\\"`"
  
  # See if our own CI classes are installed.

  if [ -r "$curRegPath/$ciVFile" ]  # Our classes are installed.
  then
    checkLevel $ciVFile  # Check if the "to be installed" CI classes are newer than the ones in CANDLEHOME.
    [ "$levelStrg" = "Same" ] && instCI=Same  # levelStrg is set by function checkLevel().
    [ "$levelStrg" = "Newer" ] && instCI=yes  # levelStrg is set by function checkLevel().
  else  # Our classes are not installed.
    instCI=yes
  fi
fi

# Install the installer.

export saveLang=$LANG
savePath=$PATH
  
# fix for defect 38078
if [ "$instCI" = "Same" ]
then
aFile=tmp/archdsc.tbl
tar -$tarOpt $PKGLOC/cienv.tar $aFile > /dev/null 2>&1
# fix for defect 61259
tar -$tarOpt $PKGLOC/cienv.tar tmp/jr*.ver > /dev/null 2>&1
fi

kbytes=0
if [ "$instCI" = "yes" ]
then
  # See if there is enough room to install.

  export LANG=C
  kbytes=$(grep "^size[A-Z,a-z]* *=" $newRegPath/$ciVFile | cut -d"=" -f2 2> /dev/null)
  export LANG=$saveLang
  #$NLS-E$ "could not determine the size of the base CI package"
  [ kbytes -gt 0 ] || Err_report fail "`nls_replace 'KCI1120E'`"
  
  if [[ "$(uname -s)" = "NONSTOP_KERNEL" ]]	# Tandem df doesn't work as we expect, hard code now.
  then
      kbAvail=100000
  else
      checkDiskSpace $CANDLEHOME $kbytes  # install.sh exits if space is not available. 
  fi
  
  # Process any elements.
  
  eleNames="" i=1 numEle=0
  
  export LANG=C
  numEle=$(grep "^numElements *=" $newRegPath/$ciVFile 2> /dev/null | cut -d"=" -f2)
  export LANG=$saveLang
  if [[ $? -eq 0 && numEle -gt 1 ]]  # The installer is contained in multiple packages.
  then
    #$NLS-E$ "processing element CI packages"
    Err_report info "`nls_replace 'KCI1121I'`"
    while [ i -lt numEle ]
    do
      eleNames="$eleNames cienv$i"  # For CI, element names begin with 1.
      i=i+1
    done
    checkCIElements $eleNames
  fi
  
  #$NLS-E$ "unloading CI package(s)"
  Err_report info "`nls_replace 'KCI1122I'`"
  for pkg in $ciTar $eleNames
  do
    bName=${pkg%.*}  # Remove any extension.
    unTarPkg $PKGLOC/$bName.tar 
  done
    
  # Copy the .ver file for the base package, and add write access.
    
  cp $newRegPath/$ciVFile $curRegPath/ > /dev/null 2>&1
  #$NLS-E$ "could not copy version file \"$ciVFile\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1123E' \\"$ciVFile\\"`"
  chmod 755 $curRegPath/$ciVFile > /dev/null 2>&1
  #$NLS-E$ "could not change access permissions on \"$ciVFile\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1124E' \\"$ciVFile\\"`" 

  #46553 cpInstProg removed
  #cpInstProg $ciTar  # Copy install.sh to CANDLEHOME/bin.
fi

# Determine if there is an installer (ci) fixpack that needs to be applied.

typeset allVFiles=""

ciFixPacks=$(ls $PKGLOC/ciux*.t* 2> /dev/null)
if [ -n "$ciFixPacks" ]
then
  #$NLS-E$ "processing CI fixpacks"
  Err_report info "`nls_replace 'KCI1125I'`"
  
  for fp in $ciFixPacks
  do
    #$NLS-E$ "cannot read package \"$fp\""
    [ -r $fp ] || Err_report fail "`nls_replace 'KCI1126E' \\"$fp\\"`"
      
    # Determine the name of the .ver file.  If the fixpack name is ciuxdddd.t00 where d is a digit,
    # the .ver file will be named ciuxdddd.ver.  If the fixpack name is ciuxdddd.t01, ciuxdddd.t02,
    # etc, the .ver file will be named ciuxddddt01.ver, ciuxddddt02.ver, etc.
    
    vFile=${fp##*/}   # Remove the pathname.
    ext=${vFile##*.}  # Get the extension; ext -> t00, t01, t02, ...
    if [ "$ext" = "t00" ]
    then
      vFile=${vFile%.*}.ver      # vFile -> ciux6110.ver
    else
      vFile=${vFile%.*}$ext.ver  # vFile -> ciux6110t01.ver
    fi
    
    if [ "$hasRegDir" = "no" ]  # Unload the ciux*.ver files if there is no registry directory.
    then
      unloadTmpFile $vFile $fp  # Extract the .ver file.
    fi
	#$NLS-E$ "cannot read file \"$newRegPath/$vFile\""
    [ -r "$newRegPath/$vFile" ] || Err_report fail "`nls_replace 'KCI1127E' \\"$newRegPath/$vFile\\"`"
    
    [ "$ext" = "t00" ] && allVFiles="$allVFiles $vFile"  # Consider only the base package.
  done

  # Find the name of the .ver file for the latest ci fixpack.
  
  if [ -n "$allVFiles" ]
  then
    findLatest $allVFiles  # findLatest() will place the name of the .ver file in variable lateVFile. 
    ciLateVFile=$lateVFile  # Save the name for future processing.
    checkLevel $ciVFile $ciLateVFile  # See if the fixpack needs to be installed. 
    [ "$levelStrg" = "Newer" ] && instCIFix=yes
  fi 
fi

# Install a ci fixpack.

kbytes=0
if [ "$instCIFix" = "yes" ]
then
  # See if there is enough room.
  
  export LANG=C
  kbytes=$(grep "^size[A-Z]* *=" $newRegPath/$ciLateVFile | cut -d"=" -f2)
  export LANG=$saveLang
  #$NLS-E$ "could not determine the size of the CI fixpack"
  [ kbytes -gt 0 ] || Err_report fail "`nls_replace 'KCI1128E'`"

  if [[ "$(uname -s)" = "NONSTOP_KERNEL" ]]	# Tandem df doesn't work as we expect, hard code now.
  then
      kbAvail=100000
  else
      checkDiskSpace $CANDLEHOME $kbytes  # install.sh exits if space is not available. 
  fi
  
  
  # Process any elements.
  
  eleNames="" i=1 numEle=0
  typeset baseName=${ciLateVFile%.*}
  
  export LANG=C
  numEle=$(grep "^numElements *=" $newRegPath/$ciLateVFile 2> /dev/null | cut -d"=" -f2)
  export LANG=$saveLang
  if [[ $? -eq 0 && numEle -gt 1 ]]  # The fixpack is contained in multiple packages.
  then
    #$NLS-E$ "processing element CI fixpacks"
    Err_report info "`nls_replace 'KCI1129I'`"
    while [ i -lt numEle ]
    do
      [ i -le 9 ] && ext=t0$i || ext=t$i
      eleNames="$eleNames $baseName.$ext"  
      i=i+1
    done
    checkCIFixElements $baseName $eleNames
  fi
  
  #$NLS-E$ "installing CI fixpack \"$baseName\""
  Err_report info "`nls_replace 'KCI1130I' \\"$baseName\\"`"
  for pkg in $baseName.t00 $eleNames
  do
    unTarPkg $PKGLOC/$pkg 
  done
    
  # Preserve existing fixID records.  Adding the values to an array will remove the newline
  # character returned from the grep operation.
  
  export LANG=C
  set -A fixIDs $(grep "fixID" $curRegPath/$ciVFile | grep -v $baseName | cut -d"=" -f2 2> /dev/null)
  export LANG=$saveLang
  
  # Copy the base .ver file (while changing its name), and add write access.

  cp $newRegPath/$ciLateVFile $curRegPath/$ciVFile > /dev/null 2>&1
  #$NLS-E$ "could not copy version file \"$ciLateVFile\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1131E' \\"$ciLateVFile\\"`"
  chmod 755 $curRegPath/$ciVFile > /dev/null 2>&1
  #$NLS-E$ "could not change access permissions on \"$ciVFile\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1132E' \\"$ciVFile\\"`"
  
  # Add the fixpack names which have been installed to the end of the .ver file.
  
  print "" >> $curRegPath/$ciVFile 2> /dev/null
  for pkg in ${fixIDs[*]} $baseName
  do
    print "fixID = $pkg" >> $curRegPath/$ciVFile 2> /dev/null
  done
  
  #46553 cpInstProg removed
  #cpInstProg $baseName.t00  # Copy install.sh to CANDLEHOME/bin.
fi

# Copy the kcirunas.cfg file to CANDLEHOME/config if it does not already exist there.

RUNASFILE=kcirunas.cfg
RUNASIMG=""
RUNASCFG="$CANDLEHOME/config/$RUNASFILE"
[[ -z "$RUNASIMG" && -f "$PROGDIR/$RUNASFILE" ]] && RUNASIMG="$PROGDIR/$RUNASFILE"
[[ -z "$RUNASIMG" && -f "$PKGLOC/../$RUNASFILE" ]] && RUNASIMG="$PKGLOC/../$RUNASFILE"
[[ -z "$RUNASIMG" && -f "$PKGLOC/$RUNASFILE" ]] && RUNASIMG="$PKGLOC/$RUNASFILE"
#$NLS-E$ "cannot locate file \"$RUNASFILE\" - please try the install again"
[[ -z "$RUNASIMG" ]] && Err_report fail "`nls_replace 'KCI11072E' \\"$RUNASFILE\\"`"

if [[ ! -f "$RUNASCFG" ]]
then
  cp "$RUNASIMG" "$RUNASCFG"
  #$NLS-E$ "could not copy file \"$RUNASIMG\" to \\"$RUNASCFG\\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI11074E' \\"$RUNASIMG\\" \\"$RUNASCFG\\"`"
fi

# Locate the architecture description table. This table is needed to run dynarch.shl.

archTbl=archdsc.tbl
if [ -r $newRegPath/$archTbl ]  # Use the "new" table if there is one.
then
  archTbl=$newRegPath/$archTbl
else
  archTbl=$curRegPath/$archTbl
fi
#$NLS-E$ "cannot read file \"$archTbl\" - please try the install again"
[ -r $archTbl ] || Err_report fail "`nls_replace 'KCI1133E' \\"$archTbl\\"`"

# Display the license agreement after we've unpacked it
# Command-line modes need to display the license text first

# Which license agreement to display? (default is license.txt)
[ -n "$hasRoma" ]             && license="terms.agr"
[ "$instFam" = "-romaMQSEC" ] && license="mqterms.agr"
[ "$instFam" = "-pqedit" ] && license="terms.agr_MsgEdit"
export LANG=C
licName=$(print $license | tr 'a-z' 'A-Z')
export LANG=$saveLang
# Get user agreement on licensing using LAP tool if its on CD, or Candle license if not
lapDisplayMode="none"

if [ -d "$PROD_PATH/unix/LAP" ]
then
  if [[ "$cmdLnRep" = "yes" || "$cmdLnMRep" = "yes" || "$cmdLnRPRep" = "yes" || "$cmdLnDepotRep" = "yes" ]]
  then
    lapDisplayMode="-text_only"
  else
    lapDisplayMode="-win_style 0"
  fi
else
  # If license file isn't there (maybe deleted), check /misc for a spare copy
  [ -r $license ]  || cp -p $CANDLEHOME/misc/.$license $license 2> /dev/null
  # also check the top level of the cd for the license file
  [ -r $license ]  || cp -p $PROD_PATH/$license $license 2> /dev/null
  
  # Get license agreement unless we're in silent mode
  if [ -z "$silentMode" ]
  then
    if [[ "$cmdLnRep" = "yes" || "$cmdLnMRep" = "yes" || "$cmdLnRPRep" = "yes" || "$cmdLnDepotRep" = "yes" ]]
    then
      while true		# license.txt gets option to postpone view @03
      do
        print " "
		#$NLS-E$ "Do you agree to the terms of the license in file $licName on the CD?"
        print "`nls_replace 'KCI1134I' $licName`"
		#$NLS-E$ "Enter Yes, No, or R to read the agreement now."
        print "1-`nls_replace 'KCI0197I'`, 2-`nls_replace 'KCI0198I'`, `nls_replace 'KCI1135I' 3`"
		#$NLS-E$ "(choosing \"No\" exits the installation process) (Y/N/R): \c"
        print "`nls_replace 'KCI1136I' \\"2\\"` (1/2/3): \c"
        read Response
        case "$Response" in
          n*|N*|2) exit 0
                 ;;
          r*|R*|3) shoLicense
                 ;;
          y*|Y*|1) break
                 ;;
        esac
      done
    fi
  fi
fi

# Determine the machine's architecture.

dynShl=$CANDLEHOME/bin/dynarch.shl
#$NLS-E$ "cannot execute \"$dynShl\""
[ -x $dynShl ] || Err_report fail "`nls_replace 'KCI1137E' \\"$dynShl\\"`"
. $dynShl $archTbl  # dynarch.shl will determine a value for cArch.
#$NLS-E$ "could not determine the machine's architecture"
[ -n "$cArch" ] || Err_report fail "`nls_replace 'KCI1138E'`"
#$NLS-E$ "computed architecture = \"$cArch\""
Err_report info "`nls_replace 'KCI1139I' \\"$cArch\\"`"

#$NLS-E$ "HP 10 is not a supported operating system"
[[ "$cArch" = "hp10" ]] && Err_report fail "`nls_replace 'KCI1140E'`"
#$NLS-E$ "HP 10.20 is not a supported operating system"
[[ "$cArch" = "hp102" ]] && Err_report fail "`nls_replace 'KCI1141E'`"

#
# f14583 abstract      Install support for TEPS on Intel SuSE9
#
# TEPS needs to differentiate between Red and SUSE linux
export LANG=C
if [[ -f /etc/SuSE-release ]]
then
   VERSION=`cat /etc/SuSE-release | grep 'VERSION' | sed  -e 's#[^0-9]##g'`
   SUSE_VERSION="-Dsuse_version=${VERSION}"
fi
export LANG=$saveLang

# Get the names of all JRE packages (products and fixpacks) in the product directory.

typeset jrPkgs=""

# Get a list of the JRE packages we have in the media
export LANG=C
jrPkgs=$(ls $PKGLOC/jr*.tar  $PKGLOC/jr*.ctp $PKGLOC/jr*.z* 2> /dev/null)
export LANG=$saveLang

jrPkgsNotInstalled=""

# If we have JRE packages, check if the ver file is already unloaded.
if [ -n "$jrPkgs" ]
then
  for jre in $jrPkgs
  do
    bName=${jre##*/}  # Remove the pathname.
    
    # Construct the name of the .ver file.
    
    ext=${bName##*.}  # ext -> tar, ctp, z00, z01, z02, ...
    if [[ "$ext" = "tar" || "$ext" = "ctp" || "$ext" = "z00" ]]
    then
      vFile=${bName%.*}.ver      # vFile -> jraix4.ver
    else
      vFile=${bName%.*}$ext.ver  # vFile -> jraix4z01.ver
    fi
  
    [[ ! -r $CANDLEHOME/tmp/$vFile ]] && jrPkgsNotInstalled="$jre $jrPkgsNotInstalled"
  done
fi
	
jrPkgs="$jrPkgsNotInstalled"

if [ -n "$jrPkgs" ]
then
  #$NLS-E$ "processing JRE packages"
  Err_report info "`nls_replace 'KCI1142I'`"
  for jre in $jrPkgs
  do
  	#
  	# if the jre does not have read permission and 
  	# this is not deploy mode exit
  	if [[ ! -r $jre && -z "$DEPLOY_MODE" ]]
  	then
	    #$NLS-E$ "cannot read package \"$jre\""
  		Err_report fail "`nls_replace 'KCI1143E' \\"$jre\\"`"
  	fi
     
    bName=${jre##*/}  # Remove the pathname.
    
    # Construct the name of the .ver file.
    
    ext=${bName##*.}  # ext -> tar, ctp, z00, z01, z02, ...
    if [[ "$ext" = "tar" || "$ext" = "ctp" || "$ext" = "z00" ]]
    then
      vFile=${bName%.*}.ver      # vFile -> jraix4.ver
    else
      vFile=${bName%.*}$ext.ver  # vFile -> jraix4z01.ver
    fi
    
    if [ "$hasRegDir" = "no" ]  # Unload the jr*.ver files if there is no registry directory.
    then
      unloadTmpFile $vFile $jre  # Extract the .ver file.
    fi
	#$NLS-E$ "cannot read file \"$newRegPath/$vFile\""
    [ -r "$newRegPath/$vFile" ] || Err_report fail "`nls_replace 'KCI1144E' \\"$newRegPath/$vFile\\"`"
      
  done
fi

# See if there is a JRE installed.

osn=${cArch%%[0-9]*}  # Get the name (e.g. aix) of the operating system.
#$NLS-E$ "About to check for installed JRE"
Err_report info "`nls_replace 'KCI1145I'`"
curJVF=$(grep -l "^runArch *= *$cArch$" $curRegPath/jr$osn*.ver 2> /dev/null)
if [ -z "$curJVF" ]  # Look for a "runArch = open" record.
then
  export LANG=C
  set -A ta $(grep -l "^runArch *= *open" $curRegPath/jr$osn*.ver 2> /dev/null)
  export LANG=$saveLang
  numEle=${#ta[*]}
  # There may be more than one .ver file with an "open" record, so use the latest .ver file.
  [ numEle -gt 0 ] && curJVF=${ta[numEle-1]}
  
	# 17901.1 - additional check for a 32-bit JRE
  if [ -z "$curJVF" ]  # Look for the 32-bit version if this is 64-bit
  then
    # get architecture bit (3 = 32 or 6 = 64)
    typeset -i len=0
    len=$(print $cArch|wc -c)
    len=$(($len-1))
    bitNum=$(print $cArch|cut -c$len)
    [ -z "$bitNum" ] && bitNum=3

    # if we're 64-bit
    if [ "$bitNum" = 6 ]
    then
	  #$NLS-E$ "64bit JRE not found looking for installed 32bit JRE"
      Err_report info "`nls_replace 'KCI1146I'`"
      newRunArch=$(print $cArch | sed 's/6$/3/g') # replace ending 6 with 3
      export LANG=C
	  set -A ta $(grep -l "^runArch *= *$newRunArch$" $curRegPath/jr$osn+([0-9]).ver 2> /dev/null)
      export LANG=$saveLang
	  numEle=${#ta[*]}
      # There may be more than one .ver file, so use the latest .ver file.
      [ numEle -gt 0 ] && curJVF=${ta[numEle-1]}
	  #$NLS-E$ "current JRE is \"$curJVF\""
      Err_report info "`nls_replace 'KCI1147I' \\"$curJVF\\"`"
    fi
  fi
fi
[ -n "$curJVF" ] && curJVF=${curJVF##*/}  # Remove the pathname.

# See if there is a new JRE to install.

export LANG=C
newJVF=$(grep -l "^runArch *= *$cArch$" $newRegPath/jr$osn+([0-9]).ver 2> /dev/null)  # Exclude *zxx .ver files.
export LANG=$saveLang
if [ -z "$newJVF" ]  # Look for a "runArch = open" record.
then
  export LANG=C
  set -A ta $(grep -l "^runArch *= *open" $newRegPath/jr$osn+([0-9]).ver 2> /dev/null)
  export LANG=$saveLang
  numEle=${#ta[*]}
  # There may be more than one .ver file with an "open" record, so use the latest .ver file.
  [ numEle -gt 0 ] && newJVF=${ta[numEle-1]}

  # 13526.1 - additional check for a 32-bit JRE
  if [ -z "$newJVF" ]  # Look for the 32-bit version if this is 64-bit
  then
    # get architecture bit (3 = 32 or 6 = 64)
    typeset -i len=0
    len=$(print $cArch|wc -c)
    len=$(($len-1))
    bitNum=$(print $cArch|cut -c$len)
    [ -z "$bitNum" ] && bitNum=3

    # if we're 64-bit
    if [ "$bitNum" = 6 ]
    then
      newRunArch=$(print $cArch | sed 's/6$/3/g') # replace ending 6 with 3
      export LANG=C
	  set -A ta $(grep -l "^runArch *= *$newRunArch$" $newRegPath/jr$osn+([0-9]).ver 2> /dev/null)
      export LANG=$saveLang
	  numEle=${#ta[*]}
      # There may be more than one .ver file, so use the latest .ver file.
      [ numEle -gt 0 ] && newJVF=${ta[numEle-1]}
    fi
  fi
fi

[ -n "$newJVF" ] && newJVF=${newJVF##*/}  # Remove the pathname.

# Determine if a JRE needs to be installed.

instJRE=no
#$NLS-E$ "This is not a supported platform."
[[ -z "$curJVF" && -z "$newJVF" ]] && Err_report fail "`nls_replace 'KCI1148E'`"

[[ -n "$curJVF" && -z "$newJVF" ]] && { instJRE=no; toJVF=$curJVF; }

[[ -z "$curJVF" && -n "$newJVF" ]] && { instJRE=yes; toJVF=$newJVF; }

if [[ -n "$curJVF" && -n "$newJVF" ]]
then
  # See if the JRE in the product directory is newer than the one in CANDLEHOME.
  checkLevel $curJVF $newJVF
  if [ "$levelStrg" = "Newer" ] 
  then
    instJRE=yes
    toJVF=$newJVF
  else
    instJRE=no
    toJVF=$curJVF
  fi
fi

# Install the JRE.

kbytes=0
if [ "$instJRE" = "yes" ]
then
  # See if there is enough room to install.
  
  export LANG=C
  kbytes=$(grep "^size[A-Z,a-z]* *=" $newRegPath/$newJVF 2> /dev/null | cut -d"=" -f2)
  export LANG=$saveLang
  #$NLS-E$ "could not determine the size of the base JRE package"
  [ kbytes -gt 0 ] || Err_report fail "`nls_replace 'KCI1149E'`"

  if [[ "$(uname -s)" = "NONSTOP_KERNEL" ]]	# Tandem df doesn't work as we expect, hard code now.
  then
      kbAvail=100000
  else
      checkDiskSpace $CANDLEHOME $kbytes  # install.sh exits if space is not available. 
  fi
  
  
  # Determine the name of the base package.
  
  bName=${newJVF%.*}  # Remove the .ver extension.
  bPkg=$(ls $PKGLOC/$bName.z00 2> /dev/null)  # Look first for the latest .z package
  [ -n "$bPkg" ] || bPkg=$(ls $PKGLOC/$bName.tar $PKGLOC/$bName.ctp 2> /dev/null)
  if [ -n "$bPkg" ] 
  then
    bPkg=${bPkg##*/}  # Remove the pathname
  else
    # 13526.1 - for remote deploy, there may not be a native 64-bit JRE

    # get archtecture bit (3 = 32 or 6 = 64)
    typeset -i len=0
    len=$(print $cArch|wc -c)
    len=$(($len-1))
    bitNum=$(print $cArch|cut -c$len)
    [ -z "$bitNum" ] && bitNum=3

    # if we're 64-bit and can't find a 64-bit JRE, look for 32-bit
    if [ "$bitNum" = 6 ]
    then
      newRunArch=$(print $cArch | sed 's/6$/3/g') # replace ending 6 with 3
      export LANG=C
      set -A ta $(grep -l "^runArch *= *$newRunArch$" $newRegPath/jr$osn+([0-9]).ver 2> /dev/null)
      export LANG=$saveLang
	  numEle=${#ta[*]}
      # There may be more than one .ver file, so use the latest .ver file.
      [ numEle -gt 0 ] && newJVF=${ta[numEle-1]}
      [ -n "$newJVF" ] && newJVF=${newJVF##*/}  # Remove the pathname.
    fi
    bName=${newJVF%.*}  # Remove the .ver extension.
    bPkg=$(ls $PKGLOC/$bName.z00 2> /dev/null)  # Look first for the latest .z package
    [ -n "$bPkg" ] || bPkg=$(ls $PKGLOC/$bName.tar $PKGLOC/$bName.ctp 2> /dev/null)

    if [ -n "$bPkg" ]
    then
      bPkg=${bPkg##*/}  # Remove the pathname
    else
	  #$NLS-E$ " could not find a base JRE package in \"$PKGLOC\""
      Err_report fail "`nls_replace 'KCI1150E' \\"$PKGLOC\\"`"
    fi
  fi
 
  eleNames="" i=1 numEle=0
  if [ "$bPkg" = "$bName.z00" ]  # There may be elements, so process them.
  then
    numEle=$(grep "^numElements *=" $newRegPath/$newJVF 2> /dev/null | cut -d"=" -f2)
    if [[ $? -eq 0 && numEle -gt 1 ]]  # The JRE is contained in multiple packages.
    then
	  #$NLS-E$ "versioning element JRE packages"
      Err_report info "`nls_replace 'KCI1151I'`"
      while [ i -lt numEle ]
      do
        [ i -lt 10 ] && eleNames="$eleNames $bName.z0$i"
        [ i -ge 10 ] && eleNames="$eleNames $bName.z$i"
        i=i+1
      done
      checkJRElements $eleNames
    fi
  fi

  # EJF (#12868) If a JRE is going to be overwritten remove it first
  # (41680) we should remove base JRE only. There might be preReq JRE, we shouldn't remove it.
  # (53460) we should remove the JRE only, which will be overwritten.
  jrName=$(print $curJVF | cut -d . -f1 | cut -c3-)
  if [[ -n "$jrName" && -d $CANDLEHOME/JRE/$jrName ]]
  then
    #$NLS-E$ "removing old JRE"
    Err_report info "`nls_replace 'KCI1152I'`"   
    if [ "$curJVF" = "$newJVF" ]
    then
    	rm -rf $CANDLEHOME/JRE/$jrName > /dev/null 2>&1
    	if [[ $? -eq 0 ]]
    	then
	  	#$NLS-E$ "old JRE has been removed"
      	Err_report info "`nls_replace 'KCI1153I'`"
      	if [[ -n "$curRegPath" && -n "$curJVF" && -f "$curRegPath/$curJVF" ]]
      	then
        	rm -f $curRegPath/$curJVF > /dev/null 2>&1
			#$NLS-E$ "could not remove old JRE version file \"$curJVF\""
        	[ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI1154I' \\"$curJVF\\"`"
      	fi
    	else
	  	#$NLS-E$ "unable to remove all or part of old JRE"
      	Err_report warn "`nls_replace 'KCI1155I'`"
    	fi
    fi     
  fi 
  
  #$NLS-E$ "unloading JRE package(s)"
  Err_report info "`nls_replace 'KCI1156I'`"
  for pkg in $bPkg $eleNames
  do
    unTarPkg $PKGLOC/$pkg 
    if [ "$(uname -s)" = "NONSTOP_KERNEL" ] 
    then
	while true
	do
  	    repeat=true
  	    if [ -z "$JAVALOC" ]
	    then
		        #$NLS-E$ "\nEnter the java installed location.(Default is /usr/tandem/java)"
				echo
    	        nls_replace 'KCI1157I' /usr/tandem/java
				export LANG=C
    	        read resp    	        
				resp=$(eval print $resp)
    	        export LANG=$saveLang
				[ -z "$resp" ] && resp=/usr/tandem/java	
	    else
		resp="$JAVALOC"
	    fi
	
	    if [[ ! -d "$resp" ]]
	    then
		#$NLS-E$ "\n$resp is not a correct directory."
		echo
		nls_replace 'KCI1158I' $resp
		[ -n "$silentMode" ] && exit	# if this is silent mode exit now
		JAVALOC=""
		continue
	    else
		if [ ! -x $resp/jre/bin/java ] 
		then
		    #$NLS-E$ "\nThe $resp/jre/bin/java is not an executable file."
			echo
		    nls_replace 'KCI1159I' $resp/jre/bin/java
		    [ -n "$silentMode" ] && exit		# silent mode exit here.
		    JAVALOC=""
		    continue
		fi
	    fi

	    JreVersion=1.4.2
	    jreCmd="$resp/jre/bin/java -version"
	    [ -e /tmp/jrever.txt ] && rm -f /tmp/jrever.txt
	    $jreCmd 2>/tmp/jrever.txt
	    jrever=$(grep "$JreVersion" /tmp/jrever.txt)
	    [ -e /tmp/jrever.txt ] && rm -f /tmp/jrever.txt
	    if [[ -z $jrever ]] 
	    then
		$resp/jre/bin/java -version
		#$NLS-E$ "\nThis is not a correct jre version. You have to install jre 1.4.2."
		print 
		nls_replace 'KCI1160E'
		exit
	    fi
	    JAVALOC=$resp
	    break
	done
        ln -sf $JAVALOC/jre/bin $CANDLEHOME/JRE/$cArch/bin
        ln -sf $JAVALOC/jre/lib  $CANDLEHOME/JRE/$cArch/lib
    fi
  done
  
  #45988.1
  chmod -R 755 $CANDLEHOME/JRE > /dev/null 2>&1
  
  # VSS SELinux Fix - copy the SELinux script to bin, execute the SELinux script
  if [[ "$thisOS" = "Linux" ]]
  then
        cp $PROD_PATH/fix_selinux.sh $CANDLEHOME/bin/.
        $CANDLEHOME/bin/fix_selinux.sh
  fi
  
  # Copy the .ver file for the base package, and add write access.

  cp $newRegPath/$newJVF $curRegPath/ > /dev/null 2>&1
  #$NLS-E$ "could not copy version file \"$newJVF\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1161E' \\"$newJVF\\"`"
  chmod 755 $curRegPath/$newJVF > /dev/null 2>&1
  #$NLS-E$ "could not change access permissions on \"$newJVF\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI1162E' \\"$newJVF\\"`"
fi

# Copy the tables only if they don't already exist in CANDLEHOME/registry.  Remember, the old and new tables
# will be merged by CandleInstall.

for txt in $tables
do
  if [ ! -r $curRegPath/$txt ]
  then
    if [ -r $newRegPath/$txt ]
    then 
      cp $newRegPath/$txt $curRegPath/ > /dev/null 2>&1
      chmod 755 $curRegPath/$txt > /dev/null 2>&1
    fi
  fi
  
  #$NLS-E$ "cannot read file \"$curRegPath/$txt\""
  [ -r $curRegPath/$txt ] || Err_report fail "`nls_replace 'KCI1163E' \\"$curRegPath/$txt\\"`"
done

  if [[ "$(uname -s)" = "NONSTOP_KERNEL" ]]	# Tandem df doesn't work as we expect, hard code now.
  then
      kbAvail=100000
  else
      checkDiskSpace $CANDLEHOME $kbytes  # install.sh exits if space is not available. 
  fi
  

# The JRE is now installed under $CANDLEHOME/JRE.

[ -d "$CANDLEHOME/$oldJRE" ] && mv $CANDLEHOME/$oldJRE $CANDLEHOME/$oldJRE.old > /dev/null 2>&1

# Determine which JRE to use (The JRE name is stored in env var JREEXE.), and set the CLASSPATH. 
# Function setJavaEnv is defined in dynarch.shl.

setJavaEnv $cArch



# For Roma 2.1 overinstalls, we may have to rename some directories
[ "$instFam" = "-roma" ] && Bsp21Rename $RegBackup

# Display the LAP license agreement, if it was packaged
[ "$lapDisplayMode" != "none" ] && run_LAPTool $lapDisplayMode

# now copy required GSkit package to CANDLEHOME/tmp/GSkit directory
  
#Mliao

  # Copy GSkit files depending on the platform type and bitMode
  os=$(print $cArch|cut -c1-2)
  hw=$(print $cArch|cut -c2-3)

  # Extract the bitMode (32/64) of the platform
  typeset -i len=0
  len=$(print $cArch|wc -c)
  len=$(($len-1))
  bitNum=$(print $cArch|cut -c$len)
  [ -z "$bitNum" ] && bitNum=3


  #
  # 12150.1 abstract      SVT: xLinux & zLinux depot install missing GSKit files
  # only copy GSKit if installing products to the local box - not when installing
  # products to the depot
  #
  # also, the GSKit does not exist on the ADO and Exchange CDs - don't copy 
  # when installing these cds

  # if this is Tandem we will not install and support gskit
OSTYPE=$(uname -s)

if [[ "$CDNAME" != @(m3v*|hlv*|exv*|3zv*) ]] && [[ "$cmdLnRep" = "yes" || "$guiRep" = "yes" ]] && [[ "$OSTYPE" != "NONSTOP_KERNEL" ]]
then
	  # Per defect #3357, 32-bit CMS always requires 32-bit GSkit
	  # Remove the following line once that is no longer true
	#  bitNum=3
	
export LANG=C
	  case $os in
	    ai) 
	      if [ $bitNum = 6 ]  
	      then
		   gskArch=aix526
	      	   gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
               if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
               then
	      	      cp $PROD_PATH/unix/GSKit/$gskArch/gs/* $CANDLEHOME/gskit/$gskArch
               fi
	      fi
	# 64 bit will install both 32 and 64 bits GSKit.
	      gskArch=aix523
	      gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
         if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
         then
	         cp $PROD_PATH/unix/GSKit/$gskArch/gs/gskta.rte $CANDLEHOME/gskit/$gskArch
	         cp $PROD_PATH/unix/GSKit/$gskArch/gs/gskjt.rte $CANDLEHOME/gskit/$gskArch
         fi
	      ;;
	    hp) 
	#      gskArch=hp11
	      if [ $bitNum = 6 ] 
	      then
		 gskArch=hp116
		 [ "$(uname -m)" = "ia64" ] && gskArch=hpi116
	         gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
            if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
            then
	            cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
            fi
	      fi
	
	      gskArch=hp11
		[ "$(uname -m)" = "ia64" ] && gskArch=hpi113
	      gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
         if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
         then
	         cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
         fi
	      ;;
	    li) 
	#      gskArch=li6243
          #Check for Itanium
          if [ $hw = ia ]
          then
             #Set to copy lia266 gskit
             gskArch=lia266
          else
             #Check for 64bit and copy 64 bit Linux Intel li gskit
             if  [ $bitNum = 6 ]
             then
                gskArch=li6246
                gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
                if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
                then
                   cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
                fi
             fi
             #Set to copy over 32bit Linux Intel li gskit
             gskArch=li6243
             ##Change architecture if we find red Hat 2.1
             cat /etc/*release |grep "Red Hat" |grep "2.1"  > /dev/null 2>&1
             if [ $? -eq 0 ] 
             then
                gskArch=li6242
             fi
          fi
	
	      gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
         if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
         then
	         cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
         fi
	      ;;
	    lp) 
	      if [ $bitNum = 6 ] 
	      then
	        gskArch=lpp266
	        gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
           if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
           then
	           cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
           fi
	      fi
	      gskArch=lpp263
	      gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
	      if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
	      then
	        cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
	      fi
	      ;;
	    ls) 
	#      gskArch=ls3263
	      if [ $bitNum = 6 ] 
	      then
	        gskArch=ls3266
	        gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
           if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
           then
	           cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
           fi
	      fi
	      gskArch=ls3263
	      gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
         if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
         then
	         cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
         fi
	      ;;
	    lx) 
	      if [ $bitNum = 6 ] 
	      then
		 gskArch=lx8266
	         gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
            	if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
            	then
	            cp  $PROD_PATH/unix/GSKit/$gskArch/gs/*  $CANDLEHOME/gskit/$gskArch
            	fi
	      fi
	      ;;
	    so) 
	#      gskArch=sol283
	      if [ $bitNum = 6 ] 
	      then
		  gskArch=sol286
		  [ $(uname -m) = i86pc ] && gskArch=sol606
	          gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir
             if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
             then
	             cp $PROD_PATH/unix/GSKit/$gskArch/gs/* $CANDLEHOME/gskit/$gskArch
             fi
	      fi
	
	      if [ $(uname -m) != i86pc ]
	      then
	        gskArch=sol283
	       else
		gskArch=sol603
	      fi
	        gskDir=$CANDLEHOME/gskit/$gskArch;[ -d $gskDir ] || mkdir $gskDir

         if [[ -d $PROD_PATH/unix/GSKit/$gskArch/gs/ ]]
         then
	         cp $PROD_PATH/unix/GSKit/$gskArch/gs/* $CANDLEHOME/gskit/$gskArch
         fi
	
	      ;;
	  esac

export LANG=$saveLang
	
	cmd=$CANDLEHOME/bin/runGSkit
	  #$NLS-E$ "command \"$cmd\" not found"
	  [ -x $cmd ] || Err_report warn "`nls_replace 'KCI1164I' \\"$cmd\\"`"
	  if [ -x $cmd ]
	  then
	    if [ "X$silentMode" != X ]
	    then
	      runGSkitParm='-mode silent'
	    elif [ $guiRep = yes ]
	    then
	      runGSkitParm='-mode gui'
	    else
	      runGSkitParm='-mode cmd'
	    fi
	
	    $cmd $runGSkitParm  # Run the command.
	    cc=$?
	
	    # cc=9 means they're not running as root in silent mode
		#$NLS-E$ "The root user must run installGSkit after the install to complete the setup"
	    [ $cc = 9 ] && Err_report warn "`nls_replace 'KCI1165I' installGSkit`"
	
	    # cc=42 means runGSkit was in GUI mode and the user canceled the window
	    if [ $cc = 42 ]
	    then
	      exit
	    fi
	
	    # cc=10 means runGSkit failed, defect 4990
	    if [ $cc = 10 ]
	    then
		  #$NLS-E$ "Prerequisite IBM GSkit failed to install. Retry install.sh after the problem has been corrected in your environment"
	      Err_report error "`nls_replace 'KCI1166E'`" 10
	    fi
	
	
	    # run setGSkitDir from dynarch.shl to set the ICCRTE_DIR and KEYFILE_DIR variables
	    setGSkitEnv $cArch
	  fi
fi

# Start the installer.
if [[ "$supportCLIRep" = "yes" ]]
then
cmdLnRep="no"
cmdLnDepotRep="no"
startSupport
fi
[ "$guiRep" = "yes" ] && startGUI
[ "$cmdLnRep" = "yes" ] && startCmdLn prod
[ "$cmdLnMRep" = "yes" ] && startCmdLn fix
[ "$guiRPRep" = "yes" ] && startGUIRP
[ "$cmdLnRPRep" = "yes" ] && startCmdLnRP
[ "$cmdLnDepotRep" = "yes" ] && startCmdLnDepot
[ "$guiDepotRep" = "yes" ] && startGUIDepot

# Restore the library path.  It was saved in dynarch.shl.  The restoration must be done after CandleInstall 
# has completed.

if [ -n "$saveLibPath" ]
then
  [[ "$1" = aix+([0-9]) ]] && export LIBPATH="$saveLibPath"
  [[ "$1" = hp+([0-9]) ]] && export SHLIB_PATH="$saveLibPath"
  [[ "$1" = hpi+([0-9]) ]] && export SHLIB_PATH="$saveLibPath"
  [[ "$1" = sol+([0-9]) ]] && export LD_LIBRARY_PATH="$saveLibPath"
  [[ "$1" = tsf+([0-9]) ]] && export LD_LIBRARY_PATH="$saveLibPath"
fi

export LANG="$saveLang"
export PATH="$savePath"

# change owner and group fot Linux if ID is root defect 12436
if [[ "$thisOS" = "Linux" && "$thisUser" = "root" ]]
then
    chown -R root $CANDLEHOME/bin $CANDLEHOME/config $CANDLEHOME/HTML $CANDLEHOME/images $CANDLEHOME/samples $CANDLEHOME/misc $CANDLEHOME/JRE  $CANDLEHOME/classes  $CANDLEHOME/tmp
    chgrp -R root $CANDLEHOME/bin $CANDLEHOME/config $CANDLEHOME/HTML $CANDLEHOME/images $CANDLEHOME/samples $CANDLEHOME/misc $CANDLEHOME/JRE  $CANDLEHOME/classes  $CANDLEHOME/tmp
    [ -d $CANDLEHOME/tables ] && chmod -R 777 $CANDLEHOME/tables
fi

# Set write permissions for some directories 
chmod -R 777 $CANDLEHOME/bin 2> /dev/null
chmod -R 777 $CANDLEHOME/config 2> /dev/null
chmod -R 777 $CANDLEHOME/logs 2> /dev/null
chmod -R 777 $CANDLEHOME/tmp 2> /dev/null

# These products require more write permissions than others

# defect 18183, the permssions set in SetPerm are being overwritten here
#chmod -R 777 $CANDLEHOME/*/um 2> /dev/null
chmod -R 777 $CANDLEHOME/*/um/work 2> /dev/null
chmod -R 777 $CANDLEHOME/*/um/tables 2> /dev/null
chmod -R 777 $CANDLEHOME/*/um/scripts 2> /dev/null
chmod -R 777 $CANDLEHOME/*/um/metafiles 2> /dev/null
chmod -R 777 $CANDLEHOME/*/qi 2> /dev/null

# defect 44550, run UpdateAutoRun.sh only for root user
# $CANDLEHOME/bin/UpdateAutoRun.sh $CANDLEHOME
myID=$(id 2> /dev/null | cut -d"=" -f2 2> /dev/null | cut -d"(" -f1 2> /dev/null)
if [ "$myID" = "0" ]
then
    $CANDLEHOME/bin/UpdateAutoRun.sh -h $CANDLEHOME
else
    # For non-root user, just display a warning
    #$NLS-E$ "The root user must run bin/UpdateAutoRun.sh from the ITM home to complete the setup"
    Err_report warn "`nls_replace 'KCI1042I' bin/UpdateAutoRun.sh`"
fi

# EJF (#12046) ensure that the images directory has read access for everyone
chmod -R 755 $CANDLEHOME/images 2> /dev/null

# VSS SELinux Fix - copy the SELinux script to bin, execute the SELinux script
if [[ "$thisOS" = "Linux" ]]
then
    cp $PROD_PATH/fix_selinux.sh $CANDLEHOME/bin/.
    $CANDLEHOME/bin/fix_selinux.sh
fi

cd $CANDLEHOME/bin
restart_proc start
cd - 2> /dev/null > /dev/null

cleanUp 0




