#! /bin/sh
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
#
#
# Licensed Materials - Property of IBM
#
# Restricted Materials of IBM
#
# (C) COPYRIGHT International Business Machines Corp. 2004,2008
# All Rights Reserved
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
# IBM_PROLOG_END_TAG
# %Z%%M%   %I%	 %W% %G% %U%
#
# Licensed Materials - Property of IBM
#=========================================================================
# Use this script to install or upgrade SAMP
#
# Syntax:
#	  ./installSAM [options: see SAMP base reference]
#
# Output:
#	 - rpm/pkg/installp program output from installation of each rpm/pkg/fileset  installed.
#	   List of all rpms/pkg/filesets installed.
#	   List of all subsystems active
#        - detailed log of installation in /tmp/installSAM.<#>.log.
#
# Change Activity:
#   20021018 ws Initial version
#   20030108 ws added $1 for rpm install options
#   20030218 ws add handling of arch 's390x' for 64 bit
#   20030228 ws add handling rpm return code
#   20031317 ws add conditional processing for version sam-1.1.1.0-0
#   20030519 ws add power pc (ppc)
#   20030616 ws fixed multiple version check
#   20030701 ws V1.2 add NLS, convert shell type from ksh to bash
#   20030730 ws V1.2 add arch ia64
#   20030924 ws add opteron x86_64
#   20030925 ws add packages for samnls and sam-policies
#   20031203 ws use installSAM<lang>.properties file
#   20031212 ws install rsct.core and rsct.basic together
#   20040312 ws add AIX (installp)
#   20040319 ws add sam.msg and rsct.*.msg packages
#   20040402 ws use .msg in native language (no UCS-2)
#   20040414 ws include license enablement
#   20040420 ws merge with installp (AIX)
#   20040623 ws sam 1.2 PTF1 sam-1.2.0.1
#                    - fix RSCT version greater than version to be installed
#                    - fix defect 110294 (check for softdog)
#   20040928 ws sam 1.2 PTF2 sam-1.2.0.2
#   20041213 ws sam 1.2 PTF3 sam-1.2.0.3 fix $PKG for AIX
#   20041216 ws sam 1.2 PTF3 sam-1.2.0.3 fix do not check license files
#   20050330 ws remove usage of AWK
#   20050528 ws sam 2.1.0.0 integrate instsamadapter
#   20051006 ws sam 2.1.0.1 fix order in which src and rsct msg RPMs are installed.
#   20051108 ws sam 2.1.0.1 place error message at end, prevent further non msg packages
#                    to be installed.
#   20051118 ws sam 2.1.1.0 add silent install, etc.
#   20051209 ws Issue message that java package does not exist only if Java untar is required.
#   20051212 ws Add -d option (packages directory)
#   20060203 ws Redo options.
#   20060208 ws Fix PR1P0239MiS - --noupgrade option.
#   20060208 ws Fix PR1P0240WBl - directory with prereqSAM does not exist.
#   20060208 ws Fix PR1P0246MiS - msg display although --silent specified.
#   20060331 ws Show only active RMs at completion + use correct RSCT_VSN_PAT_XX.
#   20060519 ws Fix false -d detection
#   20060608 ws Fix PR1P0242RBa - StorageRM package is not installed with SAM base install
#   20060613 ws Handle package xdrsl10 for s390 with SLES10
#   20060801 ws fix PR1P0401WBl
#   20060807 ws revise option --nonls, and add option -n <lang>
#   20060816 ws add uninstallSAM from installed package (c001)
#   20060824 ws add option --onlyupgrade
#   20060912 ws Fix PR1P0535LOB - try and buy not detected.
#   20060913 ws Allow try and buy over full, if --noliccheck.
#   20061005 ws version 2.2.0.1 fix for bug reported by F.Ning:
#                    allow installation of msg packages from directory w/o sam pkg
#   20061016 ws fix problem that in some timezones samlicm returns 2037 rather than 2038
#   20061025 ws also capture stdout.
#   20061113 ws Fix RSCT version problem (more than 1 digit version) reported by Frank Ning.
#   20061113 ws Java 1.5 for Linux
#   20070228 ws Fix CSM/TSA RSCT installation problem reported by Frank Ning.
#   20070306 ws Include handling of RSCT packages required by CSM
#   20070314 ws pass --noliccheck option to prereqSAM
#   20070330 ws append to existing logfile (req. F.Ning)
#   20070419 ws Fix for Java PMR 71010,001,866 VM aborting (RH selinux)
#   20070508 ws Always replace Java in Linux
#   20070604 ws Fix P2300610RKa Paused in Russian locale.
#   20070605 ws Fix AIX NLS package not installed (rep. F.Ning)
#   20070718 ws Fix P2300876ASc No LA/LI on new GA
#   20071001 ws sam3100
#   20071001 ws Add AIX6
#   20071002 ws support SunOS, Linux repackaged
#   20071015 ws unconditionally install rsct 64bit on p and x c002
#   20071015 ws xdrsl10 for SUSE SLES10 on all platforms c003
#   20071018 ws switch to RSCT 2.5.0.0
#   20071023 ws drop AIX 5.2 support
#   20080128 ws Fix P3100739JOE 
#   20080130 ws Fix P3100776ASC Solaris lang packs
#   20080130 ws Fix P3100696JOE link to java for AIX
#   20080208 ws Fix P3100882VVa
#   20080214 ws DCR11 - Install AIX RSCT
#   20080319 ws Fix P3101257ASc - Solaris package names
#   20080514 rb Changed sys file recognition from *.sys to *.sys*
#   20080521 rb Fixed wrong ITLM file handling, included XDR ITLM file handling
#   20080521 rb Commented out echo "Test: ..." debug outputs
#   20080526 rb Commented out 'else' for "Test:" outputs as well
#   20080529 rb Adjusted I15 comment to match current message
#   20080530 rb Fixed false pkg names in checkSAMInst() and getSAMInstPkg() for Solaris (sam -> IBMsam)
#   20080625 rb sam3101
#   20080709 rb Ignoring errors when installing RSCT msg packages -> only a warning, should not prevent installation of sam
#   20080710 rb Added extra check for copying ITLM file (only copy if $ITLM_FILE has non-zero length)
#
#=========================================================================
# TODO: Consolidate all functions common in installSAM, prereqSAM, and uninstallSAM in one utility
# TODO: Implement "Test" option, were the actual install steps only simulate the installation (has to be supported by installp, rpm and on SunOS)
# TODO: Introduce DEBUG variable for test output (echo "Test: ...")
#
#=========================================================================

DISABLE_INST=0  # 1 causes installation to be suppressed
DEBUG=0         # 1 causes additional messages to be displayed

#PN=`echo $0 | sed s/'.*\/'//` # strip program name from call arg[0]
#DIR=`echo $0 | sed s/$PN$//`  # strip directory from call arg[0]
PN=`basename $0` # strip program name from call arg[0]
DIR=`dirname $0` # strip directory from call arg[0]
TMP_STDERR=/tmp/$PN.$$.err
TMP_FIRST_STDERR="${TMP_STDERR}1"
SCRIPT=$PN': '
MSG_NAME=installSAM # messages are in installSAM.*.msg files
INST_LOG=''

# required Java version
AIX_REQ_JAVA_VERSION=14

PLATFORM=""
RSCT_DIR='/usr/sbin/rsct/bin/'
LIC_DIR='/var/opt/sam/lic'
ADAPTER_DIR='/opt/IBM/tsamp/sam'
UNINST_DIR=${ADAPTER_DIR}/uninst  # c001
ADAPTER=samadapter

# AIX RSCT install flags
RSCT_INST=1   # if version, release, or modification of pkg > installed
RSCT_UPG=2    # if fixlevel of pkg > installed
RSCT_SAME=4   # if version, release, modification, or fixlevel of pkg == installed 
RSCT_ALREADY_INST=8   # if version, release, modification, or fixlevel of pkg < installed

LUM_FILE=''
ANY_INST=0
ERROR=0		   # error flag if multiple versions
FIRST_ERROR=""     # capture text of first error
FIRST_WARN=""      # capture text of first warning
IS_ONLINE=0
IS_SAM_INST=0
USE_OPTIONS=0
TB_LIC_PKG=0
FULL_LIC_INST=0
ADAPTER_RUNS=0

HOST_NAME=`hostname`
# English only messages:
ENMSG_NOARCH="${SCRIPT}Cannot determine architecture - exit."
ENMSG_NOOS="${SCRIPT}Cannot determine OS - exit."
ENMSG_NOLANG="${SCRIPT}Cannot determine language - will use English."
ENMSG_NOLIC="${SCRIPT}Cannot find license files - will show English license."
ENMSG_NONLS="${SCRIPT}The language currently set is not supported :"
ENMSG_LANGINST="${SCRIPT}If you want to cancel installSAM to set a supported language in the operating system, type 'y':"
ENMSG_NODEFLANG="${SCRIPT}Default language not found - exit."
ENMSG_CONTEN="${SCRIPT}Will try to continue in English."
ENMSG_NOITLMFILE="${SCRIPT}ITLM sys file missing - exit."
ENMSG_LOG_STARTED="${SCRIPT}>>> Installation on $HOST_NAME - log started :"
ENMSG_LOG_STARTED="${SCRIPT}>>> Installation on $HOST_NAME - log appended :"
ENMSG_LOG_ENDED="${SCRIPT}<<< Installation on $HOST_NAME - log  ended :"
ENMSG_NO_DIR="${SCRIPT}Directory specified with option -d does not exist:"
ENMSG_NO_PKGDIR="${SCRIPT}Directory specified with option -d does not contain packages:"
ENMSG_NO_LOGDIR="${SCRIPT}Unable to create log file. Maybe the directory does not exist:"
ENMSG_NO_PREREQ="${SCRIPT}Unable find script prereqSAM in directory:"
ENMSG_NO_PREREQCHECK="${SCRIPT}WARNING: prerequisite check was bypassed."
ENMSG_LANG_OPTS_INVALID="${SCRIPT}ERROR: Options --nonls and -n <language> cannot not be used in combination."
ENMSG_UINST="${SCRIPT}Provided uninstallSAM in directory: $UNINST_DIR for uninstallation" # c001

USAGE1="Usage:" 
USAGE2="      installSAM [--noliccheck] [--nonls] [--noupgrade] [-d inst_pkg_dir] [-l log_file] [-n language] [--silent]" 

# Return codes from installSAM script
RC_OK=0
RC_INSTALLER_ERROR=1
RC_VERSION_SAME=2
RC_VERSION_INSTALLED_HIGHER=3
RC_VERSION_INSTALLED_LOWER=4
RC_NODE_ONLINE=5
RC_NO_LICENSE=6
RC_INST_UNABLE=7
RC_LANG_NOT_SUPP=8           # -n <lang> only
RC_PREREQ_PKG_NOT_INST=9     # -n <lang> only
RC_ONLY_UPGRADE=10           # if option --onlyupgrade and non installed
RC_ADAPTER=11

# Return codes from compPkgInstVersion
# return 1  if version of $Pkg > Inst
# return 0  if version of $Pkg == Inst
# return -1 if version of $Pkg < Inst
# return 2  if supplied package could not be used
# return 3  if installed package could not be used
# return 4  if versions could not be compared
RCVSN_PKG_EQ_INST=0
RCVSN_PKG_GT_INST=1
RCVSN_PKG_LT_INST=-1
RCVSN_NO_PKG=2
RCVSN_NO_INST=3
RCVSN_CMP_FAIL=4

# options:
# --force --nodeps

# internal: --noadapter
# internal: --nolic
# internal: --noprereqcheck
# internal: --noaixrsct
OPTIONS=$*
OPT_FORCE=''
OPT_NOADAPTER=0
OPT_NOLIC=0
OPT_NOPREREQCHECK=0
OPT_NOAIXRSCT=0
# additionally for silent install
# --silent
# --noliccheck
# --noupgrade
# --onlyupgrade
# --nonls
# -d
# -l
# -n
OPT_SILENT=0
OPT_NOLICCHECK=0
OPT_NOUPGRADE=0
OPT_ONLYUPGRADE=0
OPT_NONLS=0
OPT_DIR=''
OPT_LOG_FILE=''
OPT_LANG=''
SUPP_LANG=''
INST_LANG_ONLY=0
#----------------------------------
# functions
#----------------------------------

# function getcpcmd
# get cp command with its path
# Prereq: $OS must be set 'uname -s'
# return cp command with path
getcpcmd () {
   CPCMD=cp
   WRC=0
   case "$OS" in
       AIX|SunOS) CPCMD=`which cp 2>/dev/null`
            WRC=$?
       ;;
       Linux) CPCMD=`which --skip-alias cp 2>/dev/null`
            WRC=$?
            if [ $WRC -ne 0 ] ; then
               CPCMD=`which cp 2>/dev/null`
               WRC=$?
            fi
       ;;
   esac
   if [ $WRC -ne 0 ] ; then
      CPCMD=cp
   fi
   echo $CPCMD
}

# function makeLog
# paramters:
#  $1 prefix of log file
# Make log file of the form: /tmp/$1.#.log
# where # is a number that does not exist yet in
# existing log files.
# returns log file name.
makeLog () {
   NUM=`ls /tmp/$1.*.log 2>/dev/null | sed s/"\/tmp\/$1\."//g | sed s/"\.log"//g | sort -nr |head -1`
   if [ -n "$NUM" ] ; then
      NUM=`expr $NUM + 1`
   else
      NUM=1
   fi
   INST_LOG=/tmp/$1.$NUM.log
   echo $INST_LOG
}

# function logit
# log and conditionally echo message
# parameters:
#  $1 message
# Side effects:
#  if OPT_SILENT==1 do not echo message
#  log message in file installSAM.PID.log
#
logit () {
  echo "$1" >> $INST_LOG
  if [ $OPT_SILENT -eq 0 ] ; then
     echo "$1"
  fi
}

# function instexit.
# exit installation with return code.
# parameters:
#  $1 RC
#  $2 if exists then skip processing acc. to flag
#     "NONE" no output
#     "NONLS" no NLS related text
# Side effects:
#  exits script after logging.
#
instexit () {
  # remove first error file
  if [ -r "$TMP_FIRST_STDERR" ] ; then
     rm $TMP_FIRST_STDERR
  fi
  # remove stderr file
  if [ -r "$TMP_STDERR" ] ; then
     rm $TMP_STDERR
  fi

  #case "$1" in
  #   $RC_INSTALLER_ERROR) logit "$I22 $1"
  #   ;;
  #   $RC_VERSION_SAME) logit "$I49"
  #   ;;
  #   $RC_VERSION_INSTALLED_HIGHER) logit "$I39"
  #   ;;
  #   $RC_VERSION_INSTALLED_LOWER) logit "$I38"
  #   ;;
  #   $RC_NODE_ONLINE) logit "$I18"
  #   ;;
  #   $RC_NO_LICENSE) logit "$I31"     # assume only cas where license file is missing
  #   ;;
  #   $RC_INST_UNABLE) logit "$I15"
  #   ;;
  #esac
  # if rc >=20 then prereqSAM failed.

  if [ -z "$2" ] || [ "$2" = "0" ] ; then
     if [ $OPT_SILENT -eq 0 ] && [ $1 -ne 0 ] && [ $RC -lt 20 ] ; then
        echo "$I68 $INST_LOG"
     fi
  fi
  if [ -z "$2" ] || [ "$2" = "0" ] || [ "$2" = "NONLS" ] ; then
     DATE=`date`
     echo "$ENMSG_LOG_ENDED $DATE" >> $INST_LOG
  fi
  exit $1
}

# function checkNodeOnline.
# Check and memorize if node is online.
# set IS_ONLINE to 1 if online, otherwise 0.
#
checkNodeOnline () {
   IS_ONLINE=0
   # check if the local node is online and automated if true exit
   if [ -x "${RSCT_DIR}lsrpnode" ] ; then
      ONLINE=`LANG=C lsrpnode -xL 2>/dev/null | $GREP "Online"`
      if [ -n "$ONLINE" ] && [ $DISABLE_INST -ne 1 ] ; then
         IS_ONLINE=1
      fi
   fi
}


# function logNodeOnline.
# Check if node is online and log error messages.
# precondition: checkNodeOnline must have been run before.
#
logNodeOnline () {
   if [ $IS_ONLINE -eq 1 ] ; then
      if [ -x "${RSCT_DIR}lsrpnode" ] ; then
         logit "$I18"
         if [ $OPT_SILENT -eq 0 ] ; then
            lsrpnode -L
         fi
         lsrpnode -L >> $INST_LOG
         logit "$I19"
         logit "$I20"
         logit "$I21"
      fi
   fi
}

# function checkAdapterRuns.
# Check and memorize if adapter runs locally.
# set ADAPTER_RUNS to 1 if running, otherwise 0.
#
checkAdapterRuns () {
   ADAPTER_RUNS=0
   if [ -x "${ADAPTER_DIR}/bin/samadapter" ] ; then
      ${ADAPTER_DIR}/bin/samadapter status >/dev/null
      R=$?
      if [ $R -eq 1 ] ; then
         # is online
         ADAPTER_RUNS=1
      fi
   fi
}         

# function getASCII
# get the ASCII NLS string from $NLS_FILE
# if string is not available get from installSAM.en_US.msg - English
# parameters:
#  $1 ASCII key to search for NLS string
#  $2 == 1, if removal of trailing CR(13) is required
# return:
#  ASCII NLS string with $SCRIPT prefix
#
getASCII () {
  # find NLS text for pattern xxx=<NLS text>
  R=${SCRIPT}`cat $NLS_FILE | $GREP $1= | sed s/$1=//`
  #echo "R='$R'"
  if [ "$R" = "$SCRIPT" ] ; then
     # assume: not yet available as translated text, use English
     R=${SCRIPT}`cat "$MSG_DIR/$MSG_NAME.en_US.msg" | $GREP $1= | sed s/$1=//`
  fi
  if [ "$R" != "$SCRIPT" ] && [ $2 -eq 1 ] ; then
     # remove CR
     #R=`echo $R |$AWK 'BEGIN {RS="\x0D\x0A"} {gsub("\x0D\x0A","\x0A"`; print; exit;}'`
     RCNT=`echo $R | wc -c`
     RCNT=`expr $RCNT - 2`
     R=`echo $R | cut -b1-$RCNT`
  fi
  echo $R
}

# function chkLangSupport
# check if the language is supported
# parameters:
#  $1 language to check for
# return language checked, empty if none matched

chkLangSupport () {
   SUPP_LANG=''

   case $1 in
          DE|ES|FR|IT|BR|JP|KR|CN|TW) SUPP_LANG=$1
          ;;
   esac
   echo $SUPP_LANG
}

# function mapSUPPLANG2LLCC
# map language to a supported LOCALE
# parameters:
#  $1 language to map, e.g. DE
# return LOCALE, de_DE(Linux) DE_DE(AIX)
mapSUPPLANG2LLCC () {
   LL_CC=''

   if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
      case $1 in
             DE) LL_CC=de_DE
             ;;
             ES) LL_CC=es_ES
             ;;
             FR) LL_CC=fr_FR
             ;;
             IT) LL_CC=it_IT
             ;;
             BR) LL_CC=pt_BR
             ;;
             JP) LL_CC=ja_JP
             ;;
             KR) LL_CC=ko_KR
             ;;
             CN) LL_CC=zh_CN
             ;;
             TW) LL_CC=zh_TW
             ;;
      esac
      if [ "$OS" = Linux ] ; then
         LL_CC="${LL_CC}.UTF-8"  # all languages have an UTF-8 packages
      else # Solaris
         LL_CC="${LL_CC}-UTF-8"  # all languages have an UTF-8 packages
      fi      
   else   # AIX
      case $1 in
             DE) LL_CC=DE_DE
             ;;
             ES) LL_CC=ES_ES
             ;;
             FR) LL_CC=FR_FR
             ;;
             IT) LL_CC=IT_IT
             ;;
             BR) LL_CC=PT_BR
             ;;
             JP) LL_CC=JA_JP
             ;;
             KR) LL_CC=KO_KR
             ;;
             CN) LL_CC=ZH_CN
             ;;
             TW) LL_CC=ZH_TW
             ;;
      esac
   fi
   echo $LL_CC
}

# function mapLanguage
# get similar language: e.g.
# if $1 is en_US.iso885915 then map to en_US
# parameters:
#  $1 language currently set
#
mapLanguage () {
   MAPPED_LANG=$NLS_LANG
   # try map utf8 -> UTF-8
   IS_UTF8=`echo $1 | $GREP -c utf8`
   if [ $IS_UTF8 -ne 0 ] && [ $LINUX_OR_SOLARIS -eq 1 ] ; then
      MAPPED_LANG=`echo $1 | sed s/'.utf8'/'.UTF-8'/`
   else # not UTF-8
      # extract first part like 'en_' from 'en_UK'
      LANG_PREFIX=`echo $1 | sed s/_.*/_/`

      case "$LANG_PREFIX" in
          en_) MAPPED_LANG=$LANG_PREFIX"US"
          ;;
          de_) MAPPED_LANG=$LANG_PREFIX"DE"
          ;;
          es_) MAPPED_LANG=$LANG_PREFIX"ES"
          ;;
          fr_) MAPPED_LANG=$LANG_PREFIX"FR"
          ;;
          it_) MAPPED_LANG=$LANG_PREFIX"IT"
          ;;
          pt_) MAPPED_LANG=$LANG_PREFIX"BR"
          ;;
          ja_)
             IS_EUC=`echo $1 | $GREP -ic eucjp`
             if [ $IS_EUC -ne 0 ] ; then
                if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
                   MAPPED_LANG=$LANG_PREFIX"JP.eucJP"
                else
                   MAPPED_LANG=$LANG_PREFIX"JP"
                fi
             else
                MAPPED_LANG=$LANG_PREFIX"JP"
             fi
          ;;
          ko_)
             IS_EUC=`echo $1 | $GREP -ic euckr`
             if [ $IS_EUC -ne 0 ] ; then
                if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
                   MAPPED_LANG=$LANG_PREFIX"KR.eucKR"
                else
                   MAPPED_LANG=$LANG_PREFIX"KR"
                fi
             else
                MAPPED_LANG=$LANG_PREFIX"KR"
             fi
          ;;
          zh_)
             IS_GBK=`echo $1 | $GREP -ic gbk`
             if [ $IS_GBK -ne 0 ] ; then
                if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
                   MAPPED_LANG=$LANG_PREFIX"CN.GBK"
                else
                   MAPPED_LANG=$LANG_PREFIX"CN"
                fi
                break
             fi
             IS_GB18=`echo $1 | $GREP -ic gb18030`
             if [ $IS_GB18 -ne 0 ] ; then
                if [ $LINUX_OR_SOLARIS -eq 1 ]
                then
                   MAPPED_LANG=$LANG_PREFIX"CN.GB18030"
                else
                   MAPPED_LANG="Zh_CN"
                fi
                break
             fi
             IS_GB23=`echo $1 | $GREP -ic gb2312`
             if [ $IS_GB23 -ne 0 ] ; then
                if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
                   MAPPED_LANG=$LANG_PREFIX"CN.GB2312"
                else
                   MAPPED_LANG=$LANG_PREFIX"CN"
                fi
                break
             fi
             IS_TWEUC=`echo $1 | $GREP -ic euctw`
             if [ $IS_TWEUC -ne 0 ] ; then
                if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
                   MAPPED_LANG=$LANG_PREFIX"TW.eucTW"
                else
                   MAPPED_LANG=$LANG_PREFIX"TW"
                fi
                break
             fi
             IS_TWBIG5=`echo $1 | $GREP -ic big5`
             if [ $IS_TWBIG5 -ne 0 ] ; then
                if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
                   MAPPED_LANG=$LANG_PREFIX"TW.Big5"
                else
                   MAPPED_LANG="Zh_TW"
                fi
                break
             fi
             IS_TW=`echo $1 | $GREP -ic tw`
             if [ $IS_TW -ne 0 ] ; then
                MAPPED_LANG=$LANG_PREFIX"TW"
             else
                MAPPED_LANG=$LANG_PREFIX"CN"
             fi
          ;;
      esac
   fi
   #echo "mapped to: "$MAPPED_LANG
   NLS_LANG=$MAPPED_LANG
}

# function geVersion
# check if version from $1 is greather or equal to version from $2
# parameters:
# $1 Name 1 with a version
# $2 Name 2 with a version
# return 1 if version of $1 is greater or equal version of $2
#
geVersion () {
   GERC=0
   # delimit the version x.x.x.x-yydddd with #x.x.x.x-yydddd#, then cut the
   # version field and remove the . (3x) and the - to get the version as a number
   # There may be versions like x.x.x.x-0 or x.x.x.x-yyddd, where yy is the last 2 digits of the year and
   # ddd is the day in the year. Versions like x.x.x.x-0 must be extended to x.x.x.x-00000 for
   # successful comparison
   VT1=`extend0 $1`
   VT2=`extend0 $2`
   V1=`echo $VT1 | sed 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}-[0-9]\{5\}/#&#/g' | cut -s -d '#' -f2 | sed 's/\.//g' | sed 's/-//g'`
   V2=`echo $VT2 | sed 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}-[0-9]\{5\}/#&#/g' | cut -s -d '#' -f2 | sed 's/\.//g' | sed 's/-//g'`
   if [ -n "$V1" ] && [ -n "$V2" ] && [ $V1 -ge $V2 ] ; then
      GERC=1
   fi
   echo $GERC
}

# function compVersion
# compare versions from $1 and $2
# parameters:
# $1 Name 1 with a version
# $2 Name 2 with a version
# return 1  if version of $1 > $2
# return 0  if version of $1 == $2
# return -1 if version of $1 < $2
# return 4 if versions could not be compared
#
#
compVersion () {
   CMPRC=$RCVSN_CMP_FAIL
   # delimit the version x.x.x.x-yydddd with #x.x.x.x-yydddd#, then cut the
   # version field and remove the . (3x) and the - to get the version as a number
   # There may be versions like x.x.x.x-0 or x.x.x.x-yyddd, where yy is the last 2 digits of the year and
   # ddd is the day in the year. Versions like x.x.x.x-0 must be extended to x.x.x.x-00000 for
   # successful comparison
   VT1=`extend0 $1`
   VT2=`extend0 $2`
   V1=`echo $VT1 | sed 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}-[0-9]\{5\}/#&#/g' | cut -s -d '#' -f2 | sed 's/\.//g' | sed 's/-//g'`
   V2=`echo $VT2 | sed 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}-[0-9]\{5\}/#&#/g' | cut -s -d '#' -f2 | sed 's/\.//g' | sed 's/-//g'`
   if [ -n "$V1" ] && [ -n "$V2" ] ; then
      if [ $V1 -gt $V2 ] ; then
         CMPRC=$RCVSN_PKG_GT_INST
      elif [ $V1 -lt $V2 ] ; then
         CMPRC=$RCVSN_PKG_LT_INST
      else
         CMPRC=$RCVSN_PKG_EQ_INST
      fi
   fi
   echo $CMPRC
}

      
      
      
# function extend0
# check if version from $1 has only -0 appended, if yes extend by -00000
# parameters:
# $1 Name 1 with a version
#
# return changed version  x.x.x.x-00000 if version was x.x.x.x-0
#
extend0 () {
   # There may be versions like x.x.x.x-0 or x.x.x.x-yyddd where yy is the last 2 digits of the year and
   # ddd is the day in the year.
   VOUT=""
   COUNT1=`echo $1 | $GREP -c "\-0$"`                          # detect x.x.x.x-0
   COUNT2=`echo $1 | $GREP -c "\-0\."`                         # detect x.x.x.x-0.<arch>.${PKGEXT}
   COUNT3=`echo $1 | $GREP -c "\-[0-9][0-9][0-9][0-9][0-9]\."` # detect x.x.x.x-yyddd.<arch>.${PKGEXT}
   if [ $COUNT3 -eq 1 ] ; then
      # detect x.x.x.x-yyddd.<arch>.${PKGEXT} - leave as is
      VOUT=$1
   elif [ $COUNT2 -eq 1 ] ; then
      # detect x.x.x.x-0.<arch>.${PKGEXT}
      # chop off appendix -0.<arch>.${PKGEXT} to append -00000
      # sed must use "s/...." and NOT 's/...." here!
      VOUT=`echo $1 | sed "s/\-0\..*\.$PKGEXT//"`
      VOUT=$VOUT"-00000"
   elif [ $COUNT1 -eq 1 ] ; then
      # detect x.x.x.x-0
      VOUT=$1"0000"
   else
      # x.x.x.x
      VOUT=$1"-00000"
   fi
   echo $VOUT
}


# function extractPkgVersion
# Extract version from package file name
# parameters:
# $1 file path and name of package
# $2 name of installed package
# return package version: any of the form *x.x.x.x*

#
extractPkgVersion () {
   VERSION=""
   case "$OS" in
       AIX)   VERSION=`strings $1 | $GREP -E "$2 [0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}" | cut -d ' ' -f2 | head -1`
       ;;
       Linux|SunOS) PKGNAME=`echo $1 | sed s/'.*\/'//g `
              #echo "[TEST: msg to be removed!!!] extractPkgVersion PKGNAME: '$PKGNAME'"  >> $INST_LOG
              VERSION=`echo $PKGNAME | sed s/"$2\-"// | sed s/"\.$ARCH\.${PKGEXT}"//`
              #echo "[TEST: msg to be removed!!!] extractPkgVersion VERSION: '$VERSION'"  >> $INST_LOG
       ;;
   esac
   echo $VERSION
}

# function extractInstVersion
# Extract version from installed package
# parameters:
# $1 name of installed package
# return package version: any of the form x.x.x.x
#        empty string if package is not installed
#
extractInstVersion () {
   VERSION=""
   case "$OS" in
       AIX)
           INST=`lslpp -l $1 2>/dev/null | $GREP -E $1 | head -1`
           if [ -n "$INST" ] ; then
              VERSION=`echo $INST  | sed 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}/#&#/g' | cut -s -d "#" -f2`
           fi
       ;;
       Linux)
           INST=`rpm -q $1 2>/dev/null`
           RC=$?
           if [ $RC -eq 0 ] && [ -n "$INST" ] ; then
              VERSION=`echo $INST | sed s/"$1\-"// `
           fi
       ;;
       SunOS)
           INST=`pkginfo -x $1 2>/dev/null`
           if [ $RC -eq 0 ] && [ -n "$INST" ] ; then
              # extract version among line with name and revision
              VERSION=`echo $INST | sed s/.*\)// | sed s/,.*// | tail -1`
           fi
       ;;
   esac
   echo $VERSION
}


# function compPkgInstVersion
# Compare versions of supplied package against installed package
# parameters:
# $1 file path/name of package
# $2 name of installed package
# return 1  if version of $Pkg > Inst
# return 0  if version of $Pkg == Inst
# return -1 if version of $Pkg < Inst
# return 4  if versions could not be compared
# return 2  if supplied package could not be used
# return 3  if installed package could not be used
#
compPkgInstVersion () {
   PIRC=$RCVSN_CMP_FAIL
   PKGVERSION=`extractPkgVersion $1 $2`
   #echo "[TEST: msg to be removed!!!] compPkgInstVersion 1: '$1' 2: '$2'"  >> $INST_LOG
   #echo "[TEST: msg to be removed!!!] compPkgInstVersion PKGVERSION: '$PKGVERSION'"  >> $INST_LOG
   if [ -z "$PKGVERSION" ] ; then
      PIRC=$RCVSN_NO_PKG
   else
      echo "$I43 '$2' '$PKGVERSION'" >> $INST_LOG
      INSTVERSION=`extractInstVersion $2`
      if [ -z "$INSTVERSION" ] ; then
         PIRC=$RCVSN_NO_INST
      else
         echo "$I44 '$2' '$INSTVERSION'" >> $INST_LOG
         PIRC=`compVersion $PKGVERSION $INSTVERSION`
      fi
   fi
   echo $PIRC
}

# function extractPkgVR
# Extract version/release from package file name
# parameters:
# $1 file path and name of package
# return package version: any of the form x.x

#
extractPkgVR () {
   VERSION=""
   case "$OS" in
       AIX) # special handling of msg packages: They have .core appended in their version string
            # e.g. sam.msg.FR_FR has version string like: sam.msg.FR_FR.core 2.2.0.0000
            VERSION_STG=`echo $1 | sed s/'.*\/'//g`        # strip off path
            IS_MSG_PKG=`echo $1 | $GREP -Ec "\.msg\."`
            if [ $IS_MSG_PKG -eq 1 ] ; then
               VERSION_STG="${VERSION_STG}.core"
            fi
            #echo "[TEST] VERSION_STG=$VERSION_STG"  >> $INST_LOG
            VERSION=`strings $1 | $GREP -E "$VERSION_STG [0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}" | cut -d ' ' -f2 | head -1`
       ;;
       Linux|SunOS) VERSION=`echo $1 | sed 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}/#&#/g' | cut -s -d "#" -f2`
       ;;
   esac
   if [ -n "$VERSION" ] ; then
      # extract v.r from v.r.m.f
      VERSION=`echo $VERSION |  sed s/'.[0-9]\{1,\}\.[0-9]\{1,\}$//'`
   fi
   echo $VERSION
}

# function extractInstVR
# Extract version.release from installed package
# parameters:
# $1 name of package
# return package version: any of the form x.x

#
extractInstVR () {
   VERSION=""
   RC=-1
   case "$OS" in
       AIX)
           INST=`lslpp -l $1 2>/dev/null | $GREP -E $1 | head -1`
           if [ -n "$INST" ] ; then
              RC=0
           fi
       ;;
       Linux)
           INST=`rpm -q $1 2>/dev/null`
           RC=$?
       ;;
       SunOS)
           INST=`pkginfo -x $1 2>/dev/null`
           if [ -n "$INST" ] ; then
              RC=0
              INST=`echo $INST | tail -1`
           fi
       ;;
   esac
   if [ -n "$INST" ] && [ $RC -eq 0 ] ; then
      VERSION=`echo $INST | sed 's/[0-9]\{1,\}\.[0-9]\{1,\}/#&#/g' | cut -s -d "#" -f2`
   fi
   echo $VERSION
}


# function compPkgInstVR
# Compare version/release of a supplied package against another installed package
# parameters:
# $1 file path/name of supplied package
# $2 name of installed package
# return 1  if version of $Pkg > Inst
# return 0  if version of $Pkg == Inst
# return -1 if version of $Pkg < Inst
# return 4  if versions could not be compared
# return 2  if supplied package could not be used
# return 3  if installed package could not be used
#
compPkgInstVR () {
   PIRC=$RCVSN_CMP_FAIL
   PKGVERSION=`extractPkgVR $1`
   #echo "[TEST: msg to be removed!!!] compPkgInstVR 1: '$1' 2: '$2'"  >> $INST_LOG
   #echo "[TEST: msg to be removed!!!] compPkgInstVR PKGVERSION: '$PKGVERSION'"  >> $INST_LOG
   if [ -z "$PKGVERSION" ] ; then
      PIRC=$RCVSN_NO_PKG
   else
      echo "$I43 '$1' '$PKGVERSION'" >> $INST_LOG
      INSTVERSION=`extractInstVR $2`
      if [ -z "$INSTVERSION" ] ; then
         PIRC=$RCVSN_NO_INST
      else
         echo "$I44 '$2' '$INSTVERSION'" >> $INST_LOG
         PIRC=`compVR $PKGVERSION $INSTVERSION`
      fi
   fi
   echo $PIRC
}

# function compVR
# compare versions.release from $1 and $2
# parameters:
# $1 version.release  1
# $2 version.release  2
# return 1  if version of $1 > $2
# return 0  if version of $1 == $2
# return -1 if version of $1 < $2
# return 4 if versions could not be compared
#
#
compVR () {
   CMPRC=$RCVSN_CMP_FAIL
   # make numeric
   V1=`echo $1 | sed 's/\.//g'`
   V2=`echo $2 | sed 's/\.//g'`
   if [ -n "$V1" ] && [ -n "$V2" ] ; then
      if [ $V1 -gt $V2 ] ; then
         CMPRC=$RCVSN_PKG_GT_INST
      elif [ $V1 -lt $V2 ] ; then
         CMPRC=$RCVSN_PKG_LT_INST
      else
         CMPRC=$RCVSN_PKG_EQ_INST
      fi
   fi
   echo $CMPRC
}


# function getRSCTInstFlags
# compare AIX RSCT pacakge and installed versions from $1 and $2
# and set Installation flags according to what must be done
# parameters:
# $1 RSCT package version of the form x.x.x.x
# $2 RSCT installed version of the form x.x.x.x
# return $RSCT_INST(1) if version, release, or modification of pkg > inst
# return $RSCT_UPG(2)  if fixlevel of pkg > inst
# return $RSCT_SAME(4) if version, release, modification, or fixlevel of 
#                      pkg == inst 
# return $RSCT_ALREADY_INST(8) if version, version, release, modification, or fixlevel of 
#                      pkg < inst
# return 0 if versions could not be compared
#
getRSCTInstFlags () {
   INST_FLAG=0
   #echo "Test: getRSCTInstFlags() entered with pkg-version:'$1', inst-version:'$2'" >> $INST_LOG
   if [ -n "$1" ] && [ -n "$2" ] ; then
      # extract V,R,M,F
      # Version
      VPKG=`echo $1 | cut -d. -f1`
      VINST=`echo $2 | cut -d. -f1`
      # Release
      RPKG=`echo $1 | cut -d. -f2`
      RINST=`echo $2 | cut -d. -f2`
      # Modification
      MPKG=`echo $1 | cut -d. -f3`
      MINST=`echo $2 | cut -d. -f3`
      # Fix
      FPKG=`echo $1 | cut -d. -f4`
      FINST=`echo $2 | cut -d. -f4`
      if [ $VPKG -gt $VINST ] ; then
         INST_FLAG=$RSCT_INST
         #echo "Test: pkg version $VPKG > $VINST" >> $INST_LOG
      elif [ $VPKG -eq $VINST ] ; then
         #echo "Test: pkg version $VPKG == $VINST" >> $INST_LOG
         if [ $RPKG -gt $RINST ] ; then
            INST_FLAG=$RSCT_INST
            #echo "Test: pkg release $RPKG > $RINST" >> $INST_LOG
         elif [ $RPKG -eq $RINST ] ; then
            #echo "Test: pkg release $RPKG == $RINST" >> $INST_LOG
            if [ $MPKG -gt $MINST ] ; then
               #echo "Test: pkg modification $MPKG > $MINST" >> $INST_LOG
               INST_FLAG=$RSCT_INST
            elif [ $MPKG -eq $MINST ] ; then
               #echo "Test: pkg modification $MPKG == $MINST" >> $INST_LOG
               if [ $FPKG -gt $FINST ] ; then
                  INST_FLAG=$RSCT_UPG
                  #echo "Test: pkg fix $FPKG > $FINST" >> $INST_LOG 
               elif [ $FPKG -eq $FINST ] ; then
                  #echo "Test: pkg fix $FPKG == $FINST rsct version are same" >> $INST_LOG 
                  INST_FLAG=$RSCT_SAME
               else
                  #echo "Test: pkg fix $FPKG < $FINST" >> $INST_LOG 
                  INST_FLAG=$RSCT_ALREADY_INST
               fi
            else
               INST_FLAG=$RSCT_ALREADY_INST
               #echo "Test: pkg modification $MPKG < $MINST" >> $INST_LOG 
            fi
         else
            INST_FLAG=$RSCT_ALREADY_INST
            #echo "Test: pkg modification $MPKG < $MINST" >> $INST_LOG 
         fi
      else
         INST_FLAG=$RSCT_ALREADY_INST
         #echo "Test: pkg release $RPKG < $RINST" >> $INST_LOG 
      fi
   else
      INST_FLAG=$RSCT_ALREADY_INST
      #echo "Test: pkg version $VPKG < $VINST" >> $INST_LOG 
   fi
   #echo "Test: getRSCTInstFlags() returns INST_FLAG: $INST_FLAG" >> $INST_LOG 
   echo $INST_FLAG
}



# function installn
# install n packages [1...n]
#
# parameters:
# $1 package names as used by Linux:rpm -q <name> or SunOS pkginfo -x
# Note: If multiple packages are supplied, all must be in the same path.
#
# $2 optional architecture if not regular: s390, ppc, i386
# return 0 if installed
#
installn () {
   RC=$RC_INSTALLER_ERROR
   #echo "test>>>> entered"
   NPKGS=
   ARCH_EXT=
   AIX_PKGDIR=`getAIXPkgSrcDir $1`
   AIX_PKGDIR=${PKGDIR}${AIX_PKGDIR}
   if [ -n "$2" ] ; then
      ARCH_EXT=$2
   else
      ARCH_EXT=$ARCH
   fi
   for APKG in $1
   do
      DOINST=1
      #echo "test>>>> APKG=$APKG"   >> $INST_LOG
      IRC=1
      case "$OS" in
         Linux)
            # test if rpm is installed
            INSTPKG=`rpm -q $APKG 2>/dev/null`
            IRC=$?
         ;;
         SunOS)
            INSTPKG=`pkginfo -x $APKG 2>/dev/null`
            IRC=$?
            if [ $IRC -eq 0 ] ; then
                INSTPKG=`echo $INSTPKG | head -1 | cut -f1 -d' '`
            fi
         ;;

         AIX)
            # never challange installed packages in AIX
            IRC=1
         ;;
      esac
      if [ $IRC -ne 0 ] ; then
         INSTPKG=""
      fi
      if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
         # list existing package(s) hopefully only one
         PKG="${PKGDIR}/$APKG-*.${ARCH_EXT}.${PKGEXT}"
      #else
         # never test for existing fileset in AIX - only use directory for filtering
      fi
      #echo "test>>>> PKG=$PKG"           >> $INST_LOG
      #echo "test>>>> INSTPKG=$INSTPKG"    >> $INST_LOG
      # check if package in install directory exists exactly once
      if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
         # determine new package name and ensure it exists once
         NPKG=`ls -1 $PKG 2>/dev/null | $GREP "$APKG-[0-9]"`
         COUNT=`ls -1 $PKG 2>/dev/null | $GREP -c "$APKG-[0-9]"`
      else
         # AIX - new package is APKG
         NPKG=`ls -1 $AIX_PKGDIR 2>/dev/null | $GREP -E $APKG`
         COUNT=`ls -1 $AIX_PKGDIR 2>/dev/null | $GREP -Ec $APKG`
         NPKG=$APKG
      fi
      #echo "test>>>> NPKG=$NPKG"  >> $INST_LOG
      #echo "count=$COUNT"  >> $INST_LOG 
      if [ $COUNT -gt 1 ] ; then
         # error! package exists more than once
         ERT=$I12" "$COUNT
         logit "$ERT"
         if [ $OPT_SILENT -eq 0 ] ; then
            ls -1 $NPKG 2>/dev/null
         fi
         ls -1 $NPKG 2>/dev/null >> $INST_LOG
         logit "$I13"
         if [ -z "$FIRST_ERROR" ] ; then
            FIRST_ERROR=$ERT
         fi
         DOINST=0
      elif [ $COUNT -lt 1 ] ; then
         # error! package does not exist
         # check if msg rpm only - then warn only
         IS_MSG=`echo $APKG | $GREP -Ec ".msg|Msg\-"`
         if [ $IS_MSG -eq 0 ] ; then
            if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
               ERT="$I14 $PKG"
            else
               ERT="$I14 $APKG"
            fi
            echo $ERT
            if [ -z "$FIRST_ERROR" ] ; then
               FIRST_ERROR=$ERT
            fi
         else
            RC=0
         fi
         DOINST=0
      else
         ISINST=0
         # package exists exactly once
         # if no force option
         if [ -z "$OPT_FORCE" ] ; then
            # check if package at version is installed
            # e.g INSTPKG= sam-1.2.0.0-0
            #     NPKG   = ./sam-1.2.0.0-0.s390.${PKGEXT}

            if [ -n "$INSTPKG" ] ; then
               # echo "test:: package installed? INSTPKG="$INSTPKG", PKG="$NPKG
               if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
                  ISINST=`geVersion $INSTPKG $NPKG`
               #else do not check in AIX
               fi
               if [ $ISINST -ne 0 ] ; then
                  # is installed at that or greater version
                  DOINST=0
                  if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
                     logit "$I25$INSTPKG"
                  fi
                  RC=0
               fi
            fi
         fi
      fi
      if [ $DOINST -eq 1 ] ; then
         if [ "$OS" = "AIX" ] ; then
            # strip $DIR off of $NPKG
            #echo "test>>>> before NPKG=$NPKG"
            NPKG=`echo $NPKG | sed s/'.*\/'//`
            #echo "test>>>> after NPKG=$NPKG"
         fi
         # add to packages to be installed
         NPKGS=$NPKGS" "$NPKG
      fi
   done
   #echo "test>>> DOINST="$DOINST  >> $INST_LOG
   if [ -n "$NPKGS" ] ; then
      # any to install!
      logit ""
      logit "$I02"
      for NPKG in $NPKGS
      do
         logit " $NPKG"
      done
      if [ $DISABLE_INST -ne 1 ] ; then
         #echo "test:: USE_OPTIONS: $USE_OPTIONS" >> $INST_LOG
         OPTS_USED=''
         if [ $USE_OPTIONS -eq 1 ] ; then
            OPTS_USED=$OPT_FORCE
         fi
         # normal options - Linux has none
         case "$OS" in
            Linux)
            ;;
            AIX) if [ -z "$OPTS_USED" ] ; then
                    # use AIX normal install options
                    OPTS_USED='-agXd'
                 fi
            ;;
         esac
         #echo "test:: OPTS_USED: $OPTS_USED" >> $INST_LOG
         INST_CMD=''
         case "$OS" in
            Linux) INST_CMD="rpm -U $OPTS_USED $NPKGS"
                   rpm -U $OPTS_USED $NPKGS >$TMP_STDERR 2>&1
                   RC=$?
            ;;
            SunOS) # until we support multiple packages and
                   # require interaction loop through packages
                   for APKG in $NPKGS
                   do
                      # Install one by one 
                      #XPKG=`echo $APKG | sed 's/.*\///' | sed 's/-[0-9]\..*//'`
                      INST_CMD="pkgadd -a $PKG_ADM_FILE -d $APKG -G all"
                      #echo "test:: use install command: $INST_CMD"  >> $INST_LOG
                      pkgadd -n -a $PKG_ADM_FILE -d $APKG -G all >$TMP_STDERR 2>&1
                      RC=$?
                      if [ $RC -ne 0 ] ; then
                         #echo "test:: install failed with RC:$RC"  >> $INST_LOG
                         break
                      fi   
                   done   
            ;;
            AIX) INST_CMD="installp $OPTS_USED $AIX_PKGDIR $NPKG"
                 installp $OPTS_USED $AIX_PKGDIR $NPKGS >$TMP_STDERR 2>&1
                 RC=$?
            ;;
         esac
         echo "$I46 '$INST_CMD' returned:$RC" >> $INST_LOG
         if [ $RC -ne 0 ] ; then
            saveInstErrorMsgs $RC "$NPKGS"
         else
            # installation successful
            ANY_INST=`expr $ANY_INST + 1`
            RC=0
         fi
      else
         case "$OS" in
            Linux) logit "would do: rpm -U $OPTS_USED $NPKGS"
            ;;
            SunOS) logit "would do: pkgadd -G -n -d $NPKGS"
            ;;
            AIX) logit "would do: installp -agXd $PKGDIR $NPKGS"
            ;;
         esac
      fi
   fi
   return $RC
}

# function saveInstErrorMsgs
# Display installation error message append with $1 $2.
# Expects the error message in file $TMP_STDERR
# Side effects
# If this is the first error encountered:
#  - save rpm/pkg/installp error messages to
#    $TMP_FIRST_STDERR.
#  - keep error message in $FIRST_ERROR (for final output)
# $1 return code from rpm/pkg/installp
# $2 list of packages that failed install
# 
saveInstErrorMsgs () {
   # rpm/pkg/installp failed with rc!=0
   ERT=$I22" $1 : $2"
   logit "$ERT"
   ERROR=1
   if [ -z "$FIRST_ERROR" ] ; then
      # save first error if install failed
      FIRST_ERROR=$ERT
      # save stderr into first-error-file
      if [ -r "$TMP_STDERR" ] ; then
         $CPCMD $TMP_STDERR $TMP_FIRST_STDERR
      fi
   fi
}

# function checkSAMInst
# Check if sam is installed
#
checkSAMInst () {
   LALIRC=1
   # Is sam installed?
   case "$OS" in
      Linux)  rpm -q sam 1>/dev/null 2>/dev/null
              LALIRC=$?
      ;;
      SunOS) pkginfo -x IBMsam 1>/dev/null 2>/dev/null
             LALIRC=$?
      ;;
      AIX) lslpp -l sam.core.rte 1>/dev/null 2>/dev/null
           LALIRC=$?
      ;;
   esac
   if [ $LALIRC -eq 0 ] ; then
      # sam is installed
      IS_SAM_INST=1
   else
      logit "Error: checkSAMInst() returned false. SAM not installed!"
   fi
}


# function getSAMInstPkg
# Get installed SAM package
# Return installed SAM package
getSAMInstPkg () {
   INSTSAMPKG=''
   case "$OS" in
      Linux) INSTSAMPKG=`rpm -q sam 2>/dev/null`
      ;;
      SunOS) INSTSAMPKG=`pkginfo -x IBMsam 2>/dev/null | head -1 | cut -f1 -d' '`
      ;;
      AIX) INSTSAMPKG=`lslpp -l sam.core.rte 2>/dev/null | $GREP sam.core.rte | head -1`
      ;;
   esac
   echo $INSTSAMPKG
}


# function installLUM
# install license
# parameters:
# $1 license file with fully qualified path
# $2 indicates if full license installed
# $3 indicates if t&b license in pkg
# return 0 if installed or not required
# Conditions for installing a license:
# 1. t&b installed and full in package
# 2. sam installed and NOT full license installed AND t&b in package
#
installLUM () {
   RC=0
   LUM_FILE=$1
   FULL_LIC_INST=$2
   TB_LIC_PKG=$3
   DO_LIC_INST=0
   if [ -r "$LUM_FILE" ] ; then
      if [ $FULL_LIC_INST -eq 0 ] && [ $TB_LIC_PKG -eq 0 ] ; then # condition 1
         DO_LIC_INST=1
      elif [ $IS_SAM_INST -eq 1 ] ; then  # condition 2
         if [ $FULL_LIC_INST -eq 1 ] && [ $TB_LIC_PKG -eq 1 ] ; then # !condition 2
            DO_LIC_INST=0   # assign just to fill clause
         else
            DO_LIC_INST=1
         fi
      else
         logit "$I15" # Errors occurred - none installed
      fi
   fi

   if [ $DO_LIC_INST -eq 1 ] ; then
      # call samlicm to install lic file
      ${RSCT_DIR}samlicm -i $LUM_FILE
      RC=$?
      if [ $RC -ne 0 ] ; then
         logit "$I30 $LUM_FILE"
         RC=$RC_NO_LICENSE
      fi
   fi
   # test and list the license
   if [ $RC -eq 0 ] ; then
      JUNK=`${RSCT_DIR}samlicm -t 2>/dev/null`
      RC=$?
      if [ $RC -ne 0 ] ; then
         if [ $OPT_NOLICCHECK -eq 0 ] ; then
            logit "$I32"
            RC=$RC_NO_LICENSE
         fi
      else
         # list license
         logit "$I33"
         if [ $OPT_SILENT -eq 0 ] ; then
            ${RSCT_DIR}samlicm -s
         fi
         ${RSCT_DIR}samlicm -s >> $INST_LOG
      fi
   fi

   return $RC
}

# function getJavaPath - non 64bit
# get the path of the latest java installed
# parameters:
#  $1 path to add to java path
# return:
#  Value: javapath with added path or errormsg
#
getJavaPath () {
   JPATH=""
   JPATH_OK=0
   case "$OS" in
       AIX)   # c003
              JPATHS=`ls -d /usr/java[0-9]* | $GREP -v 64`
              # check version in each path
              ISJVERSION="0"
              J14PATH=""
              J15PATH=""
              J15VSN=""
              for JP in $JPATHS
       	      do
       	         # check if java is really 32 bit (path might be OK - but may link to 64bit Java)
       	         # take only first 2 digits 
                 if [ -x "$JP/jre/bin/java" ] ; then
                    ISJV=`$JP/jre/bin/java -fullversion 2>&1 | $GREP -v 64 | sed 's/[1-9]\.[0-9]/#&#/g' | cut -s -d "#" -f2 | sed 's/\.//g'`
        	    if [ "$ISJVERSION" -lt "$ISJV" ] ; then
        	       ISJVERSION=$ISJV
        	       JPATH=$JP
        	       case "$ISJV" in
        	          14) J14PATH=$JP
        	          ;;
        	          15) J15PATH=$JP
        	              J15VSN=`$JP/jre/bin/java -fullversion 2>&1`
        	          ;;   
        	       esac  
        	    fi
        	 fi    
       	      done 
       	      if [ -z "$JPATH" ] ; then
                 JPATH="$I127"
              else 
                 JPATH_OK=1   
              fi 
              if [ -n "$J15VSN" ] ; then
                 # do not use if below (SR5) c018
                 HAS_SR=`echo "$J15VSN" | $GREP -c "SR"`
                 if [ $HAS_SR -eq 1 ] ; then 
                    SR=`echo "$J15VSN" | sed s/.*SR// | sed s/[a-z]*\)\"//`  # extract n from ....(SRn[a-z])"
                    #echo "SR='$SR'"
                    if [ -z "$SR" ] ; then 
                       JPATH="$I128" 
                       JPATH_OK=0  
                    elif [ $SR -lt 5 ] ; then
                       if [ -n "$J14PATH" ] ; then
                          JPATH=$J14PATH
                       else 
                          JPATH="$I128"
                          JPATH_OK=0
                       fi
                    else
                       JPATH_OK=1    
                    fi
                 else
                    JPATH="$I128"
                    JPATH_OK=0
                 fi   
              fi            
       ;;
       Linux|SunOS) JPATH=$ADAPTER_DIR/java
                    JPATH_OK=1
       ;;
       *)     JPATH="$ENMSG_NOARCH"
       ;;
   esac
   if [ -n "$JPATH" ] && [ $JPATH_OK -eq 1 ] ; then
      JPATH="${JPATH}$1"
   fi
   echo "$JPATH"    # return java path or an error message
}
                
                
#--- function copyUninst c001
# Copy files required by uninstallSAM to uninstall directory
# Steps:
# 1. create uninst msg directory if it does not exist
# 2. copy uninstallSAM and uninstall msg files to uninst directory
#
copyUninst () {
   if [ -d "$ADAPTER_DIR" ] && [ -x "${DIR}/uninstallSAM" ] ; then
      # 1. create uninst/msg directory if it does not exist
      mkdir -p $UNINST_DIR/${OS}/msg
      # 2. copy uninstallSAM and msg to uinst directory
      cp ${MSG_DIR}/uninstallSAM.*.msg $UNINST_DIR/${OS}/msg
      cp ${DIR}/uninstallSAM $UNINST_DIR
      echo "$I104 $UNINST_DIR" >> $INST_LOG
   fi
}

#--- function getAIXPkgSrcDir
# Determine directory of package based on AIX version and package name
# $1 package name
getAIXPkgSrcDir () {
   AIX_SRC_DIR=''
   case "$OS" in
      AIX)
         AIXPKG=`echo $1 | cut -d" " -f1`
         AIX_VERSION=`oslevel -r | sed "s/\-.*//"`
         case "$AIX_VERSION" in
            6100)
                if [ "$AIXPKG" = sam.core ] ; then
                   AIX_SRC_DIR=/AIX6
                fi
            ;;
            # add more here if required
         esac
      ;;
   esac   
   echo $AIX_SRC_DIR
}

#--function installAIXRSCT
# $1 subdirectory
# $2 rsct packages to be installed
installAIXRSCT () {
   ARRC=1
   if [ "$1" = "ptf" ] ; then
       install_all_updates -d ${PKGDIR}${AIX_SAMCORE_DIR}/rsct/$1 -c >$TMP_STDERR 2>&1
       ARRC=$?
   else
       installp -agX -d ${PKGDIR}${AIX_SAMCORE_DIR}/rsct/$1 "$2" >$TMP_STDERR 2>&1
       ARRC=$?
   fi
   
   if [ $ARRC -ne 0 ] ; then
      #echo "Test: cat error:" >> $INST_LOG
      #cat $TMP_STDERR >> $INST_LOG  #test only
      #echo "Test: done cat error:" >> $INST_LOG
      saveInstErrorMsgs $ARRC "$2"
   else
      # installation successful
      ANY_INST=`expr $ANY_INST + 1`
   fi                                    
   return $ARRC
}

#--- function makePkgAdminFile
# Make file for SunOS package admin.
# pkgadd -a <pkgAdminFile> can be used to suppress interaction
# If $1 == 1 allow overwrite
# Returns path and name of file
makePkgAdminFile () {
  PKG_ADM_FILE=`rmvPkgAdminFile`
  touch $PKG_ADM_FILE
  echo "mail=" > $PKG_ADM_FILE
  if [ $1 -eq 1 ] ; then
     # allow overwrite
     echo "conflict=nocheck" >> $PKG_ADM_FILE
     echo "instance=overwrite" >> $PKG_ADM_FILE
  else
     echo "conflict=nochange" >> $PKG_ADM_FILE
  fi   
  echo "setuid=nocheck"    >> $PKG_ADM_FILE
  echo "action=nocheck"    >> $PKG_ADM_FILE
  echo $PKG_ADM_FILE
}

#--- function rmvPkgAdminFile
# Remove package admin file for SunOS.
# Returns path and name of file
rmvPkgAdminFile () {
  PKG_ADM_FILE=/tmp/pkgadmfile.com.ibm.sunos
  rm -f $PKG_ADM_FILE
  echo $PKG_ADM_FILE
}  

# Check if any help option is in options
# $1 options
#
# Rules:
# - If any help like option is detected, display usage and exit.
#
checkHelp () {
   IS_HELP=`echo $1 | $GREP -Ec "\-h|\-help|\-\-help|\-\?|\?"`
   if [ $IS_HELP -ne 0 ] ; then
      echo "$USAGE1"
      echo "$USAGE2"
      exit 1
   fi   
}

##########
#################### Begin installation processing ###################################
OS=`uname -s`   # distinguish "Linux" "AIX" before trying to determine platform
DATE=`date`
ARCH=

GREP=
if [ "$OS" = SunOS ] ; then
   GREP=/usr/xpg4/bin/grep
else
   GREP=grep    
fi

# get the copy command that does not need confirmation 'y'
CPCMD=`getcpcmd`

if [ -n "$OPTIONS" ] ; then
   checkHelp "$OPTIONS"
   # -l <log-file> option
   OPT_LOG_FILE=`echo " $OPTIONS" | $GREP " \-l " | sed s/".* \-l "// | sed s/" -.*"//`
   # --silent
   OPT_SILENT=`echo $OPTIONS | $GREP -c "\-\-silent"`
fi
# inst log is either of the form /tmp/installSAM.#.log or
# the file supplied in -l logfile
if [ -n "$OPT_LOG_FILE" ] ; then
   INST_LOG=$OPT_LOG_FILE
else
   INST_LOG=`makeLog $PN`
fi
#echo "logfile: $INST_LOG"

if [ $? -ne 0 ] ; then
   if [ $OPT_SILENT -eq 0 ] ; then
      echo "$ENMSG_NO_LOGDIR $INST_LOG"
   fi
   instexit $RC_INST_UNABLE "NONE"
fi

if [ -n "$OPT_LOG_FILE" ] && [ -w "$INST_LOG" ] ; then
   # append to existing logfile
   echo "$ENMSG_LOG_APPENDED $DATE"  >> $INST_LOG
else
   # create a new logfile
   touch $INST_LOG >/dev/null
   echo "$ENMSG_LOG_STARTED $DATE"   > $INST_LOG
fi

# set all options
PREREQ_OPTS=''
if [ -n "$OPTIONS" ] ; then
   # --force
   COUNT=`echo $OPTIONS | $GREP -c "\-\-force"`
   #echo "force count=$COUNT"
   if [ $COUNT -ne 0 ] ; then
      case "$OS" in
         Linux) OPT_FORCE="--force"
         ;;
         SunOS) echo "SunOS - --nodeps options not supported yet in this version of installSAM."
         ;;
         AIX) OPT_FORCE="-aFXd"
         ;;
      esac
   fi
   # --nodeps
   COUNT=`echo $OPTIONS | $GREP -c "\-\-nodeps"`
   #echo "nodeps count=$COUNT"
   if [ $COUNT -ne 0 ] ; then
      case "$OS" in
         Linux) OPT_FORCE="--nodeps"
         ;;
         SunOS) echo "SunOS - --nodeps options not supported yet in this version of installSAM."
         ;;
         AIX) OPT_FORCE=""     # AIX TBD
         ,,
      esac
   fi
   # internal --nonls
   OPT_NONLS=`echo $OPTIONS | $GREP -c "\-\-nonls"`
   # internal --noadapter
   OPT_NOADAPTER=`echo $OPTIONS | $GREP -c "\-\-noadapter"`
   # internal --nolic
   OPT_NOLIC=`echo "$OPTIONS " | $GREP -c "\-\-nolic "`
   # internal --noprereqcheck
   OPT_NOPREREQCHECK=`echo $OPTIONS | $GREP -c "\-\-noprereqcheck"`
   # internal --noaixrsct
   OPT_NOAIXRSCT=`echo $OPTIONS | $GREP -c "\-\-noaixrsct"`

   # silent install options
   # --silent
   if [ $OPT_SILENT -eq 1 ] ; then
      # also add option to prereqSAM
      if [ -z "$PREREQ_OPTS" ] ; then
         PREREQ_OPTS="--silent"
      else
         PREREQ_OPTS="$PREREQ_OPTS --silent"
      fi
   fi
   # --noupgrade
   OPT_NOUPGRADE=`echo $OPTIONS | $GREP -c "\-\-noupgrade"`
   # --onlyupgrade
   OPT_ONLYUPGRADE=`echo $OPTIONS | $GREP -c "\-\-onlyupgrade"`
   # --noliccheck
   OPT_NOLICCHECK=`echo $OPTIONS | $GREP -c "\-\-noliccheck"`
   if [ $OPT_NOLICCHECK -eq 1 ] ; then
      # also add option to prereqSAM
      if [ -z "$PREREQ_OPTS" ] ; then
         PREREQ_OPTS="--noliccheck"
      else
         PREREQ_OPTS="$PREREQ_OPTS --noliccheck"
      fi
   fi
   # -d <package-directory> option
   OPT_DIR=`echo " $OPTIONS" | $GREP " \-d " | sed s/".* \-d "// | sed s/" -.*"//`
   if [ -n "$OPT_DIR" ] ; then
      if [ ! -d "$OPT_DIR" ] ; then
         logit "$ENMSG_NO_DIR $OPT_DIR"
         instexit $RC_INST_UNABLE "NONLS"
      else
         DIR=$OPT_DIR
      fi
   fi
   # -n <lang> option
   OPT_LANG=`echo " $OPTIONS" | $GREP " \-n " | sed s/".* \-n "// | sed s/" -.*"//`
   if [ -n "$OPT_LANG" ] ; then
      INST_LANG_ONLY=1
   fi
fi

echo "$SCRIPT OPTIONS = $OPTIONS"                    >> $INST_LOG
echo "$SCRIPT OPT_FORCE       = $OPT_FORCE"          >> $INST_LOG
echo "$SCRIPT OPT_SILENT      = $OPT_SILENT"         >> $INST_LOG
echo "$SCRIPT OPT_NOLICCKECK  = $OPT_NOLICCHECK"     >> $INST_LOG
echo "OPT_NOPREREQCHECK       = $OPT_NOPREREQCHECK"  >> $INST_LOG
echo "$SCRIPT OPT_NOUPGRADE   = $OPT_NOUPGRADE"      >> $INST_LOG
echo "$SCRIPT OPT_NONLS       = $OPT_NONLS"          >> $INST_LOG
echo "$SCRIPT OPT_NOAIXRSCT   = $OPT_NOAIXRSCT"      >> $INST_LOG
if [ -n "$OPT_LANG" ] ; then
   echo "$SCRIPT Install language = $OPT_LANG" >> $INST_LOG
fi

if [ $INST_LANG_ONLY -eq 1 ] && [ $OPT_NONLS -eq 1 ] ; then
   logit "$ENMSG_LANG_OPTS_INVALID"
   instexit $RC_INST_UNABLE "NONLS"
fi

# Options not meant for customers
#echo "OPT_NOADAPTER     = $OPT_NOADAPTER"     >> $INST_LOG
#echo "OPT_NOLIC         = $OPT_NOLIC"         >> $INST_LOG


# Do prereq checking first
# add log option to prereq options
if [ -z "$PREREQ_OPTS" ] ; then
   PREREQ_OPTS="-l $INST_LOG"
else
   PREREQ_OPTS="$PREREQ_OPTS -l $INST_LOG"
fi

#====================================================
# Call script 'prereqSAM' before attempting install
#====================================================
#echo "PREREQ_OPTS=$PREREQ_OPTS"
if [ ! -x "$DIR/prereqSAM" ] ; then
   logit "$ENMSG_NO_PREREQ $DIR"
   instexit $RC_INST_UNABLE "NONLS"
fi

if [ $OPT_NOPREREQCHECK -eq 0 ] ; then
   $DIR/prereqSAM "$PREREQ_OPTS"
   RC=$?
else
   logit "$ENMSG_NO_PREREQCHECK"
   RC=0
fi
#echo "from prereqSAM RC=$RC"

if [ $RC -ne 0 ] ; then
   # Failed prereq checks - exit
   instexit $RC
fi

# package extension Linux or SunOS
PKGEXT=
case "$OS" in
    AIX)   PLATFORM=AIX
    ;;
    Linux) PLATFORM=`arch` # platform of target Linux machine
           PKGEXT=rpm
    ;;
    SunOS) PLATFORM=`mach` # platform of target SunOS machine
           PKGEXT=pkg
    ;;
    *)     logit "$ENMSG_NOOS"
           instexit $RC_INST_UNABLE "NONLS"
    ;;
esac

#echo "OS = $OS" >> $INST_LOG

# determine architecture

COUNT=`echo $PLATFORM | $GREP -c "^i[3-6]86$"`
if [ $COUNT -eq 1 ] ; then
   ARCH=i386
fi

COUNT=`echo $PLATFORM | $GREP -c "^x86_64$"`
if [ $COUNT -eq 1 ] ; then
   ARCH=i386
fi

COUNT=`echo $PLATFORM | $GREP -c "^ia64"`
if [ $COUNT -eq 1 ] ; then
   ARCH=i386
fi

COUNT=`echo $PLATFORM | $GREP -c "^s390"`
if [ $COUNT -eq 1 ] ; then
   ARCH=s390
fi

COUNT=`echo $PLATFORM | $GREP -c "^ppc"`
if [ $COUNT -eq 1 ] ; then
   ARCH=ppc
fi

COUNT=`echo $PLATFORM | $GREP -c "^sparc"`
if [ $COUNT -eq 1 ] ; then
   ARCH=sparc
fi

COUNT=`echo $PLATFORM | $GREP -c "^AIX"`
if [ $COUNT -eq 1 ] ; then
   ARCH=   # use only OS name
fi

# Check Architecture
if [ -z "$ARCH" ] && [ "$OS" != AIX ] ; then
   logit "$ENMSG_NOARCH"
   instexit $RC_INST_UNABLE "NONLS"
fi

#echo "Architecture = $ARCH" >> $INST_LOG
OS_ARCH_DIR=
if [ "$OS" = AIX ] ; then
   OS_ARCH_DIR=$OS
else
   OS_ARCH_DIR=$OS/$ARCH
fi

if [ -n "$OPT_DIR" ] ; then
   if [ -d "${OPT_DIR}/$OS_ARCH_DIR" ] ; then
      DIR=$OPT_DIR
   else
      logit "$ENMSG_NO_PKGDIR $OPT_DIR"
      instexit $RC_INST_UNABLE "NONLS"
   fi
fi
PKGDIR=${DIR}/$OS_ARCH_DIR

LINUX_OR_SOLARIS=0
if [ "$OS" = "Linux" ] || [ "$OS" = "SunOS" ] ; then
   LINUX_OR_SOLARIS=1
fi

# determine if ITLM files are in $DIR/$OS/itlm/
ITLM_FILE=${DIR}/${OS}/itlm/ITSAMP0301.SYS2
ITLM_FILE=`ls $ITLM_FILE 2>/dev/null`
ITLM_FILE_XDR=${DIR}/${OS}/itlm/ITSAMPXDR0301.SYS2
ITLM_FILE_XDR=`ls $ITLM_FILE_XDR 2>/dev/null`

if [ ! -r "$ITLM_FILE" ] ; then
   logit "$ENMSG_NOITLMFILE"
   instexit $RC_INST_UNABLE "NONLS"
fi

#====================================================
# determine National Language
# extract <value> from LANG, LC_ALL, or LC_CTYPE
NLS_LANG=`locale | $GREP "LANG=" | sed s/LANG=// | sed 's/\"//g'` 2>/dev/null
if [ -z "$NLS_LANG" ] ; then
   NLS_LANG=`locale | $GREP "LC_ALL=" | sed s/LC_ALL=// | sed 's/\"//g'` 2>/dev/null
   if [ -z "$NLS_LANG" ] ; then
      NLS_LANG=`locale | $GREP "LC_CTYPE=" | sed s/LC_CTYPE=// | sed 's/\"//g'` 2>/dev/null
      if [ -z "$NLS_LANG" ] ; then
         logit "$ENMSG_NOLANG"
         NLS_LANG=en_US
      fi
   fi
fi

if [ "$NLS_LANG" = "POSIX" ] || [ "$NLS_LANG" = "C" ] ; then
   NLS_LANG=en_US
fi

MSG_DIR=
case "$OS" in
   AIX|Linux|SunOS) MSG_DIR="${DIR}/${OS}/msg"
   ;;
esac

NLS_FILE="$MSG_DIR/$MSG_NAME.$NLS_LANG.msg"
#echo "try to find: "$NLS_FILE


if [ ! -r "$NLS_FILE" ]  ; then
   # try to map to similar language
   mapLanguage $NLS_LANG
   NLS_FILE="$MSG_DIR/$MSG_NAME.$NLS_LANG.msg"
   if [ ! -r "$NLS_FILE" ] ; then
      # fall back to English
      logit "$ENMSG_NONLS $NLS_LANG"
      logit
      logit "$ENMSG_LANGINST"
      logit
      if [ $OPT_SILENT -eq 0 ] ; then
         read RES
         if [ "$RES" = "y" ] || [ "$RES" = "Y" ] ; then
            logit "$I45"
            instexit $RC_INST_UNABLE "NONLS"
         fi
      fi
      logit "$ENMSG_CONTEN"
      NLS_FILE="$MSG_DIR/$MSG_NAME.en_US.msg"
      if [ ! -r "$NLS_FILE" ] ; then
         logit "$I45"
         logit "$ENMSG_NODEFLANG"
         instexit $RC_INST_UNABLE "NONLS"
      fi
   fi
fi


if [ $DEBUG -eq 1 ] ; then
   logit T:use language-texts in file: $NLS_FILE # test
fi

# test
#cat $NLS_FILE
# test

# list of messages (from installSAM.*.msg)

# I01=Installing System Automation on platform
# I02=Installing
# I03=Information: uninstall/install done for this version of sam
# I04=Option passed to rpm:
# I05=Installed System Automation package and prerequisites:
# I06=Status of System Automation on
# I07=A general License Agreement and product specific License Information will be shown. Scroll down using the Enter key (line by line) or Space bar (page by page). At the end you will be asked to accept the terms to be allowed to install the product. Select Enter to continue.
# I08=To accept all terms of the preceding License Agreement and License Information type 'y', anything else to decline.
# I09=To accept all terms of the preceding License Agreement and License Information select 'Enter', to decline type Ctrl-c.
# I10=You did not accepted the terms in License Agreement and License information. System Automation will not be installed.
# I11=You accepted the terms in License Agreement and License information. The product will now be installed.
# I12=Too many versions to install:
# I13=You may have extracted a new version over an older version into directory SAM. Hint: Delete directory SAM before using tar to extract files.
# I14=Package does not exist:
# I15=Errors occurred - package installation is incomplete.
# I16=Architecture not supported:
# I17=Only option: --force can be used
# I18=Cannot upgrade because this node is online:
# I19=This node must be excluded from automation and then stopped before upgrade can proceed.
# I20=Exclude this node from automation using samctrl -u a
# I21=Before you try again, stop this node with stoprpnode
# I22=Error: rpm failed with return-code:
# I23=No License Agreement or License License Information was found. The product cannot be installed.
# I24=Warning: Must set CT_MANAGEMENT_SCOPE=2
# I25=Package is already installed:
# I26=All packages were installed successfully.            (added 03/23)
# I27=Any packages failed installation. See details below. (added 03/23)
# I28=Option ignored:                                      (added 03/23)
# I29=yes                                                  (added 04/02)
# I30=Installing license failed.                           (added 04/02)
# I31=License file not found:                              (added 04/02)
# I32=Cannot upgrade because no valid license was found.   (added 04/02)
# I33=The following license is installed:                  (added 04/02)
# I34=Warning: Module 'softdog' could not be loaded...     (added 04/06/23)

# new messages SAM2.1.0.0
# I35=Stop the end-to-end automation manager adapter, using command 'samadapter stop'. (added 2005-05-28)
# I36=Found Java at version:                                                           (added 2005-05-28)
# I37=To run the end-to-end automation manager adapter, you must install 32-bit Java at this or higher version: (added 2005-05-28)

# new messages SAM2.1.0.1 (added 2005-11-24)
# I38=Package 'sam' was found installed at a lower version and needs to be upgraded, but option '--noupgrade' was specified to prevent upgrade.
# I39=Package 'sam' is already installed at a higher version than the package supplied for upgrade.
# I40=Cannot determine version of package 'sam'.
# I41=Warning: You are installing a package over the same version that is already installed:
# I42=Warning: You are installing a package over a higher version that is already installed:
# I43=Package and version supplied for installation:
# I44=Package and version installed:
# I45=No installation performed.
# I46=Installation command:
# I47=Packages are installed from directory:
# I82=Detected operating system:
# I83=Detected architecture:

# new messages SAM2.2.0.0 (added 2006-08-09) for separate language installation
# I96=Error: The following language is not supported:
# I97=Only the English version of packages will be installed.
# I98=Only the following language will be installed:
# I99=Error: Unable to install a language because package 'sam' is not installed.
# I100=Error: Version and release of language to be installed and installed package 'sam' are different:
# I101=Error: Option '--onlyupgrade' was specified which can only be used for upgrading, but package 'sam' was not found installed.
# new sam 2.2.0.2
# I104=Provided uninstallSAM in directory for uninstallation:

#new sam 3.1.0.0
# I113=Error: 'samadapter' is running. Stop samadapter with command 'samadapter stop'. Then re-try installation.
# I114=Error: Installing a new version of RSCT for AIX failed with installp return code: 
# I115=The new RSCT version for AIX to be installed is:
# I116=Error: Upgrading RSCT for AIX failed with installp return code: 
# I117=The new RSCT version for AIX to be upgraded is:
# I118=Installed new version of RSCT for AIX successfully. New version is:
# I119=Upgraded RSCT for AIX successfully. Upgraded version is:
# I120=RSCT for AIX is not installed or upgraded because it is already installed at a higher version: 
# I121=Package rsct.basic required by package 'sam' is not found installed on AIX. 
# I122=Error: Package rsct.basic cannot be installed on AIX because the installed version of other RSCT packages is higher:
# I124=SUN package is installed:
#new sam 3.1.0.0 English only
# I127=Error: Cannot find Java 32-bit."
# I128=Error: Cannot use java5 because service release is less than SR5."

# Get all NLS texts acc. to $NLS_FILE
# get ASCII texts from keys
I01=`getASCII "I01" 1`' '
I02=`getASCII "I02" 1`' '
I03=`getASCII "I03" 1`
I04=`getASCII "I04" 1`" $1"
I05=`getASCII "I05" 1`' '
I06=`getASCII "I06" 1`' '
I07=`getASCII "I07" 1`' '
I08=`getASCII "I08" 1`' '
I09=`getASCII "I09" 1`' '
I10=`getASCII "I10" 1`
I11=`getASCII "I11" 1`

I12=`getASCII "I12" 1`' '
I13=`getASCII "I13" 1`
I14=`getASCII "I14" 1`' '
I15=`getASCII "I15" 1`
I16=`getASCII "I16" 1`' '
I17=`getASCII "I17" 1`' '
I18=`getASCII "I18" 1`' '
I19=`getASCII "I19" 1`
I20=`getASCII "I20" 1`' '$HOST_NAME
I21=`getASCII "I21" 1`' '$HOST_NAME
I22=`getASCII "I22" 1`' '
I23=`getASCII "I23" 1`
I24=`getASCII "I24" 1`' '
I25=`getASCII "I25" 1`' '
I26=`getASCII "I26" 1`
I27=`getASCII "I27" 1`
I28=`getASCII "I28" 1`' '
I29=`getASCII "I29" 1`
I30=`getASCII "I30" 1`' '
I31=`getASCII "I31" 1`' '
I32=`getASCII "I32" 1`' '
I33=`getASCII "I33" 1`' '
I34=`getASCII "I34" 1`' '              # new msg sam-1.2.0.1 for softdog
# new messages SAM2.1.0.0
I35=`getASCII "I35" 1`' '
I36=`getASCII "I36" 1`' '
I37=`getASCII "I37" 1`' '
# new messages SAM2.1.0.1
I38=`getASCII "I38" 1`' '
I39=`getASCII "I39" 1`' '
I40=`getASCII "I40" 1`' '
I41=`getASCII "I41" 1`' '
I42=`getASCII "I42" 1`' '
I43=`getASCII "I43" 1`' '
I44=`getASCII "I44" 1`' '
I45=`getASCII "I45" 1`' '
I46=`getASCII "I46" 1`' '
I47=`getASCII "I47" 1`' '
I48=`getASCII "I48" 1`' '
I49=`getASCII "I49" 1`' '
I50=`getASCII "I50" 1`' '
I51=`getASCII "I51" 1`' '
I52=`getASCII "I52" 1`' '
I53=`getASCII "I53" 1`' '
I68=`getASCII "I68" 1`' '             # shared with prereqSAM
I82=`getASCII "I82" 1`' '             # shared with prereqSAM
I83=`getASCII "I83" 1`' '             # shared with prereqSAM
I90=`getASCII "I90" 1`' '             # shared with prereqSAM
# new messages SAM2.2.0.0
I96=`getASCII "I96" 1`' '             # separate language installation
I97=`getASCII "I97" 1`' '             # separate language installation
I98=`getASCII "I98" 1`' '             # separate language installation
I99=`getASCII "I99" 1`' '             # separate language installation
I100=`getASCII "I100" 1`' '           # separate language installation
# new sam 3.1.0.0
I110=`getASCII "I110" 1`' '
I113=`getASCII "I113" 1`' '           # option --onlyupgrade
I114=`getASCII "I114" 1`' '
I115=`getASCII "I115" 1`' '
I116=`getASCII "I116" 1`' '
I117=`getASCII "I117" 1`' '
I118=`getASCII "I118" 1`' '
I119=`getASCII "I119" 1`' '
I120=`getASCII "I120" 1`' '
I121=`getASCII "I121" 1`' '
I122=`getASCII "I122" 1`' '
I124=`getASCII "I124" 1`' '
I127=`getASCII "I127" 1`' '
I128=`getASCII "I128" 1`' '
  


echo "$I83 $OS" >> $INST_LOG

RC=0

# Check if language is supported
if [ $INST_LANG_ONLY -eq 1 ] ; then
   SUPP_LANG=`chkLangSupport $OPT_LANG`
   if [ -z "$SUPP_LANG" ] ; then
      logit "$I96 $OPT_LANG"
      instexit $RC_LANG_NOT_SUPP
   fi
fi

if [ $INST_LANG_ONLY -eq 0 ] ; then    # no need to check if only language installed
   #======================================================
   # if Linux check if softdog module is installed - SunOS?
   if [ "$OS" = "Linux" ] ; then
      #modprobe --show softdog1 2>/dev/null # for test
      modprobe --show softdog 2>/dev/null
      RC=$?
      # logit "modprobe RC=$RC"
      if [ $RC -ne 0 ] ; then
         # ask user if installation should continue, although
         # softdog module cannot be found
         logit "$I34"
         # If users enters "y" continue anyway, although softdog does not exist
         if [ $OPT_SILENT -eq 0 ] ; then
            echo
            read RES
            if [ "$RES" != "y" ] && [ "$RES" != "Y" ] ; then
               instexit $RC_INST_UNABLE
            fi
            echo
         fi
      fi
   fi
fi
RC=0

#======================================================
# Start License Handling
#======================================================

# Check sam is already installed
# if not LA or LI and LUM are required
checkSAMInst

#======================================================
# Check LUM license supplied
LUM_FILE=`ls ${DIR}/license/*.lic 2>/dev/null`
if [ ! -r "$LUM_FILE" ] ; then
   # no license file supplied
   if [ $IS_SAM_INST -eq 1 ] ; then
      # sam is installed
      # may be PTF - check license exists - refuse to install if not,
      # unless option bypasses license check
      JUNK=`${RSCT_DIR}samlicm -t 2>/dev/null`
      RC=$?
      if [ $RC -ne 0 ] ; then
         if [ $OPT_NOLICCHECK -eq 0 ] ; then
            logit "$I32"
            logit "$I45"
            instexit $RC_NO_LICENSE
         else
            echo "$I52" >> $INST_LOG
         fi
      else
         # Detected installed license
         echo "$I50" >> $INST_LOG
         ${RSCT_DIR}samlicm -s >> $INST_LOG

      fi
   else
      # sam is not installed yet and no LUM file supplied
      logit "$I31"
      if [ $OPT_NOLICCHECK -eq 0 ] ; then
         # exit because license check not overridden
         logit "$I45"
         instexit $RC_NO_LICENSE
      else
         echo "$I53" >> $INST_LOG
      fi
   fi
else
   # have a license file
   # check if is a try&buy license file to install
   TB_LIC_PKG=`cat $LUM_FILE | $GREP -c "TryAndBuy\=Yes"`
   # Check if full license is installed
   JUNK=`${RSCT_DIR}samlicm -t 2>/dev/null`
   RC=$?
   if [ $RC -eq 0 ] ; then
      # a license is installed - list it to see
      # if this is full license.
      # Note: uses a method that has the year2038 problem!
      FULL_LIC_INST=`${RSCT_DIR}samlicm -s | $GREP -Ec "2037|2038"`
   fi
   if [ $TB_LIC_PKG -eq 1 ] ; then
      # if there is --noliccheck service may also have a T&B license and then don't exit.
      if [ $FULL_LIC_INST -eq 1 ] && [ $OPT_NOLICCHECK -eq 0 ] ; then
         # Installing try&buy license over a full license is not allowed.
         # list license with error
         logit "$I33"
         if [ $OPT_SILENT -eq 0 ] ; then
            ${RSCT_DIR}samlicm -s
         fi
         ${RSCT_DIR}samlicm -s >> $INST_LOG
         logit "$I110" 
         instexit $RC_NO_LICENSE
      fi
   fi
   echo "$I51" >> $INST_LOG
fi

RC=0

# Check if package sam must be installed.
# if not return w/o any prereq installation

# 1. Compare package 'sam' versions
SAMPKG=''
SAMINST=''
AIX_SAMCORE_DIR=''
if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
   # list existing package(s) hopefully only one
   if [ "$OS" = Linux ] ; then
      SAMPKG="${PKGDIR}/sam-*.$ARCH.${PKGEXT}"
      SAMINST=sam
   else # Solaris
      SAMPKG="${PKGDIR}/IBMsam-*.$ARCH.${PKGEXT}"
      SAMINST=IBMsam
   fi   
   SAMPKG=`ls -1 $SAMPKG 2>/dev/null | $GREP "$SAMINST-[0-9].*\-[0-9]*\.$ARCH\.${PKGEXT}"`
   #echo "[TEST: msg to be removed!!!] SAMPKG=$SAMPKG"   >> $INST_LOG
   COUNT=`ls -1 $SAMPKG 2>/dev/null | $GREP -c "$SAMINST-[0-9].*\-[0-9]*\.$ARCH\.${PKGEXT}"`
   #echo "[TEST: msg to be removed!!!] COUNT=$COUNT"    >> $INST_LOG
   if [ $COUNT -gt 1 ] ; then
      # error! sam package exists more than once
      logit "$I12 $COUNT"
      if [ $OPT_SILENT -eq 0 ] ; then
         ls -1 $SAMPKG 2>/dev/null
      fi
      ls -1 $SAMPKG 2>/dev/null >> $INST_LOG
      logit "$I13"
      instexit $RC_INST_UNABLE
   elif [ $COUNT -eq 0 ] ; then
      SAMPKG="sam-" # package is not supplied (NLS packages only)
   fi
else
   # list existing fileset in AIX
   AIX_SAMCORE_DIR=`getAIXPkgSrcDir sam.core`
   SAMPKG=${PKGDIR}${AIX_SAMCORE_DIR}/sam.core
   SAMINST=sam.core.rte
fi
#echo "[TEST: msg to be removed!!!] came here: SAMPKG=$SAMPKG, SAMINST=$SAMINST, AIX_SAMCORE_DIR=$AIX_SAMCORE_DIR"
RC=`compPkgInstVersion $SAMPKG $SAMINST`
#echo "[TEST: msg to be removed!!!] Comparing 'sam' package and installed version returned: $RC"

# Indicates if sam installation is forced
DO_FORCE=0
OVERWRITE=0
# 2. Based on RC decide if installation is required:
if [ $RC -eq $RCVSN_PKG_GT_INST ] ; then
   # sam package is more recent than installed
   # If option "--noupgrade" is specified do not upgrade and exit
   if [ $OPT_NOUPGRADE -eq 1 ] ; then
      logit "$I45"
      logit "$I38"
      instexit $RC_VERSION_INSTALLED_LOWER
   fi
   OVERWRITE=1
elif [ $RC -eq $RCVSN_PKG_EQ_INST ] ; then
   INSTSAMPKG=`getSAMInstPkg`
   # sam package is at the same level than installed
   # if this installs only language bypass exit
   if [ $INST_LANG_ONLY -eq 0 ] ; then
      # If "--force" is specified install anyway
      # If not exit - saying installed version is at same level than package
      if [ -z "$OPT_FORCE" ] ; then
         logit "$I45"
         logit "$I49 $INSTSAMPKG"
         # at least install license if full over t&b
         installLUM $LUM_FILE $FULL_LIC_INST $TB_LIC_PKG
         instexit $RC_VERSION_SAME
      else
         logit "$I41 $INSTSAMPKG"
      fi
   fi
   OVERWRITE=1
elif [ $RC -eq $RCVSN_PKG_LT_INST ] ; then
   INSTSAMPKG=`getSAMInstPkg`
   # sam package is at lower level than installed
   # If "--force" is specified install anyway
   # If not exit - saying installed version is already at higher level than package
   # if this installs only language bypass exit
   if [ $INST_LANG_ONLY -eq 0 ] ; then
      if [ -z "$OPT_FORCE" ] ; then
         logit "$I45"
         logit "$I39"
         # at least install license if full over t&b
         installLUM $LUM_FILE $FULL_LIC_INST $TB_LIC_PKG
         instexit $RC_VERSION_INSTALLED_HIGHER
      else
         logit "$I42 $INSTSAMPKG"
         DO_FORCE=1
      fi
   fi
   OVERWRITE=1
elif [ $RC -eq $RCVSN_NO_INST ] ; then
   if [ $OPT_ONLYUPGRADE -eq 0 ] ; then
      # seems sam package is not installed - must install it
      INSTSAMPKG=`getSAMInstPkg`
      logit "$I48 $SAMPKG"
   else
      logit "$I101"
      instexit $RC_ONLY_UPGRADE
   fi
elif [ $RC -eq $RCVSN_NO_PKG ] ; then
   if [ $INST_LANG_ONLY -eq 0 ] ; then
      # seems sam package is not supplied - cannot install - exit
      logit "$I45"
      logit "$I14 $SAMINST"
      instexit $RC_INST_UNABLE
   fi
elif [ $RC -eq $RCVSN_CMP_FAIL ] ; then
   # package and installed cannot be compared - exit
   logit "$I45"
   logit "$I40 $SAMINST"
   instexit $RC_INST_UNABLE
fi

# Check language only installation is required,
# then SAM must be at the correct level.
# Otherwise exit
if [ $INST_LANG_ONLY -eq 1 ] ; then
   if [ $RC -eq $RCVSN_NO_INST ] || [ $RC -eq $RCVSN_CMP_FAIL ] ; then
      logit "$I99"
      instexit $RC_PREREQ_PKG_NOT_INST
   else
      # make a check if any lang package and installed version agree in Version/Release (e.g. 2.2`
      SAMLANGPKG=''
      LL_CC=`mapSUPPLANG2LLCC $SUPP_LANG`
      #echo "[TEST: msg3 to be removed!!!] LL_CC=$LL_CC" >> $INST_LOG 
      if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
         # list existing lang package
         if [ "$OS" = Linux ] ; then
            SAMLANGPKG="${PKGDIR}/sam.msg.${LL_CC}-*.$ARCH.${PKGEXT}"
         else # Solaris   
            SAMLANGPKG="${PKGDIR}/IBMsamMsg-${LL_CC}-*.$ARCH.${PKGEXT}"
         fi   
         #echo "[TEST: msg1 to be removed!!!] came here: SAMLANGPKG=$SAMLANGPKG, SAMINST=$SAMINST" >> $INST_LOG
         SAMLANGPKG=`ls -1 $SAMLANGPKG 2>/dev/null`
         #echo "[TEST: msg2 to be removed!!!] after ls SAMLANGPKG=$SAMLANGPKG" >> $INST_LOG
      else
         # list existing fileset in AIX
         SAMLANGPKG="${PKGDIR}/sam.msg.${LL_CC}"
      fi
      #echo "[TEST: msg3 to be removed!!!] came here: SAMLANGPKG=$SAMLANGPKG, SAMINST=$SAMINST" >> $INST_LOG
      RC=`compPkgInstVR $SAMLANGPKG $SAMINST`
      #echo "[TEST: msg to be removed!!!] Comparing  VR 'sam' package and installed version returned: $RC" >> $INST_LOG
      # test
      #PKGVERSION=`extractPkgVR $SAMLANGPKG "$sam.msg.${LL_CC}"`
      #INSTVERSION=`extractInstVR $SAMINST`
      #echo "[TEST: msg to be removed!!!]PKGVERSION<>INSTVERSION= $PKGVERSION<>$INSTVERSION"  >> $INST_LOG
      # end test
      if [ $RC -ne $RCVSN_PKG_EQ_INST ] ; then
         if [ "$OS" = Linux ] || [ "$OS" = AIX ] ; then
            PKGVERSION=`extractPkgVR $SAMLANGPKG "sam.msg.${LL_CC}"`
         else
            PKGVERSION=`extractPkgVR $SAMLANGPKG "IBMsamMsg-${LL_CC}"`
         fi   
         INSTVERSION=`extractInstVR $SAMINST`
         if [ $RC -eq $RCVSN_PKG_GT_INST ] || [ $RC -eq $RCVSN_PKG_LT_INST ] ; then
            logit "$I100 $PKGVERSION<>$INSTVERSION"
            if [ $RC -eq $RCVSN_PKG_LT_INST ] ; then
               instexit $RC_VERSION_INSTALLED_HIGHER
            elif [ $RC -eq $RCVSN_PKG_GT_INST ] ; then
               instexit $RC_VERSION_INSTALLED_LOWER
            fi
         elif [ $RC -eq $RCVSN_NO_INST ] || [ $RC -eq $RCVSN_CMP_FAIL ] ; then
            logit "$I99"
         fi
         instexit $RC_PREREQ_PKG_NOT_INST
      fi
   fi
fi

RC=0
#=========================================================
# Now it is clear that installation of sam package
# OR the language pack is required.

# 1. Check if license file is available or installed
# 2. Indicate that LA and LI will be shown
# 3. Show the LA_<$strNLS> (License Agreement) file
# 4. Show the LI_<$strNLS> (License Information) file
# 5. Ask the user to accept the terms

LILA_DIR=
case "$OS" in
   AIX|Linux|SunOS) LILA_DIR="${DIR}/${OS}/license"
   ;;
esac

if [ $INST_LANG_ONLY -eq 0 ] ; then
   # check for domain online (must NOT be online)
   checkNodeOnline
   logNodeOnline
   if [ $IS_ONLINE -eq 1 ] ; then
      logit "$I45"
      instexit $RC_NODE_ONLINE
   fi
   # check if the adapter is running
   checkAdapterRuns
   if [ $ADAPTER_RUNS -eq 1 ] ; then
      logit "$I113"
      instexit $RC_ADAPTER
   fi
   # show license agreement if installation required, but no upgrade
   # install LUM license later when successfully installed
   if [ $OPT_SILENT -eq 0 ] && [ -r "$LUM_FILE" ] ; then
      # Find license agreement(LA) and information(LI) files
      # 1. Generate names for LA and LI files
      #    and check if files are in directory license/<$NLS_LANG>
      #
      LA="${LILA_DIR}/LA."$NLS_LANG
      LI="${LILA_DIR}/LI."$NLS_LANG
      #logit "NLS_LANG=$NLS_LANG"
      if [ $OPT_NOLICCHECK -eq 0 ] ; then
         if [ ! -r "$LA" ] || [ ! -r "$LI" ] ; then
            logit "$ENMSG_NOLIC $LA, $LI"
            LA="${LILA_DIR}/LA.en_US"
            LI="${LILA_DIR}/LI.en_US"
         fi
         if [ -r "$LA" ] && [ -r "$LI" ] ; then
            if [ $OPT_NOLIC -eq 0 ] ; then
               # 2. Indicate that LA and LI will be shown
               echo
               echo "$I07"
               echo
               read RES
               # 3. Show the LA_<locale> (License Agreement) file
               more $LA
               # 4. Show the LI_<locale> (License Information) file
               more $LI
               # 5. Ask the user to accept the terms
               echo
               echo "$I08"
               # If users enters "y" license is accepted
               echo
               read RES
               if [ "$RES" != "y" ] && [ "$RES" != "Y" ] ; then
                  echo "$I10"
                  instexit $RC_INST_UNABLE
               else
                  echo "$I11"
               fi
               echo
            else
               echo "WARNING - you must accept license $LA and $LI although it was not shown."
            fi
         else
            logit "$I23"
            instexit $RC_INST_UNABLE
         fi
         # done License Handling
      fi
   fi
fi

# Do install packages in correct order!
logit "$I01$PLATFORM"

if [ "$OS" = AIX ] ; then
   logit "$I47 $AIX_SAMCORE_DIR"
else   
   logit "$I47 $PKGDIR"
fi

if [ $OPT_NONLS -eq 1 ] ; then
   logit "$I97"
fi

if [ $INST_LANG_ONLY -eq 1 ] ; then
   logit "$I98 $SUPP_LANG"
fi

if [ "$OS" = SunOS ] ; then
   PKG_ADM_FILE=`makePkgAdminFile $OVERWRITE`
fi

# install SRC/RSCT on Linux or SunOS if no force option has been specified
if [ $LINUX_OR_SOLARIS -eq 1 ] && [ $DO_FORCE -eq 0 ] ; then
   if [ $INST_LANG_ONLY -eq 0 ] ; then
      #======================================================
      # >>> install prerequesite package "src"
      #
      # check if package at that version is installed
      if [ "$OS" = Linux ] ; then
         installn "src"
      else # Solaris
         installn "IBMsrc"
      fi      
      RC=$?

      #=======================================================
      # >>> install package prerequesite "rsct.core.utils"
      # and install prerequesite package "rsct.core"
      # and install prerequesite package "rsct.basic"
      # together, because they have cross dependencies!!!
      #
      if [ $RC -eq 0 ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils \
                      rsct.core \
                      rsct.basic"
         else # Solaris 
            installn "IBMrsctCoreUtils \
                      IBMrsctCore \
                      IBMrsctBasic"
         fi              
         RC=$?
      fi
      # handle RSCT packages required by CSM, assume Linux only
      if [ "$OS" = Linux ] ; then 
         if [ "$ARCH" = "i386" ] || [ "$ARCH" = "ppc" ] ; then
            if [ $RC -eq 0 ] ; then
               # unconditionally install rsct 64 bit c002
               ARCH_EXT=`arch`
               RSCT64="${PKGDIR}/rsct.64bit-*.${ARCH_EXT}.${PKGEXT}"
               RSCT64=`ls -1 $RSCT64 2>/dev/null`
               if [ -r "$RSCT64" ] ; then
                  installn "rsct.64bit" $ARCH_EXT
                  RC=$?
               fi
               if [ $RC -eq 0 ] ; then
                  # Only if cimrm is installed, upgrade it.
                  rpm -q rsct.core.cimrm 2>/dev/null
                  INSTRC=$?
                  #INSTRC=0
                  #echo "test: INSTRC=0 pretend csm is installed INSTRC=$INSTRC"
                  if [ $INSTRC -eq 0 ] ; then
                     #CSM is installed! must install RSCT packages required by CSM
                     # Check if prereq packages exist and install.
                     CSMPKG="${PKGDIR}/rsct.core.cimrm-*.$ARCH.${PKGEXT}"
                     CSMPKG=`ls -1 $CSMPKG 2>/dev/null`
                     if [ -r "$CSMPKG" ] ; then
                        installn "rsct.core.cimrm"
                        RC=$?
                     fi
                  fi
               fi
            fi
         fi
      fi
      if [ "$OS" = SunOS ] ; then 
         if [ "$ARCH" = "sparc" ] ; then
            if [ $RC -eq 0 ] ; then
               # unconditionally install rsct 64 bit c002
               RSCT64="${PKGDIR}/IBMrsct64bit-*.${ARCH}.${PKGEXT}"
               RSCT64=`ls -1 $RSCT64 2>/dev/null`
               if [ -r "$RSCT64" ] ; then
                  installn "IBMrsct64bit"
                  RC=$?
               fi
            fi
         fi
      fi   
   fi
   if [ $OPT_NONLS -eq 0 ] && [ $RC -eq 0 ] ; then
      #=========================================================
      # src
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "DE" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.de_DE \
                      src.msg.de_DE.ISO-8859-1 \
                      src.msg.de_DE@euro \
                      src.msg.de_DE.UTF-8"
         else # Solaris
            installn "IBMsrcMsg-de_DE-ISO8859-1 \
                      IBMsrcMsg-de_DE-ISO8859-15 \
                      IBMsrcMsg-de_DE-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "ES" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.es_ES \
                      src.msg.es_ES.ISO-8859-1 \
                      src.msg.es_ES@euro \
                      src.msg.es_ES.UTF-8"
         else # Solaris
            installn "IBMsrcMsg-es_ES-ISO8859-1 \
                      IBMsrcMsg-es_ES-ISO8859-15 \
                      IBMsrcMsg-es_ES-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "FR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.fr_FR \
                      src.msg.fr_FR.ISO-8859-1 \
                      src.msg.fr_FR@euro \
                      src.msg.fr_FR.UTF-8"
         else # Solaris
            installn "IBMsrcMsg-fr_FR-ISO8859-1 \
                      IBMsrcMsg-fr_FR-ISO8859-15 \
                      IBMsrcMsg-fr_FR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "IT" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.it_IT \
                      src.msg.it_IT.ISO-8859-1 \
                      src.msg.it_IT@euro \
                      src.msg.it_IT.UTF-8"
         else # Solaris
            installn "IBMsrcMsg-it_IT-ISO8859-1 \
                      IBMsrcMsg-it_IT-ISO8859-15 \
                      IBMsrcMsg-it_IT-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "JP" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.ja_JP.eucJP \
                      src.msg.ja_JP.UTF-8"
         else  #Solaris           
            installn "IBMsrcMsg-ja_JP-eucJP \
                      IBMsrcMsg-ja_JP-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "KR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.ko_KR.eucKR \
                      src.msg.ko_KR.UTF-8"
         else # Solaris
            installn "IBMsrcMsg-ko_KR-EUC \
                      IBMsrcMsg-ko_KR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "BR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.pt_BR \
                      src.msg.pt_BR.UTF-8"
         else # Solaris
            installn "IBMsrcMsg-pt_BR-UTF-8 \
                      IBMsrcMsg-pt_BR-ISO8859-1"
         fi   
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "CN" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.zh_CN.GB2312 \
                      src.msg.zh_CN.GB18030 \
                      src.msg.zh_CN.GBK \
                      src.msg.zh_CN.UTF-8"
         else # Solaris
            installn "IBMsrcMsg-zh_CN-GB18030 \
                      IBMsrcMsg-zh_CN-GBK \
                      IBMsrcMsg-zh_CN-UTF-8 \
                      IBMsrcMsg-zh_CN-EUC"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "TW" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "src.msg.zh_TW \
                      src.msg.zh_TW.Big5 \
                      src.msg.zh_TW.eucTW \
                      src.msg.zh_TW.UTF-8"
         else # Solaris
            installn "IBMsrcMsg-zh_TW-BIG5 \
                      IBMsrcMsg-zh_TW-EUC \
                      IBMsrcMsg-zh_TW-UTF-8"
         fi             
      fi
         # >>> install packages "rsct.*.msg" files
         # rsct.core.utils

      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "DE" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.de_DE \
                      rsct.core.utils.msg.de_DE.ISO-8859-1 \
                      rsct.core.utils.msg.de_DE@euro \
                      rsct.core.utils.msg.de_DE.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-de_DE-ISO8859-1 \
                      IBMrsctCorUtMsg-de_DE-ISO8859-15 \
                      IBMrsctCorUtMsg-de_DE-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "ES" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.es_ES \
                      rsct.core.utils.msg.es_ES.ISO-8859-1 \
                      rsct.core.utils.msg.es_ES@euro \
                      rsct.core.utils.msg.es_ES.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-es_ES-ISO8859-1 \
                      IBMrsctCorUtMsg-es_ES-ISO8859-15 \
                      IBMrsctCorUtMsg-es_ES-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "FR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.fr_FR \
                      rsct.core.utils.msg.fr_FR.ISO-8859-1 \
                      rsct.core.utils.msg.fr_FR@euro \
                      rsct.core.utils.msg.fr_FR.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-fr_FR-ISO8859-1 \
                      IBMrsctCorUtMsg-fr_FR-ISO8859-15 \
                      IBMrsctCorUtMsg-fr_FR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "IT" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.it_IT \
                      rsct.core.utils.msg.it_IT.ISO-8859-1 \
                      rsct.core.utils.msg.it_IT@euro \
                      rsct.core.utils.msg.it_IT.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-it_IT-ISO8859-1 \
                      IBMrsctCorUtMsg-it_IT-ISO8859-15 \
                      IBMrsctCorUtMsg-it_IT-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "JP" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.ja_JP.eucJP \
                      rsct.core.utils.msg.ja_JP.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-ja_JP-eucJP \
                      IBMrsctCorUtMsg-ja_JP-UTF-8" 
         fi                         
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "KR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.ko_KR.eucKR \
                      rsct.core.utils.msg.ko_KR.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-ko_KR-EUC \
                      IBMrsctCorUtMsg-ko_KR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "BR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.pt_BR \
                      rsct.core.utils.msg.pt_BR.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-pt_BR-UTF-8 \
                      IBMrsctCorUtMsg-pt_BR-ISO8859-1"
         fi   
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "CN" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.zh_CN.GB2312 \
                      rsct.core.utils.msg.zh_CN.GB18030 \
                      rsct.core.utils.msg.zh_CN.GBK \
                      rsct.core.utils.msg.zh_CN.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-zh_CN-GB18030 \
                      IBMrsctCorUtMsg-zh_CN-GBK \
                      IBMrsctCorUtMsg-zh_CN-UTF-8 \
                      IBMrsctCorUtMsg-zh_CN-EUC"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "TW" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.utils.msg.zh_TW \
                      rsct.core.utils.msg.zh_TW.Big5 \
                      rsct.core.utils.msg.zh_TW.eucTW \
                      rsct.core.utils.msg.zh_TW.UTF-8"
         else # Solaris
            installn "IBMrsctCorUtMsg-zh_TW-BIG5 \
                      IBMrsctCorUtMsg-zh_TW-EUC \
                      IBMrsctCorUtMsg-zh_TW-UTF-8"
         fi             
      fi
         # rsct.core
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "DE" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.de_DE \
                      rsct.core.msg.de_DE.ISO-8859-1 \
                      rsct.core.msg.de_DE@euro \
                      rsct.core.msg.de_DE.UTF-8"
         else # Solaris
            installn "IBMrsctCorMsg-de_DE-ISO8859-1 \
                      IBMrsctCorMsg-de_DE-ISO8859-15 \
                      IBMrsctCorMsg-de_DE-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "ES" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.es_ES \
                      rsct.core.msg.es_ES.ISO-8859-1 \
                      rsct.core.msg.es_ES@euro \
                      rsct.core.msg.es_ES.UTF-8"
         else # Solaris
            installn "IBMrsctCorMsg-es_ES-ISO8859-1 \
                      IBMrsctCorMsg-es_ES-ISO8859-15 \
                      IBMrsctCorMsg-es_ES-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "FR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.fr_FR \
                      rsct.core.msg.fr_FR.ISO-8859-1 \
                      rsct.core.msg.fr_FR@euro \
                      rsct.core.msg.fr_FR.UTF-8"
         else # Solaris
            installn "IBMrsctCorMsg-fr_FR-ISO8859-1 \
                      IBMrsctCorMsg-fr_FR-ISO8859-15 \
                      IBMrsctCorMsg-fr_FR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "IT" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.it_IT \
                      rsct.core.msg.it_IT.ISO-8859-1 \
                      rsct.core.msg.it_IT@euro \
                      rsct.core.msg.it_IT.UTF-8"
         else # Solaris
            installn "IBMrsctCorMsg-it_IT-ISO8859-1 \
                      IBMrsctCorMsg-it_IT-ISO8859-15 \
                      IBMrsctCorMsg-it_IT-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "JP" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.ja_JP.eucJP \
                      rsct.core.msg.ja_JP.UTF-8"
         else #Solaris
            installn "IBMrsctCorMsg-ja_JP-eucJP \
                      IBMrsctCorMsg-ja_JP-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "KR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.ko_KR.eucKR \
                      rsct.core.msg.ko_KR.UTF-8"
         else # Solaris
            installn "IBMrsctCorMsg-ko_KR-EUC \
                      IBMrsctCorMsg-ko_KR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "BR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.pt_BR \
                      rsct.core.msg.pt_BR.UTF-8"
         else # Solaris
            installn "IBMrsctCorMsg-pt_BR-UTF-8 \
                      IBMrsctCorMsg-pt_BR-ISO8859-1"
         fi   
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "CN" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.zh_CN.GB2312 \
                      rsct.core.msg.zh_CN.GB18030 \
                      rsct.core.msg.zh_CN.GBK \
                      rsct.core.msg.zh_CN.UTF-8"
         else # Solaris
            installn "IBMrsctCorMsg-zh_CN-GB18030 \
                      IBMrsctCorMsg-zh_CN-GBK \
                      IBMrsctCorMsg-zh_CN-UTF-8 \
                      IBMrsctCorMsg-zh_CN-EUC"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "TW" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.core.msg.zh_TW \
                      rsct.core.msg.zh_TW.Big5 \
                      rsct.core.msg.zh_TW.eucTW \
                      rsct.core.msg.zh_TW.UTF-8"
         else # Solaris
            installn "IBMrsctCorMsg-zh_TW-BIG5 \
                      IBMrsctCorMsg-zh_TW-EUC \
                      IBMrsctCorMsg-zh_TW-UTF-8"
         fi             
      fi
         # rsct.basic
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "DE" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.de_DE \
                      rsct.basic.msg.de_DE.ISO-8859-1 \
                      rsct.basic.msg.de_DE@euro \
                      rsct.basic.msg.de_DE.UTF-8"
         else # Solaris
            installn "IBMrsctBasMsg-de_DE-ISO8859-1 \
                      IBMrsctBasMsg-de_DE-ISO8859-15 \
                      IBMrsctBasMsg-de_DE-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "ES" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.es_ES \
                      rsct.basic.msg.es_ES.ISO-8859-1 \
                      rsct.basic.msg.es_ES@euro \
                      rsct.basic.msg.es_ES.UTF-8"
         else # Solaris
            installn "IBMrsctBasMsg-es_ES-ISO8859-1 \
                      IBMrsctBasMsg-es_ES-ISO8859-15 \
                      IBMrsctBasMsg-es_ES-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "FR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.fr_FR \
                      rsct.basic.msg.fr_FR.ISO-8859-1 \
                      rsct.basic.msg.fr_FR@euro \
                      rsct.basic.msg.fr_FR.UTF-8"
         else # Solaris
            installn "IBMrsctBasMsg-fr_FR-ISO8859-1 \
                      IBMrsctBasMsg-fr_FR-ISO8859-15 \
                      IBMrsctBasMsg-fr_FR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "IT" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.it_IT \
                      rsct.basic.msg.it_IT.ISO-8859-1 \
                      rsct.basic.msg.it_IT@euro \
                      rsct.basic.msg.it_IT.UTF-8"
         else # Solaris
            installn "IBMrsctBasMsg-it_IT-ISO8859-1 \
                      IBMrsctBasMsg-it_IT-ISO8859-15 \
                      IBMrsctBasMsg-it_IT-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "JP" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.ja_JP.eucJP \
                      rsct.basic.msg.ja_JP.UTF-8"
         else #Solaris
            installn "IBMrsctBasMsg-ja_JP-eucJP \
                      IBMrsctBasMsg-ja_JP-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "KR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.ko_KR.eucKR \
                      rsct.basic.msg.ko_KR.UTF-8"
         else # Solaris
            installn "IBMrsctBasMsg-ko_KR-EUC \
                      IBMrsctBasMsg-ko_KR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "BR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.pt_BR \
                      rsct.basic.msg.pt_BR.UTF-8"
         else # Solaris
            installn "IBMrsctBasMsg-pt_BR-UTF-8 \
                      IBMrsctBasMsg-pt_BR-ISO8859-1"
         fi   
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "CN" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.zh_CN.GB2312 \
                      rsct.basic.msg.zh_CN.GB18030 \
                      rsct.basic.msg.zh_CN.GBK \
                      rsct.basic.msg.zh_CN.UTF-8"
         else # Solaris
            installn "IBMrsctBasMsg-zh_CN-GB18030 \
                      IBMrsctBasMsg-zh_CN-GBK \
                      IBMrsctBasMsg-zh_CN-UTF-8 \
                      IBMrsctBasMsg-zh_CN-EUC"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "TW" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "rsct.basic.msg.zh_TW \
                      rsct.basic.msg.zh_TW.Big5 \
                      rsct.basic.msg.zh_TW.eucTW \
                      rsct.basic.msg.zh_TW.UTF-8"
         else # Solaris
            installn "IBMrsctBasMsg-zh_TW-BIG5 \
                      IBMrsctBasMsg-zh_TW-EUC \
                      IBMrsctBasMsg-zh_TW-UTF-8"
         fi             
      fi
   fi
elif [ "$OS" = AIX ] && [ $OPT_NOAIXRSCT -eq 0 ] && [ $RC -eq 0 ] ; then
   #---------------------------------
   # install/upgrade RSCT on AIX
   #---------------------------------
   #echo "Test: Try install RSCT for AIX" >> $INST_LOG
   RSCT_INST_FLAG=0
   # RSCT may have to be installed or upgraded
   RSCT_CORE_PKGINST=${PKGDIR}${AIX_SAMCORE_DIR}/rsct/inst/rsct.core
   if [ -r "$RSCT_CORE_PKGINST" ] ; then
      #echo "Test: RSCT_CORE_PKGINST : $RSCT_CORE_PKGINST" >> $INST_LOG
      
      RSCT_CORE_INST=rsct.core.rmc
      RSCT_CORE_PKGINST_VSN=`extractPkgVersion $RSCT_CORE_PKGINST rsct.core.rmc`
      #echo "Test: RSCT_CORE_PKGINST_VSN : $RSCT_CORE_PKGINST_VSN" >> $INST_LOG
      RSCT_CORE_INST_VSN=`extractInstVersion $RSCT_CORE_INST`
      #echo "Test: RSCT_CORE_INST_VSN : $RSCT_CORE_INST_VSN" >> $INST_LOG
      RSCT_INST_FLAG=`getRSCTInstFlags $RSCT_CORE_PKGINST_VSN $RSCT_CORE_INST_VSN`
      #echo "Test: RSCT_INST_FLAG : $RSCT_INST_FLAG" >> $INST_LOG
      
      RSCT_BASIC_INST=rsct.basic.rte
      RSCT_BASIC_INSTVERSION=`extractInstVersion $RSCT_BASIC_INST`
      #echo "Test: RSCT_BASIC_INSTVERSION : $RSCT_BASIC_INSTVERSION" >> $INST_LOG
      RSCTB_INST_FLAG=`getRSCTInstFlags $RSCT_CORE_PKGINST_VSN $RSCT_BASIC_INSTVERSION`
      #echo "Test: RSCTB_INST_FLAG : $RSCTB_INST_FLAG" >> $INST_LOG
      
      INST_ALL=0
      if [ -z "$RSCT_BASIC_INSTVERSION" ] || [ $RSCTB_INST_FLAG -eq $RSCT_INST ] ; then
         # rsct.basic is NOT installed or at a lower version.
         # rsct.basic can only be installed if
         # installed rsct.core version is same or lower than the rsct package version.
         if [ $RSCT_INST_FLAG -eq $RSCT_SAME ] ; then
            # install rsct.basic & storagrm only
            if [ -z "$RSCT_BASIC_INSTVERSION" ] ; then
               logit "$I121"   # message fits only if rsct.basic is not installed
            fi   
            #echo "Test: installp rsct.basic rsct.compat.basic.rte rsct.opt.storagerm"  >> $INST_LOG
            installAIXRSCT inst "rsct.basic rsct.compat.basic.rte rsct.opt.storagerm"
            RC=$?
            if [ $RC -eq 0 ] ; then
               #echo "Test: done installp rsct.basic rsct.compat.basic.rte rsct.opt.storagerm, rc: $RC"  >> $INST_LOG
               logit "$I118 $RSCT_CORE_INST_VSN"
            else
               #echo "Test: Failed install rsct.basic rsct.opt.storagerm for AIX, with rc: $RC"  >> $INST_LOG
               logit "$I114 $RC"
            fi   
         elif [ $RSCT_INST_FLAG -eq $RSCT_INST ] ; then
            INST_ALL=1
         elif [ $RSCT_INST_FLAG -eq $RSCT_ALREADY_INST ] ; then
			# Check if we have a PTF which fits the required version, if so we can install the base version and upgrade
			# with the PTF to reach the required level (upgrade is being done later one in the script)
			
			RSCT_BASIC_PTFPKGINST=`ls -r ${PKGDIR}${AIX_SAMCORE_DIR}/rsct/ptf/*.rsct.basic.rte.bff | cut -d ' ' -f1 | head -1`
			#echo "Test: RSCT_BASIC_PTFPKGINST : $RSCT_BASIC_PTFPKGINST" >> $INST_LOG
			RSCT_BASIC_PTFPKGINST_VSN=`extractPkgVersion $RSCT_BASIC_PTFPKGINST rsct.basic.rte`
			#echo "Test: RSCT_BASIC_PTFPKGINST_VSN : $RSCT_BASIC_PTFPKGINST_VSN" >> $INST_LOG
			RSCTBASIC_INST_FLAG=`getRSCTInstFlags $RSCT_BASIC_PTFPKGINST_VSN $RSCT_CORE_INST_VSN`
			#echo "Test: RSCTBASIC_INST_FLAG : $RSCTBASIC_INST_FLAG" >> $INST_LOG
			
			if [ $RSCTBASIC_INST_FLAG -eq $RSCT_SAME ] || [ $RSCTBASIC_INST_FLAG -eq $RSCT_INST ] ; then
				# same install code as in "if [ $RSCT_INST_FLAG -eq $RSCT_SAME ]"
				# install rsct.basic & storagrm only
	            if [ -z "$RSCT_BASIC_INSTVERSION" ] ; then
	               logit "$I121"   # message fits only if rsct.basic is not installed
	            fi   
	            #echo "Test: installp rsct.basic rsct.compat.basic.rte rsct.opt.storagerm"  >> $INST_LOG
	            installAIXRSCT inst "rsct.basic rsct.compat.basic.rte rsct.opt.storagerm"
	            RC=$?
	            if [ $RC -eq 0 ] ; then
	               #echo "Test: done installp rsct.basic rsct.compat.basic.rte rsct.opt.storagerm, rc: $RC"  >> $INST_LOG
	               logit "$I118 $RSCT_CORE_INST_VSN"
	            else
	               #echo "Test: Failed install rsct.basic rsct.opt.storagerm for AIX, with rc: $RC"  >> $INST_LOG
	               logit "$I114 $RC"
	            fi
			else			
				# Found rsct installed at a higher version, and therefore cannot install rsct.basic at the lower
				# package version.
				#echo "Test: installed version > package version ($RSCT_CORE_INST_VSN>$RSCT_CORE_PKGINST_VSN), cannot install rsct.basic" >> $INST_LOG
				logit "$I122 $RSCT_CORE_INST_VSN > $RSCT_CORE_PKGINST_VSN"
				RC=$RC_INST_UNABLE
			fi
         fi      
      elif [ $RSCT_INST_FLAG -eq $RSCT_INST ] ; then   
         # rsct.basic is installed at any lower version, indicate that install all needed
         INST_ALL=1
      elif [ $RSCT_INST_FLAG -eq $RSCT_ALREADY_INST ] || [ $RSCT_INST_FLAG -eq $RSCT_SAME ] ; then
         # Need not install rsct.core, equal/higher version found for rsct.core
         logit "$I120 $RSCT_CORE_PKGINST_VSN (rsct.core.rmc)"
      fi
      if [ $INST_ALL -eq 1 ] ; then
         # install all rsct packages w/o message packages
         RSCT_PKGS=`ls ${PKGDIR}${AIX_SAMCORE_DIR}/rsct/inst/* | $GREP -v rsct.msg* | sed s/".*\/rsct\/inst\/"//g 2>/dev/null`
         #echo "Test: installp (all rsct): '$RSCT_PKGS'" >> $INST_LOG
         logit "$I115 $RSCT_CORE_PKGINST_VSN"
         installAIXRSCT inst "$RSCT_PKGS"
         RC=$?
         #echo "Test: done installp (all rsct): '$RSCT_PKGS', rc=$RC" >> $INST_LOG
         if [ $RC -eq 0 ] ; then
            logit "$I118 $RSCT_CORE_PKGINST_VSN"
            if [ $OPT_NONLS -eq 0 ] ; then
               RSCT_MSG_PKGS=`ls ${PKGDIR}${AIX_SAMCORE_DIR}/rsct/inst/rsct.msg.* 2>/dev/null | sed s/".*\/rsct\/inst\/"//g 2>/dev/null`
               if [ -n "$RSCT_MSG_PKGS" ] ; then
                  if [ $INST_LANG_ONLY -eq 0 ] ; then
                     # rsct contains more than the 9 primary langauges
                     # install all of them if no specfic language selected
                     #echo "Test: install all rsct NLS..."   >> $INST_LOG
                     logit "$I115 $RSCT_CORE_PKGINST_VSN (rsct.msg.*)"
                     installAIXRSCT inst $RSCT_MSG_PKGS
                     RC=$?
                     #echo "Test: ... done install all rsct NLS"  >> $INST_LOG
                     if [ $RC -eq 0 ] ; then
                        logit "$I118 $RSCT_CORE_PKGINST_VSN (rsct.msg.*)"
                     else
                        logit "$I114 $RC (rsct.msg.*)"
						RC=0
                     fi
                  elif [ $RSCT_INST_FLAG -eq $RSCT_SAME ] || [ $RSCT_PTF_FLAG -eq $RSCT_UPG ] ; then 
                     # install by language
                     logit "$I98 $SUPP_LANG"
                     if [ "$SUPP_LANG" = "DE" ] ; then
                        installAIXRSCT inst "rsct.msg.DE_DE rsct.msg.de_DE"
                     fi
                     if [ "$SUPP_LANG" = "ES" ] ; then
                        installAIXRSCT inst "rsct.msg.ES_ES rsct.msg.es_ES"
                     fi
                     if [ "$SUPP_LANG" = "FR" ] ; then
                        installAIXRSCT inst "rsct.msg.FR_FR rsct.msg.fr_FR"
                     fi
                     if [ "$SUPP_LANG" = "IT" ] ; then
                        installAIXRSCT inst "rsct.msg.IT_IT rsct.msg.it_IT"
                     fi
                     if [ "$SUPP_LANG" = "JP" ] ; then
                        installAIXRSCT inst "rsct.msg.JA_JP rsct.msg.Ja_JP rsct.msg.ja_JP"
                     fi
                     if [ "$SUPP_LANG" = "KR" ] ; then
                        installAIXRSCT inst "rsct.msg.KO_KR rsct.msg.ko_KR"
                     fi
                     if [ "$SUPP_LANG" = "BR" ] ; then
                        installAIXRSCT inst "rsct.msg.PT_BR rsct.msg.pt_BR"
                     fi
                     if [ "$SUPP_LANG" = "CN" ] ; then
                        installAIXRSCT inst "rsct.msg.ZH_CN rsct.msg.Zh_CN"
                     fi
                     if [ "$SUPP_LANG" = "TW" ] ; then
                        installAIXRSCT inst "rsct.msg.ZH_TW rsct.msg.Zh_TW rsct.msg.zh_TW"
                     fi
                  else
                     echo "Error: No RSCT message packages found in installation directory"  >> $INST_LOG   
                  fi      
               else
                  echo "Error: No RSCT message packages found in installation directory"  >> $INST_LOG     
               fi
            else
               logit "$I97"      
            fi   
         else
            #echo "Test: Failed install all rsct for AIX :'$RSCT_PKGS' with rc: $RC"  >> $INST_LOG
            logit "$I114 $RC"   
         fi   
      fi
      if [ $RC -eq 0 ] ; then
         # Check if PTF to install
         RSCT_BASIC_PKGPTF=`ls ${PKGDIR}${AIX_SAMCORE_DIR}/rsct/ptf/*rsct.basic.rte.bff 2>/dev/null`
         #echo "Test: looking for RSCT_BASIC_PKGPTF: $RSCT_BASIC_PKGPTF"  >> $INST_LOG
         if [ -r "$RSCT_BASIC_PKGPTF" ] ; then
            #echo "Test: found RSCT_BASIC_PKGPTF: $RSCT_BASIC_PKGPTF"  >> $INST_LOG
            # see if need to install PTF by comparing versions of PTF package
            # and installed version
            RSCT_BASIC_PKGPTF_VSN=`extractPkgVersion $RSCT_BASIC_PKGPTF rsct.basic.rte`
            #echo "Test: RSCT_BASIC_PKGPTF_VSN: $RSCT_BASIC_PKGPTF_VSN"  >> $INST_LOG
            RSCT_BASIC_INST_VSN=`extractInstVersion $RSCT_BASIC_INST`
            #echo "Test: Installed rsct.basic.rte version: $RSCT_BASIC_INST_VSN"  >> $INST_LOG
            RSCT_PTF_FLAG=`getRSCTInstFlags $RSCT_BASIC_PKGPTF_VSN $RSCT_BASIC_INST_VSN`
            if [ $RSCT_PTF_FLAG -eq $RSCT_UPG ] ; then
               #echo "Test: Upgrade with RSCT PTF from $RSCT_BASIC_INST_VSN to $RSCT_BASIC_PKGPTF_VSN"  >> $INST_LOG
               logit "$I117 $RSCT_BASIC_PKGPTF_VSN"
               installAIXRSCT ptf
               RC=$?
               if [ $RC -eq 0 ] ; then
                  #echo "Test: done upgrade installp rsct to $RSCT_BASIC_PKGPTF_VSN rc: $RC"  >> $INST_LOG
                  logit "$I119 $RSCT_BASIC_PKGPTF_VSN"
               else
                  #echo "Test: Failed upgrade installp rsct to $RSCT_BASIC_PKGPTF_VSN rc: $RC"  >> $INST_LOG
                  logit "$I116 $RC"
               fi
            else 
               #echo "Test: no upgrade ? RSCT_PTF_FLAG: $RSCT_PTF_FLAG"  >> $INST_LOG
               # Need not upgrade rsct, equal/higher version found for rsct.core
               logit "$I120 $RSCT_BASIC_INST_VSN"      
            fi
         #else
            #echo "Test: No RSCT PTF yet"  >> $INST_LOG     
         fi
      #else
         #echo "Test: failed to install RSCT"  >> $INST_LOG   
      fi
   #else 
      #echo "Test: Warning: AIX RSCT package $RSCT_CORE_PKGINST not found. Installation of RSCT for AIX suppressed." >> $INST_LOG
   fi   
   #echo "Test: exit"
   #exit 1      
fi
#echo "Test: before install sam  rc: $RC"

if [ $INST_LANG_ONLY -eq 0 ] && [ $RC -eq 0 ] ; then
   #=========================================================
   # >>> install package "sam" (SAMP)
   #
   # Only for package sam, sam*msg and sam.adapter use options (like --force)
   USE_OPTIONS=1
   #echo "test:: OPT_FORCE=$OPT_FORCE"
   if [ $RC -eq 0 ] ; then
      if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam"
         else    
            installn "IBMsam"
         fi   
         RC=$?
      else
         installn "sam.core"
         RC=$?
      fi
   fi
   USE_OPTIONS=0
fi

#=========================================================
# >>> install packages "sam.msg" (SAMP NLS)
#
if [ $OPT_NONLS -eq 0 ] && [ $RC -eq 0 ] ; then
   if [ $LINUX_OR_SOLARIS -eq 1 ] ; then
      # not AIX
      # sam
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "DE" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.de_DE \
                      sam.msg.de_DE.ISO-8859-1 \
                      sam.msg.de_DE@euro \
                      sam.msg.de_DE.UTF-8"
         else # Solaris
            installn "IBMsamMsg-de_DE-ISO8859-1 \
                      IBMsamMsg-de_DE-ISO8859-15 \
                      IBMsamMsg-de_DE-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "ES" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.es_ES \
                      sam.msg.es_ES.ISO-8859-1 \
                      sam.msg.es_ES@euro \
                      sam.msg.es_ES.UTF-8"
         else # Solaris
            installn "IBMsamMsg-es_ES-ISO8859-1 \
                      IBMsamMsg-es_ES-ISO8859-15 \
                      IBMsamMsg-es_ES-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "FR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.fr_FR \
                      sam.msg.fr_FR.ISO-8859-1 \
                      sam.msg.fr_FR@euro \
                      sam.msg.fr_FR.UTF-8"
         else # Solaris
            installn "IBMsamMsg-fr_FR-ISO8859-1 \
                      IBMsamMsg-fr_FR-ISO8859-15 \
                      IBMsamMsg-fr_FR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "IT" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.it_IT \
                      sam.msg.it_IT.ISO-8859-1 \
                      sam.msg.it_IT@euro \
                      sam.msg.it_IT.UTF-8"
         else # Solaris
            installn "IBMsamMsg-it_IT-ISO8859-1 \
                      IBMsamMsg-it_IT-ISO8859-15 \
                      IBMsamMsg-it_IT-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "JP" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.ja_JP.eucJP \
                      sam.msg.ja_JP.UTF-8"
         else # Solaris
            installn "IBMsamMsg-ja_JP-eucJP \
                      IBMsamMsg-ja_JP-UTF-8"
         fi
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "KR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.ko_KR.eucKR \
                      sam.msg.ko_KR.UTF-8"
         else # Solaris
            installn "IBMsamMsg-ko_KR-EUC \
                      IBMsamMsg-ko_KR-UTF-8"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "BR" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.pt_BR \
                      sam.msg.pt_BR.UTF-8"
         else # Solaris
            installn "IBMsamMsg-pt_BR-UTF-8 \
                      IBMsamMsg-pt_BR-ISO8859-1"
         fi   
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "CN" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.zh_CN.GB2312 \
                      sam.msg.zh_CN.GB18030 \
                      sam.msg.zh_CN.GBK \
                      sam.msg.zh_CN.UTF-8"
         else # Solaris
            installn "IBMsamMsg-zh_CN-GB18030 \
                      IBMsamMsg-zh_CN-GBK \
                      IBMsamMsg-zh_CN-UTF-8 \
                      IBMsamMsg-zh_CN-EUC"
         fi             
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "TW" ] ; then
         if [ "$OS" = Linux ] ; then
            installn "sam.msg.zh_TW \
                      sam.msg.zh_TW.Big5 \
                      sam.msg.zh_TW.eucTW \
                      sam.msg.zh_TW.UTF-8"
         else # Solaris
            installn "IBMsamMsg-zh_TW-BIG5 \
                      IBMsamMsg-zh_TW-EUC \
                      IBMsamMsg-zh_TW-UTF-8"
         fi             
      fi
   else # is AIX
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "DE" ] ; then
         installn "sam.msg.DE_DE"
         installn "sam.msg.de_DE"
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "ES" ] ; then
         installn "sam.msg.ES_ES"
         installn "sam.msg.es_ES"
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "FR" ] ; then
         installn "sam.msg.FR_FR"
         installn "sam.msg.fr_FR"
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "IT" ] ; then
         installn "sam.msg.IT_IT"
         installn "sam.msg.it_IT"
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "JP" ] ; then
         installn "sam.msg.JA_JP"
         installn "sam.msg.Ja_JP"
         installn "sam.msg.ja_JP"
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "KR" ] ; then
         installn "sam.msg.KO_KR"
         installn "sam.msg.ko_KR"
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "BR" ] ; then
         installn "sam.msg.PT_BR"
         installn "sam.msg.pt_BR"
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "CN" ] ; then
         installn "sam.msg.ZH_CN"
         installn "sam.msg.Zh_CN"
      fi
      if [ -z "$OPT_LANG" ] || [ "$SUPP_LANG" = "TW" ] ; then
         installn "sam.msg.ZH_TW"
         installn "sam.msg.Zh_TW"
         installn "sam.msg.zh_TW"
      fi
   fi
fi

if [ $INST_LANG_ONLY -eq 0 ] ; then
   # Handle special package xdrsl10 for SUSE SLES10 on all platforms c003
   # check distro
   if [ "$OS" = Linux ] ; then
      IS_VERSION=`cat  /etc/SuSE-release 2>/dev/null`
      if [ -n "$IS_VERSION" ] ; then
         COUNT=`echo $IS_VERSION | $GREP -Ec "SLES|SuSE.*Enterprise Server|SUSE.*Enterprise Server"`
         if [ $COUNT -eq 1 ] ; then
            # distro is SUSE - check version
            VSN_IS=`echo $IS_VERSION | $GREP VERSION | sed s/".*VERSION = "// | sed s/" PATCHLEVEL.*"//`
            if [ "$VSN_IS" = "10" ] ; then
               # is SLES10 - install package
               installn "xdrsl10"
            fi
         fi
      fi
   fi
fi

#=========================================================
# >>> install optional rsct storagerm
#
if [ $RC -eq 0 ] && [ $LINUX_OR_SOLARIS -eq 1 ] && [ $INST_LANG_ONLY -eq 0 ] ; then
  if [ "$OS" = Linux ] ; then
     STRM="${PKGDIR}/rsct.opt.storagerm-*.$ARCH.${PKGEXT}"
     STRM=`ls -1 $STRM 2>/dev/null`
     if [ -r "$STRM" ] ; then
        installn "rsct.opt.storagerm"
     fi    
  else # Solaris   
     STRM="${PKGDIR}/IBMrsctOptStoragerm-*.$ARCH.${PKGEXT}"
     STRM=`ls -1 $STRM 2>/dev/null`
     if [ -r "$STRM" ] ; then
        installn "IBMrsctOptStoragerm"
     fi    
  fi
fi


#=========================================================
# >>> install package "sam.adapter" (ITSAMP E2E adapter) and java
#
if [ $OPT_NOADAPTER -eq 0 ] && [ $RC -eq 0 ] && [ $INST_LANG_ONLY -eq 0 ] ; then
   if [ -z "$FIRST_ERROR" ] ; then
      # check if samadapter is running - must be stopped
      if [ -x "$ADAPTER_DIR/bin/$ADAPTER" ] ; then
         # command exists - see if adapter is started
         $ADAPTER_DIR/bin/$ADAPTER status >/dev/null
         RC=$?
         if [ $RC -eq 1 ] ; then
            logit
            logit "$I35"
            instexit $RC_INST_UNABLE
         fi
      fi
      # Reset RC from adapter test
      RC=0
      # install adapter
      case "$OS" in
         AIX|Linux) 
             installn "sam.adapter"
             RC=$?
         ;;
         SunOS) 
             installn "IBMsamAdapter"
             RC=$?
         ;;
      esac              
      if [ $RC -eq 0 ] ; then
         #==================================================
         # Java installation
         #==================================================
         MUST_JAVA=0
         #-- determine Java package -------------------
         JAVAPKG=""
         EXJPKG=""
         ISJVERSION="0"
         case "$OS" in
             AIX) 
                  # For IBM OS (like AIX) java must not be installed.
             ;;
             Linux)
                  JAVAPAT=${PKGDIR}/"java.$OS.$ARCH.tgz"
                  JAVAPKG=`ls -1 $JAVAPAT 2>/dev/null`
             ;;
             SunOS)
                  JAVAPAT=${PKGDIR}/"java.$OS.$ARCH.tar.Z"
                  JAVAPKG=`ls -1 $JAVAPAT 2>/dev/null`
             ;;     
             *)     logit "$ENMSG_NOARCH"
             ;;
         esac

         # check if version is less
         case "$OS" in
             AIX)   EXJPKGS=`lslpp -l Java* | $GREP -E "ava.*.(rte|sdk)" | $GREP -Ev ".*64.*"`
                    if [ -n "$EXJPKGS" ] ; then
                       for EXJPKG in $EXJPKGS
                       do
                          # take only first 2 digits
                          ISJV=`echo $EXJPKG  | sed 's/[1-9]\{1,\}\.[0-9]\{1,\}/#&#/g' | cut -s -d "#" -f2 | sed 's/\.//g'`
                          if [ "$ISJVERSION" -lt "$ISJV" ] ; then
                             ISJVERSION=$ISJV
                             ISJPKG=$EXJPKG
                          fi
                       done
                    fi
                    #echo "Test - EXJPKG: $ISJPKG"
                    #echo "Test - architecture: $ARCH"
                    #echo "Test - is java version      : $ISJVERSION"
                    #echo "Test - required java version: $AIX_REQ_JAVA_VERSION"
                    JERR=0
                    if [ "$ISJVERSION" = "0" ] ; then
                       # no java exists
                       logit "$I37 $AIX_REQ_JAVA_VERSION"
                       JERR=1
                    elif [ "$ISJVERSION" -lt "$AIX_REQ_JAVA_VERSION" ] ; then
                       # version too low
                       logit "$I36 $ISJPKG"
                       logit "$I37 $AIX_REQ_JAVA_VERSION"
                       JERR=1
                    fi
                    if [ $JERR -eq 0 ] ; then
                       # set link required by JDBCPublisher
                       JPATH=`getJavaPath`
                       ISJPATH=`echo "$JPATH" | $GREP -c "\/jre"`
                       if [ $ISJPATH -eq 0 ] ; then
                          logit "$JPATH"      # jpath is non NLS AIX java error message
                       elif [ -n "$JPATH" ] ; then
                          ln -s ${JPATH}/jre  /opt/IBM/tsamp/sam/java/jre
                       else
                          logit "Cannot find java path on $OS to set link to java."   # unlikely
                       fi
                    fi   
             ;;
             Linux|SunOS)
                    JPATH=`getJavaPath`
                    MUST_JAVA=1
             ;;
             *)     logit "$ENMSG_NOARCH"
             ;;
         esac

         if [ $MUST_JAVA -eq 1 ] ; then
            #==================================================
            # Install Java
            #==================================================
            case "$OS" in
                AIX)   #echo "Test - Java is never installed for AIX - package:"
                       #echo "Test - must be package $ISJPKG"
                ;;
                Linux) mkdir -p "$JPATH"
                       if [ -d "$JPATH" ] ; then
                          if [ -z "$JAVAPKG" ] ; then
                             logit "$I14$JAVAPAT"
                          else
                             # remove existing Java
                             rm -rf $JPATH/jre
                             rm -rf $JPATH/docs
                             tar zxf $JAVAPKG --directory=$JPATH
                             # apply chcon to avoid VM aborting on RH selinux
                             chcon -t textrel_shlib_t $JPATH/jre/bin/j9vm/lib*.so 2>/dev/null
                             chcon -t textrel_shlib_t $JPATH/jre/bin/lib*.so 2>/dev/null
                          fi
                       fi
                ;;
                SunOS) mkdir -p "$JPATH"
                       if [ -d "$JPATH" ] ; then
                          if [ -z "$JAVAPKG" ] ; then
                             logit "$I14$JAVAPAT"
                          else
                             # remove existing Java
                             rm -rf $JPATH/jre
                             mkdir -p $JPATH/jre
                             # make an absolute path of the Java package, 
                             # because tar on SunOS does not handle --directory option.
                             DJ=`dirname "$JAVAPKG"`
                             BJ=`basename "$JAVAPKG"`
                             JAVAPKG="`cd \"$DJ\" 2>/dev/null && pwd || echo \"$DJ\"`/$BJ"
                             #echo "Test:: absolute java pkg: $JAVAPKG"
                             CPATH=`pwd`
                             cd $JPATH/jre
                             zcat $JAVAPKG | tar -xf -  >TMP_STDERR 2>&1
                             RC=$?
                             if [ $RC -eq 0 ] ; then
                                logit "$I124 $JAVAPKG"
                             else
                                saveInstErrorMsgs $RC $JAVAPKG
                             fi       
                             #echo "Test:: zcat / tar into $JPATH/jre, rc=$?"
                             cd "$CPATH"
                          fi
                       fi
                ;;
                *)     logit "$ENMSG_NOARCH"
                ;;
            esac
         fi
      fi
   fi
fi

# Done with installation

if [ $INST_LANG_ONLY -eq 0 ] ; then
   # Check what was installed
   SHOW_INST=0
   case "$OS" in
      Linux) DONE=`rpm -qa | $GREP -E "^src-|^src\.|^rsct|^sam-|^sam\." |sort`
             if [ -n "$DONE" ] ; then
                SHOW_INST=1
             fi
      ;;
      SunOS) DONE=`pkginfo -x | $GREP -E "^IBMsrc|^IBMrsct|^IBMsam" | awk '{print $1}' | sort`
             if [ -n "$DONE" ] ; then
                SHOW_INST=1
             fi
             JUNK=rmvPkgAdminFile 
      ;;
      AIX) DONE=`lslpp -l "sam*" 2>/dev/null |$GREP -E "^sam-|^sam\." |sort`
           RC=$?
           if [ $RC -eq 0 ] && [ -n "$DONE" ] ; then
              SHOW_INST=1
           fi
      ;;
   esac

   # Show what was installed
   if [ $SHOW_INST -eq 1 ] ; then
      logit "$I05"
      for DONE1 in $DONE
      do
         logit " $DONE1"
      done
   fi

   # verify again if sam is installed
   checkSAMInst
fi

if [ $ERROR -eq 0 ] && [ $INST_LANG_ONLY -eq 0 ] ; then
   # install LUM license
   logit ""
   installLUM $LUM_FILE $FULL_LIC_INST $TB_LIC_PKG
   if [ -d "$LIC_DIR" ] ; then
      # handle ITLM sys file
      
      # 1. remove old ITLM sys files
      rm $LIC_DIR/*.sys $LIC_DIR/*.SYS2 2>/dev/null
      
      # 2. install new ITLM sys file
      if [ -n $ITLM_FILE ] ; then
         cp $ITLM_FILE $LIC_DIR
      fi
      
      # 3. install xdr ITLM sys file if we are on z/Linux
      if [ "$OS" = "Linux" ] && [ "$ARCH" = "s390" ] ; then
         if [ -n $ITLM_FILE_XDR ] ; then
            cp $ITLM_FILE_XDR $LIC_DIR
	     fi
      fi
   fi
fi

if [ $ERROR -eq 0 ] && [ $INST_LANG_ONLY -eq 0 ] ; then
   if [ $ANY_INST -eq 1 ] ; then
      logit "$I06"
   fi
   # show RMs active (NLS!)
   # RMs that are inoperative show no processid (NF=3)
   if [ $OPT_SILENT -eq 0 ] ; then
      lssrc -a | $GREP "Subsystem.*\|rsct.*" | awk '{if (NF==4)print}'
   fi
   lssrc -a | $GREP "Subsystem.*\|rsct.*" | awk '{if (NF==4)print}' >> $INST_LOG

   # test for CT_MANAGEMENT_SCOPE: if exists use value, otherwise use -1
   SCOPE_VAR=${CT_MANAGEMENT_SCOPE:-1}
   if [ "$SCOPE_VAR" != 2 ] ; then
      logit "$I24"
   fi
fi

INST_RC=0
# check for errors
if [ $ERROR -eq 1 ] ; then
   INST_RC=$RC_INSTALLER_ERROR
   logit "$I27"
   if [ -n "$FIRST_ERROR" ] ; then
      # logs installer error return code
      if [ $OPT_SILENT -eq 0 ] ; then
         echo $FIRST_ERROR
      fi
      echo $FIRST_ERROR >> $INST_LOG
   elif [ -n "$FIRST_WARN" ] ; then
      if [ $OPT_SILENT -eq 0 ] ; then
         echo $FIRST_WARN
      fi
      echo $FIRST_WARN >> $INST_LOG
   fi
   if [ -r "$TMP_FIRST_STDERR" ] ; then
      if [ $OPT_SILENT -eq 0 ] ; then
         cat $TMP_FIRST_STDERR
      fi
      cat $TMP_FIRST_STDERR >> $INST_LOG
      logit ""
   fi
else
   if [ $ANY_INST -ne 0 ] ; then
      logit ""
      logit "$I26"
   fi
fi

if [ $INST_LANG_ONLY -eq 0 ] ; then
   copyUninst #c001
fi
instexit $INST_RC
