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

# @(#) SetPerm - performs post-installation operations specific to
# @(#) select products.  These operations must be performed by root.

############ Last six mods ######################################
# @13 07/03/07 AB  Fixed component name displaying
# @12 12/23/03 LCL Set root ownership for kddos64
# @11 09/23/03 LCL Set link for aix433.
# @10 08/06/03 LCL Set permissions for UL on Linux
# @09 08/06/03 LCL Switch to chgrp 0 for aix stat_daemon.
# @08 02/06/03 LCL Add sol29 support
# @07 12/13/02 LCL Convert fail to warn so links can create; 1-22353127
# @06 10/23/02 J1091 Added setDDArch function.
# @05 10/02/02 LCL add UL aix43 link;CMS sol25 link; 1-20536554,1-20536601
###################################################################

Err_report()
{
  case $1 in
    #$NLS-E$ "$PROGNAME warning:  $2, continuing ..."
    warn) print -u2  "$PROGNAME `nls_replace 'KCI0535I'`:  $2, `nls_replace 'KCI0536I'` ..."
          sleep 2
          return
          ;;
	#$NLS-E$ "$PROGNAME warning:  $2, $3"
    warn2) print -u2  "$PROGNAME `nls_replace 'KCI0535I'`:  $2, $3"
          sleep 2
          return
          ;;
	#$NLS-E$ "$PROGNAME failure:  $2."
    fail) print -u2 "$PROGNAME `nls_replace 'KCI0537I'`:  $2."
          rm -f $tmpFile > /dev/null 2>&1
          exit 74  # Must exit with zero or 74, or setagentperm will loop.
          ;;
    info) print -u2 "$PROGNAME        :  $2."
          return
          ;;
  esac
}

Use_report()
{
  print
  print  -u2 "$PROGNAME [ -h CANDLEHOME ]"
  #$NLS-E$ " Set permissions in interactive mode. \n"
  nls_replace 'KCI0600I'
  print
  print -u2 "$PROGNAME [ -h CANDLEHOME ] -a"
  #$NLS-E$ " Set permissions in noninteractive mode. \n"
  nls_replace 'KCI0601I'
  print
  print -u2 "$PROGNAME [ -h CANDLEHOME ] -s"
  #$NLS-E$ " Set security validation on selected TEMS's. \n"
  nls_replace 'KCI0602I'
  print
#  print -u2 "$PROGNAME [ -h CANDLEHOME ] *.ver *.ver *.ver ..."  # Not documented.
#IY77938#
#  print -u2 "$PROGNAME [ -h CANDLEHOME ] -s TEMSname"  # Not documented.
  exit 0  # Must exit with zero or 74, or setagentperm will loop.
}

# @06 - Determine the arch of the common database code (dd).

setDDArch()
{
  # $1 = the name of the product's .ver file

  typeset vFile=$CANDLEHOME/registry/$1
  [ -r $vFile ] || return

  ddArch=$(grep " *preReqALL *= *dd" $vFile | cut -d "=" -f2 | cut -d "|" -f1)
  if [ -n "$ddArch" ]
  then
    ddArch=$(print $ddArch | cut -c3-)
    [ -n "$ddArch" ] && return
  fi

  # Try just plain "preReq".

  ddArch=$(grep " *preReq *= *dd" $vFile | cut -d "=" -f2 | cut -d "|" -f1)
  if [ -n "$ddArch" ]
  then
    ddArch=$(print $ddArch | cut -c3-)
    [ -n "$ddArch" ] && return
  fi

  # If no "dd" prereq could be found, use the bin arch of the product.

  ddArch=${1%.ver}  # Remove the extension.
  ddArch=$(print $ddArch | cut -c3-)  # Get the architecture.
}
# Process the database agents.

procDB()
{
  # $1 is the name of the product's .ver file.

  # Define local variables.
  typeset kddos binArch

  setDDArch $1

  kddos=$CANDLEHOME/$ddArch/bin/kddos
  [ -r $kddos ] || return
  chown root $kddos > /dev/null 2>&1
  #$NLS-E$ "could not change the owner of \"$kddos\""
  [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0603E' \\"$kddos\\"`"

  chmod 4755 $kddos > /dev/null 2>&1
  #$NLS-E$ "could not change the permissions on \"$kddos\""
  [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0604E' \\"$kddos\\"`"

  # Added for 64-bit support requested by developer Sanjay Bhojani
  kddos64=$CANDLEHOME/$ddArch/bin/kddos64

  if [ -x $kddos64 ] ; then
    chown root $kddos64 > /dev/null 2>&1
	#$NLS-E$  "could not change the owner of \"$kddos64\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0603E' \\"$kddos64\\"`"

    chmod u+xs $kddos64 > /dev/null 2>&1
	#$NLS-E$ "could not change the permissions on \"$kddos64\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0604E' \\"$kddos64\\"`"
  fi

  binArch=${1%.ver}  # Remove the extension.
  binArch=$(print $binArch | cut -c3-)  # Get the architecture.

  # procLinkU is done for all products now
}

# Process Command Pro (cz).

procCZ()
{
  # $1 is the name of the product's .ver file.

  # Define local variables.
  typeset binArch binDir files linkName name sys

  files="kumsnetd"
  sys=sys  # Use for HP-UX and Solaris.

  binArch=${1%.ver}  # Remove the extension.
  binArch=$(print $binArch | cut -c3-)  # Get the architecture.
  [[ "$binArch" = aix+([0-9]) ]] && sys=system

  if [[ "$binArch" = "ccp" ]]
  then
   return
  fi

  binDir=$CANDLEHOME/$binArch/cz/bin
  for name in $files
  do
    [ -r $binDir/$name ] || continue
    chown root $binDir/$name > /dev/null 2>&1
	#$NLS-E$ "could not change the owner of \"$name\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0603E' \\"$name\\"`"
    chmod 4755 $binDir/$name > /dev/null 2>&1
	#$NLS-E$ "could not change the permissions on \"$name\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0604E' \\"$name\\"`"
    chgrp $sys $binDir/$name > /dev/null 2>&1
	#$NLS-E$ "could not change the group for \"$name\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0605E' \\"$name\\"`"
  done
}

# Softlink for all products
# $1 = verFile

procLinkU()
{
  pc=$(print $1 | cut -c1,2)  # Get the 2-character product code.
  lName=$(print $1 | cut -c3- | cut -d"." -f1)
  #$NLS-E$ "could not determine the link name"
  [ -n "$lName" ] || Err_report fail "`nls_replace 'KCI0606E'`"
  if [[ "$pc" = ax ]]; then
    lArch=$lName
    procLinkU2 $lArch $lArch
    axReq=$(print $1 | cut -d"." -f1)
    # Note we only get the first ax pre-req, therefore if the ver file contains
    # more than one ax pre-req, one of the other pre-req components must include
    # the second ax pre-req or the second link will not be created.
    # Note: grep -H is not supported on all platforms.
    vFiles=$(cd $regDir; for vf in *.ver ; do
               print "$vf:$(grep "preReq[A-Z]* = ax" $vf | head -1)" |
               grep "preReq[A-Z]* = $axReq" | cut -d: -f1
             done)
    for file in $vFiles ; do
      lName=$(print $file | cut -c3- | cut -d"." -f1)
      procLinkU2 $lName $lArch
    done
  else
    vFile=$regDir/$1
    # Get the libArch.  The sed is needed to remove the space after the "=".
    # Note we only get the first ax pre-req, therefore if the ver file contains
    # more than one ax pre-req, one of the other pre-req components must include
    # the second ax pre-req or the second link will not be created.
    lArch=$(grep "preReq[A-Z]* = ax" $vFile | cut -d"=" -f2 | sed "s/^  *//" | cut -c3- | cut -d"|" -f1 | head -1)
    [ -n "$lArch" ] || return # if this product doesn't prereq ax
    procLinkU2 $lArch $lArch
    procLinkU2 $lName $lArch
  fi
}

procLinkU2()
{
  # set -x
  linkName=$1
  libArch=$2
  optLib=/opt/IBM/ITM/tmaitm6/links
  # If the lib directory for the platform from the pc<plat>.ver exists
  #  Do not create a link from one architecture to another
  # otherwise
  #  Do create a link from one architecture to another
  #  for agents built on one platform that use shared libs on another
  if [ -d "$CANDLEHOME/tmaitm6/$linkName/lib" ]
  then
    libArch=$linkName
  fi
  [[ "$linkName" = sol606 ]] && linkName=sos510amdx6    # 64-bit solaris 10 opteron
  [[ "$linkName" = sol293 ]] && linkName=sos59    # 32-bit solaris 9
  [[ "$linkName" = sol296 ]] && linkName=sos59x6  # 64-bit solaris 9
  [[ "$linkName" = sol283 ]] && linkName=sos58    # 32-bit solaris 8
  [[ "$linkName" = sol286 ]] && linkName=sos58x6  # 64-bit solaris 8
  [[ "$linkName" = aix5+([23])3 ]] && linkName=aix52    # 32-bit aix 5.2+
  [[ "$linkName" = aix5+([23])6 ]] && linkName=aix52x6  # 64-bit aix 5.2+
  [[ "$linkName" = hp11 ]] && linkName=hpx1111          # 32-bit hp
  [[ "$linkName" = hp+([0-9])3 ]] && linkName=hpx1111   # 32-bit hp
  [[ "$linkName" = hp+([0-9])6 ]] && linkName=hpx1111x6 # 64-bit hp
  [[ "$linkName" = hpi+([0-9])3 ]] && linkName=hpx1123ia   # 32-bit hp
  [[ "$linkName" = hpi+([0-9])6 ]] && linkName=hpx1123iax6 # 64-bit hp
  [[ "$linkName" = lia266 ]] && linkName=lnxiax6-l22-g32 # 64-bit Itanium
  [[ "$linkName" = li6242 ]] && linkName=lnxx86-l22-g296       # RH 2
  [[ "$linkName" = li624+([36]) ]] && linkName=lnxx86-l22-g32  # RH 3+, SLES 8
  [[ "$linkName" = li626+([236]) ]] && linkName=lnxx86-l23-g33 # SLES 9
  [[ "$linkName" = ls3243 ]] && linkName=lnxz-l22-g32   # 32-bit z RH 3, SLES 8
  [[ "$linkName" = ls3246 ]] && linkName=lnxzx6-l22-g32 # 64-bit z RH 3, SLES 8
  [[ "$linkName" = ls3263 ]] && linkName=lnxz-l23-g33   # 32-bit z RH 4, SLES 9
  [[ "$linkName" = ls3266 ]] && linkName=lnxzx6-l23-g33 # 64-bit z RH 4, SLES 9

  [ -d $optLib/$linkName ] || mkdir -p $optLib/$linkName > /dev/null 2>&1
  #$NLS-E$ "cannot access directory \"$optLib/$linkName\""
  [ -d $optLib/$linkName ] || Err_report fail "`nls_replace 'KCI0607E' \\"$optLib/$linkName\\"`"

  # Remove the old link if it exists, and create a new one.

  if [ -L "$optLib/$linkName/lib" ]
  then
    # Does the exact same link already exist?
    found=$(ls -l ${optLib}/${linkName} | grep $CANDLEHOME/tmaitm6/$libArch/lib)
    if [ ! "${found}" = "" ]
    then
      # Exit, since there the same link already exists.
      return
    fi

    # Located an link pointing to a different location, remove it.
    rm $optLib/$linkName/lib > /dev/null 2>&1
	#$NLS-E$ "could not remove old link"
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0608E'`"
  fi

  # Only create a link if the shared libs exist
  if [ -d "$CANDLEHOME/tmaitm6/$libArch/lib" ]
  then
    ln -sf $CANDLEHOME/tmaitm6/$libArch/lib $optLib/$linkName/lib > /dev/null 2>&1
  fi
  #$NLS-E$ "could not create link \"$optLib/$linkName/lib\""
  [ -L "$optLib/$linkName/lib" ] || Err_report fail "`nls_replace 'KCI0609E' \\"$optLib/$linkName/lib\\"`"

  # No need for second link anymore

  return
}

# Process the UNIX Logs Monitoring Agent (ul).

procUL()
{
  # $1 is the name of the product's .ver file.

  # Define local variables.
  typeset binArch kul

  binArch=${1%.ver}  # Remove the extension.
  binArch=$(print $binArch | cut -c3-)  # Get the architecture.

  kul=$CANDLEHOME/$binArch/ul/bin/kulagent
  [ -r $kul ] || return
  chown root $kul > /dev/null 2>&1
  #$NLS-E$ "could not change the owner of \"$kul\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0603E' \\"$kul\\"`"

  chmod 4755 $kul > /dev/null 2>&1
  #$NLS-E$ "could not change the permissions on \"$kul\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0604E' \\"$kul\\"`"

  # UL not supported on AIX 433 in this release

  # procLinkU is done for all products now
}

# Process the Universal Agent (um).

procUM()
{
  # $1 is the name of the product's .ver file.

  # Define local variables.
  typeset binArch binDir files linkName name sys

  files="kumsnetd kumstrap"
  sys=sys  # Use for HP-UX and Solaris.

  binArch=${1%.ver}  # Remove the extension.
  binArch=$(print $binArch | cut -c3-)  # Get the architecture.
  [[ "$binArch" = aix+([0-9]) ]] && sys=system

  binDir=$CANDLEHOME/$binArch/um/bin
  for name in $files
  do
    [ -r $binDir/$name ] || continue
    chown root $binDir/$name > /dev/null 2>&1
	#$NLS-E$ "could not change the owner of \"$name\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0603E' \\"$name\\"`"
    chgrp $sys $binDir/$name > /dev/null 2>&1
	#$NLS-E$ "could not change the group for \"$name\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0605E' \\"$name\\"`"
    chmod 4755 $binDir/$name > /dev/null 2>&1
	#$NLS-E$ "could not change the permissions on \"$name\""
    [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0604E' \\"$name\\"`"
  done
}

# Process the UNIX OS Monitoring Agent (ux)

procUX()
{
  # $1 is the name of the product's .ver file.

  # Define local variables.
  typeset binArch binDir libArch name optLib uxVFile uxDir binaries

  binArch=${1%.ver}  # Remove the extension.
  binArch=$(print $binArch | cut -c3-)  # Get the architecture.
  binDir=$CANDLEHOME/$binArch/ux/bin
  uxDir=$CANDLEHOME/$binArch/ux
  binaries="kuxagent stat_daemon kuxdstat ifstat kux_vmstat nfs_stat"

  chmod -R 644 $uxDir
  chmod -R ugo+X $uxDir
  for binary in  $binaries; do
        chmod 755 $binDir/$binary;
  done

  if [[ "$binArch" = aix+([0-9]) ]]
  then
#    [ "$binArch" = "aix43" ] && procVMStat

    name=$binDir/stat_daemon
    [ -r $name ] || return
#    chown root $name > /dev/null 2>&1
#    [ $? -eq 0 ] || Err_report warn "could not change the owner of \"$name\""
    chmod 2755 $name > /dev/null 2>&1
	#$NLS-E$ "could not change the permissions on \"$name\""
    [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0604E' \\"$name\\"`"
    chgrp 0 $name > /dev/null 2>&1
	#$NLS-E$ "could not change the group for \"$name\""
    [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0605E' \\"$name\\"`"
    return
  fi

  if [[ "$binArch" = hp+([0-9])  ||  "$binArch" = hpi+([0-9]) ]]
  then
    name=$binDir/kuxagent
    [ -r $name ] || return
    chown root $name > /dev/null 2>&1
    chmod 6755 $name > /dev/null 2>&1
	#$NLS-E$ "could not change the permissions on \"$name\""
    [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0604E' \\"$name\\"`"
    chgrp sys $name > /dev/null 2>&1
	#$NLS-E$ "could not change the group for \"$name\""
    [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0605E' \\"$name\\"`"
    return
  fi

  if [[ "$binArch" = sol+([0-9]) ]]
  then
    name=$binDir/kuxagent

    if [ -r $name ]
    then
      chmod 4755 $name > /dev/null 2>&1
	  #$NLS-E$ "could not change the permissions on \"$name\""
      [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0604E' \\"$name\\"`"
      chown root $name > /dev/null 2>&1
	  #$NLS-E$ "could not change the owner of \"$name\""
      [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0603E' \\"$name\\"`"
    fi

    # procLinkU is done for all products now

  fi
}

# Process kux_vmstat on aix43.

procVMStat()
{
  # Define local variables.
  typeset name=$CANDLEHOME/aix43/ux/bin/kux_vmstat

  [ -r $name ] || return
  chown root $name > /dev/null 2>&1
  #$NLS-E$ "could not change the owner of \"$name\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0603E' \\"$name\\"`"
  chgrp system $name > /dev/null 2>&1
  #$NLS-E$ "could not change the group for \"$name\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0605E' \\"$name\\"`"
  chmod 6755 $name > /dev/null 2>&1
  #$NLS-E$ "could not change the permissions on \"$name\""
  [ $? -eq 0 ] || Err_report fail "`nls_replace 'KCI0604E' \\"$name\\"`"
}


# Process the TEMS for security validation (ms)

procMS()
{
  # Define local variables.
  typeset rec cms host cfgFile binPath
  typeset rFile=$CANDLEHOME/config/.ConfigData/RunInfo
  rec="$*"

  print  ... processing $rec
  cms=$(print $rec | cut -d" " -f2 | sed "s/\"//g")  # cms -> mycms
  host=$(print $rec | cut -d" " -f5 | sed "s/\"//g") # host -> vulcan
  cfgFile=$CANDLEHOME/config/${host}_ms_${cms}.config
  if [[ ! -r $cfgFile || ! -w $cfgFile ]]
  then
    if [ -z "$tMName" ]
    then
	  #$NLS-E$ "cannot access file \"$cfgFile\"" skipping $rec ..."
      Err_report warn2 "`nls_replace 'KCI0610I' \\"$cfgFile\\" $rec`"
      return  # Get the next TEMS.
    else
	  #$NLS-E$ "cannot access file \"$cfgFile\""
      Err_report fail "`nls_replace 'KCI0611E' \\"$cfgFile\\"`"
    fi
  fi

  grep "CMS_BINPATH" $cfgFile > /dev/null 2>&1
  if [ $? -ne 0 ]
  then
    if [ -z "$tMName" ]
    then
	  #$NLS-E$ "could not determine the value of \"CMS_BINPATH\"" skipping $rec ..."
      Err_report warn2 "`nls_replace 'KCI0612I' \\"CMS_BINPATH\\" $rec`"
      return  # Get the next TEMS.
    else
	  #$NLS-E$ "could not determine the value of \"CMS_BINPATH\""
      Err_report fail "`nls_replace 'KCI0613E' \\"CMS_BINPATH\\"`"
    fi
  fi

  binPath=$(grep "CMS_BINPATH" $cfgFile | cut -d"=" -f2 | sed "s/'//g")  # binPath -> /aix42/ms/bin
  binPlat=${binPath%/ms/bin}  # Remove the extension.
  binPlat=${binPlat##*/}  # Remove the path.

  # Check to see if there is a TEMS running on this host.  If so, issue a warning.

  for proc in $(cat $rFile | sed "s/  */ /g" | grep "$host" | grep "^N" | cut -d" " -f2)  # proc -> ms12440
  do
    val=$(print $proc | cut -c1-2)  # val -> ms
    if [ "$val" = "ms" ]
    then
      PID=$(print $proc | cut -c3-)  # PID -> 35594
      ps -p $PID | grep $PID > /dev/null 2>&1  # Make sure the product is actually running.
	  #$NLS-E$ "there is a TEMS running with PID = \"$PID\"\n"
      [ $? -ne 0 ] && Err_report fail "`nls_replace 'KCI0614E' \\"$PID\\"`\n"
    fi
  done

  # Set the permissions, and create the soft links.
  #### 29706 root ownership and permissions are still needed for ITM 6.1

  exe=$binPath/kdsvlunx

  chown root $exe > /dev/null 2>&1
  if [ $? -ne 0 ]
  then
    if [ -z "$tMName" ]
    then
	  #$NLS-E$ "could not change the owner of \"$exe\"" "skipping $rec ..."
      Err_report warn2 "`nls_replace 'KCI0615I' \\"$exe\\" $rec`"
      return  # Get the next TEMS.
    else
	  #$NLS-E$ "could not change the owner of \"$exe\""
      Err_report fail "`nls_replace 'KCI0603E' \\"$exe\\"`"
    fi
  fi

  chmod ug+x $exe > /dev/null 2>&1  # Just in case since Sun requires ug+x for setgid and setuid.
  if [ $? -ne 0 ]
  then
    if [ -z "$tMName" ]
    then
	  #$NLS-E$ "\(1\) - could not change the permissions on \"$exe\"" "skipping $rec ..."
      Err_report warn2 "(1) - `nls_replace 'KCI0616I' \\"$exe\\" $rec`"
      return  # Get the next TEMS.
    else
	  #$NLS-E$ "\(1\) - could not change the permissions on \"$exe\""
      Err_report fail "(1) - `nls_replace 'KCI0617E' \\"$exe\\"`"
    fi
  fi

  # 36113 ensure that other has read execute access for Authentication in non-root install
  chmod o+rx $exe > /dev/null 2>&1
  if [ $? -ne 0 ]
  then
    if [ -z "$tMName" ]
    then
	  #$NLS-E$ "\(2\) - could not change the permissions on \"$exe\"" "skipping $rec ..."
      Err_report warn2 "(2) - `nls_replace 'KCI0616I' \\"$exe\\" $rec`"
      return  # Get the next TEMS.
    else
	  #$NLS-E$ "\(2\) - could not change the permissions on \"$exe\""
      Err_report fail "(2) - `nls_replace 'KCI0617E' \\"$exe\\"`"
    fi
  fi

  if [ "$fsType" = "nfs" ]
  then
    if [ "$trusted" = "true" ]  # HP-UX only.
    then
      chmod g+s $exe > /dev/null 2>&1
      if [ $? -ne 0 ]
      then
        if [ -z "$tMName" ]
        then
		  #$NLS-E$ "\(3\) - could not change the permissions on \"$exe\"" "skipping $rec ..."
          Err_report warn2 "(3) - `nls_replace 'KCI0616I' \\"$exe\\" $rec`"
          return  # Get the next TEMS.
        else
		  #$NLS-E$ "\(3\) - could not change the permissions on \"$exe\""
          Err_report fail "(3) - `nls_replace 'KCI0617E' \\"$exe\\"`"
        fi
      fi

      chmod o-rwx $exe > /dev/null 2>&1
      if [ $? -ne 0 ]
      then
        if [ -z "$tMName" ]
        then
		  #$NLS-E$ "\(4\) - could not change the permissions on \"$exe\"" "skipping $rec ..."
          Err_report warn2 "(4) - `nls_replace 'KCI0616I' \\"$exe\\" $rec`"
          return  # Get the next TEMS.
        else
		  #$NLS-E$ "\(4\) - could not change the permissions on \"$exe\""
          Err_report fail "(4) - `nls_replace 'KCI0617E' \\"$exe\\"`"
        fi
      fi
    else
      chmod ug+s $exe > /dev/null 2>&1
      if [ $? -ne 0 ]
      then
        if [ -z "$tMName" ]
        then
		  #$NLS-E$ "\(5\) - could not change the permissions on \"$exe\"" "skipping $rec ..."
          Err_report warn2 "(5) - `nls_replace 'KCI0616I' \\"$exe\\" $rec`"
          return  # Get the next TEMS.
        else
		  #$NLS-E$ "\(5\) - could not change the permissions on \"$exe\""
          Err_report fail "(5) - `nls_replace 'KCI0617E' \\"$exe\\"`"
        fi
      fi
    fi
  else  # Non-nfs systems.
    chmod u+s $exe > /dev/null 2>&1
    if [ $? -ne 0 ]
    then
      if [ -z "$tMName" ]
      then
		  #$NLS-E$ "\(6\) - could not change the permissions on \"$exe\"" "skipping $rec ..."
          Err_report warn2 "(6) - `nls_replace 'KCI0616I' \\"$exe\\" $rec`"
        return  # Get the next TEMS.
      else
		  #$NLS-E$ "\(6\) - could not change the permissions on \"$exe\""
          Err_report fail "(6) - `nls_replace 'KCI0617E' \\"$exe\\"`"
      fi
    fi

    # soft links are created for all products now

  fi  # End of else for non-nfs systems.

  # Update the .config file.  Note that since we're running as root, we must edit the file "live"
  # to maintain the original file owner.  If a new file was created, then it would be owned by root.

  grep "KDS_VALIDATE=\'NO\'" $cfgFile > /dev/null 2>&1
  if [ $? -eq 0 ]
  then

    # Use a here document with ex to edit the .config file.  Note, the lines comprising the here
    # doc must start in the first column.

#defect 26413
#ex - $cfgFile << EOF
#g/KDS_VALIDATE='NO'/s//KDS_VALIDATE='YES'/g
#wq
#EOF
#>
cp $cfgFile $cfgFile.bak
cat $cfgFile.bak | sed "s/KDS_VALIDATE='NO'/KDS_VALIDATE='YES'/g" > $cfgFile
#<

    grep "KDS_VALIDATE=\'YES\'" $cfgFile > /dev/null 2>&1  # Ensure that the .config file was updated.
    if [ $? -ne 0 ]
    then
      if [ -z "$tMName" ]
      then
	    #$NLS-E$ "could not update .config file \"$cfgFile\"" "skipping $rec ..."
        Err_report warn2 "`nls_replace 'KCI0618I' \\"$cfgFile\\" $rec`"
        return  # Get the next TEMS.
      else
	    #$NLS-E$ "could not update .config file \"$cfgFile\""
        Err_report fail "`nls_replace 'KCI0619E' \\"$cfgFile\\"`"
      fi
    fi
  fi

  # ensure that soft links were created for the TEMS product prereq
  procLinkU ms$binPlat.ver
}

# Get the names of all installed products requiring special permissions.

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

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

  for name in $(ls $CANDLEHOME/registry/*.ver)
  do
    verName=${name##*/}  # Remove the pathname.
    pc=$(print $verName | cut -c1-2 2> /dev/null)   # Get the product code.
    # all products need to be included (for setting links)

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

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

# Set root permissions via an interactive menu.

goInteractive()
{
  # Note:  this entire function assumes that the archs are given in ascending order in the .ver files and
  # in the architecture description table (archdsc.tbl).

  # Define local variables.

  typeset -i i=0 idx=0 j=0 numAA=0 numRA=0
  typeset arch archDesc pc prodDesc regDir=$CANDLEHOME/registry
  typeset AFLAG CFLAG EFLAG val verName
  typeset lastArch name os osName

  [ -f $tmpFile ] && rm $tmpFile > /dev/null 2>&1

  # Ensure that the description tables exist.

  #$NLS-E$ "cannot read file \"$regDir/archdsc.tbl\""
  [ -r $regDir/archdsc.tbl ] || Err_report fail "`nls_replace 'KCI0620E' \\"$regDir/archdsc.tbl\\"`"
  [ -r $regDir/proddsc.tbl ] || Err_report fail "`nls_replace 'KCI0620E' \\"$regDir/proddsc.tbl\\"`"

  # Build a list of product/architecture descriptions.

  while [ i -lt numProds ]
  do
    # Determine the product code and the bin arch.

    verName=${vfNames[i]}
    pc=$(print $verName | cut -c1-2 2> /dev/null)
    arch=$(print $verName | cut -c3- 2> /dev/null)
    arch=${arch%.ver}  # Remove the .ver extension.

    os=$(print $arch | sed "s/[0-9]//g")  # Remove the release numbers.
    osName=""
    [ "$os" = "aix" ] && osName=AIX
    [ "$os" = "hp" ] && osName=HP-UX
    [ "$os" = "hpi" ] && osName=HP-UX
    [ "$os" = "sol" ] && osName=Solaris
    [ "$os" = "ls" ] && osName=Linux390
    [ "$os" = "li" ] && osName=LinuxIntel
    [ "$os" = "lpp" ] && osName=LinuxPPC
    [ "$os" = "lx" ] && osName=LinuxAMD
    [ "$os" = "lia" ] && osName=LinuxItanium
	#$NLS-E$ "could not determine the name of the operating system from \"$arch\""
    [ -n "$osName" ] || Err_report fail "`nls_replace 'KCI0621E' \\"$arch\\"`"

    # Get the product and base architecture descriptions.

    prodDesc=$(grep "^$pc|" $regDir/proddsc.tbl 2> /dev/null |head -1| cut -d"|" -f2 2> /dev/null)
    archDesc=$(grep "^$arch|" $regDir/archdsc.tbl 2> /dev/null | cut -d"|" -f2 2> /dev/null)
	#$NLS-E$ "could not determine descriptions from \"$verName\""
    [[ -n "$prodDesc" && -n "$archDesc" ]] || Err_report fail "`nls_replace 'KCI0622E' \\"$verName\\"`"

    # Determine all archs supported by the product.

    set -A runArchs $(grep "^runArch *=" $regDir/$verName 2> /dev/null | cut -d"=" -f2 2> /dev/null)
    numRA=${#runArchs[*]}
	#$NLS-E$ "could not determine all run archs from \"$verName\""
    [ numRA -gt 0 ] || Err_report fail "`nls_replace 'KCI0623E' \\"$verName\\"`"

    if [ "${runArchs[numRA-1]}" = "open" ]
    then
      lastArch=${runArchs[numRA-2]}  # The last arch before the "open" record.

      set -A allArchs $(grep "^$os[0-9]*|" $regDir/archdsc.tbl 2> /dev/null | cut -d"|" -f1)
      numAA=${#allArchs[*]}
	  #$NLS-E$ "could not determine all available archs for \"$verName\""
      [ numAA -gt 0 ] || Err_report fail "`nls_replace 'KCI0624E' \\"$verName\\"`"

      # Add all archs beyond the last specified run arch.

      j=0
      while [ j -lt numAA ]
      do
        name=${allArchs[j]}
        [ "$name" = "$lastArch" ] && break
        j=j+1
      done

      numRA=numRA-2
      while [ j -lt numAA ]
      do
        runArchs[numRA]=${allArchs[j]}  # First, replace the duplicate entry.
        numRA=numRA+1
        j=j+1
      done

    fi  # End of if [ "${runArchs[numRA]}" = "open" ]

    # Build an arch description list containing all supported OS levels.

    numRA=${#runArchs[*]}  # Recalculate since additional archs may have been added by "open" processing.
    j=1  # The base arch was determined in "archDesc=..."
    while [ j -lt numRA ]
    do
      arch=${runArchs[j]}
      [ "$arch" = "open" ] && { j=j+1; continue; }
      rel=$(grep "^$arch|" $regDir/archdsc.tbl | cut -d"|" -f2 | sed "s/$osName//" | sed "s/  *//")
      [ -n "$rel" ] || { j=j+1; continue; }
      archDesc="${archDesc}/${rel}"
      j=j+1
    done

    # Write the complete description to a tmp file.  Note, the name of the .ver file is added to this
    # description.  This name will then link the user's selection to the actual product.

    print "$prodDesc ${archDesc}|$verName" >> $tmpFile
    i=i+1
  done  # End of while [ i -lt numProds ]

  # Sort the list of descriptions.

  cat $tmpFile | sort -t "|" -k 1,1 -o $tmpFile
  numProds=$(cat $tmpFile | wc -l 2> /dev/null)
  #$NLS-E$ "could not generate a list of product descriptions"
  [ numProds -gt 0 ] || Err_report fail "`nls_replace 'KCI0625E'`"

  # Add an "all" and an "exit" option to the list.

  print "All of the above.|ALL" >> $tmpFile
  print "Exit this program.|EXIT" >> $tmpFile
  numProds=$(cat $tmpFile | wc -l 2> /dev/null)  # Recalculate to include the new entries.
  #$NLS-E$ "could not generate a complete list of selections"
  [ numProds -gt 0 ] || Err_report fail "`nls_replace 'KCI0626E'`"

  # Generate a "select" menu.

  i=1
  #$NLS-E$ "\nSelect from the following products: \n"
  print "\n`nls_replace 'KCI0627I'` \n"
  while read name
  do
    name=${name%\|*}  # Remove the name of the .ver file so that it is not displayed.
    if [ i -lt 10 ]
    then
      print " $i) $name"
    else
      print "$i) $name"
    fi
    i=i+1
  done < $tmpFile

  # Force the user to make a selection.

  while [ anything ]
  do
    #$NLS-E$ "\nPlease enter a valid number or numbers separated by commas or spaces."
    print
	nls_replace 'KCI0628I'
	#$NLS-E$ "Type your selections here:  \c"
    print "`nls_replace 'KCI0629I'` \c"
    read -r resp
    [ -n "$resp" ] || continue
    # Make sure that all entries are numbers.
    val=$(print $resp | sed "s/[0-9]//g" | sed "s/  *//g" | sed "s/\,//g")
    [ -z "$val" ] || continue
    # Separate each number by a single newline so that the list may be sorted to remove duplicate numbers.
    resp=$(print $resp | sed "s/  */\\\\n/g" | sed "s/,/\\\\n/g")
    # Sort in numeric order, and replace the newlines with spaces.
    resp=$(print $resp | sort -u -n | sed "s/\\\\n/ /g")

    # Check for valid responses.

    AFLAG=""
    CFLAG=""
    EFLAG=""
    for val in $resp
    do
      [[ "$val" -gt 0 && "$val" -le numProds ]] || CFLAG=on;  # Make sure it's a valid number.
      [ "$val" -eq numProds ] && EFLAG=on  # The last selection is "exit."
      [ "$val" -eq numProds-1 ] && AFLAG=on  # The second to last selection is "all."
    done

    [ -n "$EFLAG" ] && exit 0  # Exit takes precedence.
    [ -z "$CFLAG" ] && break   # Valid response, so break out of the while loop.

  done  # End of while loop.

  # Generate the individual selection numbers if "all" was selected.  This loop is needed since a user
  # may have entered the number for "all" among their selections.

  if [ -n "$AFLAG" ]
  then
    resp=1  # This will eliminate the space at the beginning of the completed string.
    i=2
    while [ i -le numProds-2 ]  # Skip "all" and "exit."
    do
      resp="$resp $i"
      i=i+1
    done
  fi

  # Process the selections.

  print
  i=1
  while read name
  do
    for idx in $resp
    do
      if [ idx -eq i ]
      then
        desc=${name%\|*}  # Get the product description corresponding to the user's response.
        verName=${name##*\|}  # Get the name of the .ver file.
        pc=$(print $verName | cut -c1-2 2> /dev/null)  # Get the 2-character product code.
		#$NLS-E$ "could not process \"$desc\""
        [ -n "$pc" ] || Err_report warn "`nls_replace 'KCI0630I' \\""$desc"\\"`"
		#$NLS-E$ ... processing \"$desc\"
        print "`nls_replace 'KCI0631I' \\""$desc"\\"`"
        case $pc in
          or|ox|oy)
            procDB $verName
            ;;
          ul)
            procUL $verName
            ;;
          um)
            procUM $verName
            ;;
          ux)
            procUX $verName
            ;;
          cz)
            procCZ $verName
            ;;
        esac
        procLinkU $verName
      fi
    done
    i=i+1
  done < $tmpFile

  rm -f $tmpFile
}

# Set security validation via an interactive menu.

goInteractive2()
{
  # Define local variables.

  set -A mainMenu
  typeset -i i=0 j=0 numItems=0
  typeset -l fsType=anything
  typeset AFLAG CFLAG EFLAG PID cms host osName proc rec resp val
  typeset binArch binPath cfgFile exe thisMach trusted=false
  typeset createdLinks=false libArch libName optArch optLib=/opt/IBM/ITM/tmaitm6/links

  thisMach=$(uname -a | cut -d" " -f2)  # thisMach -> vulcan

  # See if <candlehome> is an NFS file system.

  osName=$(uname)
  if [[ "$osName" = @(AIX|HP-UX|Linux) ]]
  then
    set -A tmpArray $(df -P $CANDLEHOME)
    print ${tmpArray[7]} | grep ":" > /dev/null 2>&1
    [ $? -eq 0 ] && fsType=nfs
  else
    if [ -x "/usr/xpg4/bin/df" ]
    then
      set -A tmpArray $(/usr/xpg4/bin/df -P $CANDLEHOME)
      print ${tmpArray[7]} | grep ":" > /dev/null 2>&1
      [ $? -eq 0 ] && fsType=nfs
    else
      rec=$(df -n $CANDLEHOME)
      fsType=${rec##*:}
      fsType=$(print $fsType | sed "s/  *//")  # Remove any blanks before the string "nsf".
    fi
  fi

  # For HP, don't ask the user if this is a trusted system.
  # For HP, we can determine if this is a trusted system.

  if [ "$osName" = "HP-UX" ]
  then
    if [ -d "/tcb" ]
    then
      trusted=true
    else
      trusted=false
    fi
##    while [ anything ]
##    do
##      print "\nIs this a trusted system [ y or n; \"y\" is default ]?  \c"
##      read resp
##      [ -n "$resp" ] || resp=y
##      case $resp in
##        n*|N*) trusted=false
##               break
##               ;;
##        y*|Y*) trusted=true
##               break
##               ;;
##            *) print "\n Please enter either \"y\" or \"n\""
##               resp=
##               continue
##               ;;
##      esac
##    done
  fi

  # Generate the menu items.
  # Look only at *_ms_*.config files, and use "_ms_" as the delimiter between hostname/TEMS name @01
  short_hostname=$(print $(hostname) | cut -d"." -f1)
  for rec in $(ls $CANDLEHOME/config/${short_hostname}_ms_*.config | grep -v "PLACEHOLDER" | sort -t "_" -k 3)  # Sort by TEMS name.
  do
    rec=${rec##*/}  # Remove the directory path.
    rec=${rec%.*}   # Remove the ".config" extension.
    host=${rec%%_ms_*} # host -> vulcan          #IY89862
    cms=${rec##*_ms_}  # cms -> mycms
	#$NLS-E$ "TEMS \"$cms\" on host \"$host\""
    mainMenu[i]="`nls_replace 'KCI0632I' \\"$cms\\" \\"$host\\"`"
    i=i+1
  done

  # Add an "all" option if there is more than one TEMS.

  #$NLS-E$ "All of the above."
  [ ${#mainMenu[*]} -gt 1 ] && mainMenu[${#mainMenu[*]}]="`nls_replace 'KCI0633I'`"

  # Add an "exit" option.

  #$NLS-E$ "Exit this program."
  mainMenu[${#mainMenu[*]}]="`nls_replace 'KCI0634I'`"

  # Generate a "select" menu.

  i=1 j=0
  numItems=${#mainMenu[*]}  # The number of elements in the array.

  #$NLS-E$ "\nSelect from the following: \n"
  print
  nls_replace 'KCI0635I'
  print
  while [ j -lt numItems ]
  do
    if [ i -lt 10 ]
    then
      print " $i) ${mainMenu[j]}"
    else
      print "$i) ${mainMenu[j]}"
    fi
    i=i+1
    j=j+1
  done

  # Force the user to make a selection.

  resp=
  while [ anything ]
  do
    #$NLS-E$ "\nPlease enter a valid number or numbers separated by commas or spaces."
    print
	nls_replace 'KCI0636I'
	#$NLS-E$ "Type your selections here:  \c"
	print "`nls_replace 'KCI0637I'` \c"
    read -r resp
    [ -n "$resp" ] || continue
    # Make sure that all entries are numbers.
    val=$(print $resp | sed "s/[0-9]//g" | sed "s/  *//g" | sed "s/\,//g")
    [ -z "$val" ] || continue
    # Separate each number by a single newline so that the list may be sorted to remove duplicate numbers.
    resp=$(print $resp | sed "s/  */\\\\n/g" | sed "s/,/\\\\n/g")
    # Sort in numeric order, and replace the newlines with spaces.
    resp=$(print $resp | sort -u -n | sed "s/\\\\n/ /g")

    # Check for valid responses.

    AFLAG=""  # 'A' for "all"
    CFLAG=""  # 'C' for "continue"
    EFLAG=""  # 'E' for "exit"

    for val in $resp
    do
      [[ "$val" -gt 0 && "$val" -le numItems ]] || CFLAG=on;  # Make sure it's a valid number.
      [ "$val" -eq numItems ] && EFLAG=on  # The last selection is "exit."
      [[ numItems -gt 2 && "$val" -eq numItems-1 ]] && AFLAG=on  # The second to last selection is "all."
    done

    [ -n "$EFLAG" ] && exit 0  # Exit takes precedence.
    [ -z "$CFLAG" ] && break   # Valid response, so break out of the while loop.

  done  # End of while loop.

  # Generate the individual selection numbers if "all" was selected.  This loop is needed since a user
  # may have entered the number for "all" among their selections.

  if [ -n "$AFLAG" ]
  then
    resp=1  # This will eliminate the space at the beginning of the completed string.
    i=2
    while [ i -le numItems-2 ]  # Skip "all" and "exit."
    do
      resp="$resp $i"
      i=i+1
    done
  fi

  # Process the selections.

  print
  for i in $resp
  do
    rec=${mainMenu[i-1]}  # Array indexes start at 0.  rec -> TEMS "mycms" on host "vulcan"
    print  ... processing $rec
    procMS "$rec"
  done  # End of the "selections" for loop.
}


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

export TEXTDOMAINDIR=$bindir/../config/nls/msg
export PATH=$bindir:$PATH

export PATH=/usr/bin:/usr/sbin:$PATH
PROGNAME=$(basename $0)

set -A vfNames
typeset -i i=0 numProds=0
typeset ALLPRODS VALIDATE ddArch myID specCH thisDir tmpFile vFName tMName

while getopts :h:as opt
do case $opt in
  h) CANDLEHOME=$OPTARG
     CANDLEHOME=$(eval print $CANDLEHOME)  # Process ~ if it was entered.
     specCH=true
     ;;
  a) ALLPRODS=true  # Set all permissions in silent mode.
     ;;
  s) VALIDATE=true  # Set security validation.
     ;;
  ?) Use_report
     ;;
  :) Use_report
     ;;
  esac
done

shift OPTIND-1

if [ $# -gt 0 ]
then
 [ -z "$ALLPRODS" ] || Use_report
fi

#IY77938#
if [ $# -gt 1 ]
then
 [ -z "$VALIDATE" ] || Use_report
fi

[[ -n "$ALLPRODS" && -n "$VALIDATE" ]] && Use_report  # Options -a and -s cannot be used together.

if [ $# -eq 0 ]  # Interactive and silent mode.  Security validation too.
then
#   Sun does not support "id -u," so use the following to get the user ID number.
  myID=$(id 2> /dev/null | cut -d"=" -f2 2> /dev/null | cut -d"(" -f1 2> /dev/null)
  #$NLS-E$ "you must be \"root\" to run this command"
  [ "$myID" = "0" ] || Err_report fail "`nls_replace 'KCI0638E' \\"root\\"`"
fi

# If it wasn't specified via -h, try to determine the name of CANDLEHOME.
if [[ -z "$specCH" || -z "$CANDLEHOME" ]]
then
  CANDLEHOME=$(cd $(dirname $0) ; dirname $(pwd))
fi
#if [ -z "$specCH" ]
#then
#  thisDir=$(basename $(pwd))
#  [ "$thisDir" = "bin" ] && CANDLEHOME=$(dirname $(pwd))
#fi

#$NLS-E$ "CANDLEHOME directory not set or not specified"
[ -n "$CANDLEHOME" ] || Err_report fail "`nls_replace 'KCI0639E' CANDLEHOME`"
#$NLS-E$ "\"$CANDLEHOME\" is not a directory"
[ -d "$CANDLEHOME" ] || Err_report fail "`nls_replace 'KCI0640E' \\"$CANDLEHOME\\"`"

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

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

regDir=$CANDLEHOME/registry
[ -d $regDir ] || Err_report fail "\"$regDir\" is not a directory"

# EJF (#18230.1) set kbbacf1 permissions
if [ -d "$CANDLEHOME/tmaitm6" ]
then
  filesToChange=$(ls $CANDLEHOME/tmaitm6/*/bin/kbbacf1)

  for fileToChange in $filesToChange
  do
    chown root $fileToChange > /dev/null 2>&1
    #$NLS-E$ "could not change the owner of \"$fileToChange\""
    [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0603E' \\"$fileToChange\\"`"

    chmod 4755 $fileToChange > /dev/null 2>&1
    #$NLS-E$ "could not change the permissions of \"$fileToChange\""
    [ $? -eq 0 ] || Err_report warn "`nls_replace 'KCI0604E' \\"$fileToChange\\"`"
  done
fi

# Process products in interactive mode.

if [[ $# -eq 0 && -z "$ALLPRODS" && -z "$VALIDATE" ]]
then
  getVFNames  # Get the names of the .ver files for products that require special permissions.
  numProds=${#vfNames[*]}
  #$NLS-E$ "no root permissions required"
  [ numProds -gt 0 ] || { Err_report info "`nls_replace 'KCI0643I'`"; exit 0; }
  CANDLETMP=$CANDLEHOME/tmp
  #$NLS-E$ "cannot write to directory \"$CANDLETMP\""
  [ -w $CANDLETMP ] || Err_report fail "`nls_replace 'KCI0644E' \\"$CANDLETMP\\"`"
  tmpFile=$CANDLETMP/osList.$$
  goInteractive
  print "... Done.\n"
  exit 0
fi

# Process all products (-a option) in noninteractive mode.

if [[ $# -eq 0 && -n "$ALLPRODS" ]]
then
  getVFNames  # Get the names of the .ver files for products that require special permissions.
  numProds=${#vfNames[*]}
  #$NLS-E$ "no root permissions required" - defect 37210 extraneous message removed.
  [ numProds -gt 0 ] || exit 0
  i=0
  while [ i -lt numProds ]
  do
    vFName=${vfNames[i]}
    # No need to print during silent mode
    osCode=$(print $vFName | cut -c1,2)  # Get the 2-character product code.
    case $osCode in
      or|ox|oy)
        procDB $vFName
        ;;
      ul)
        procUL $vFName
        ;;
      um)
        procUM $vFName
        ;;
      ux)
        procUX $vFName
        ;;
      cz)
        procCZ $vFName
        ;;
    esac
    procLinkU $vFName
    i=i+1
  done
  # No need to print during silent mode
  exit 0
fi

# Set security validation on selected TEMS's.

if [[ -n "$VALIDATE" ]]
then
# In interactive mode.
  if [[ $# -eq 0 ]]
  then
    tMName=""
    ls $CANDLEHOME/config/*ms*.config | grep -v "PLACEHOLDER" > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
      goInteractive2
	  #$NLS-E$ "... Done.\n"
	  nls_replace 'KCI0648I'
      print " "
    else
	  #$NLS-E$ "There are no configured TEMS's in \"$CANDLEHOME\""
      Err_report info "`nls_replace 'KCI0645I' \\"$CANDLEHOME\\"`"
    fi
# In noninteractive mode.
  else
    tMName="$1"
    short_hostname=$(print $(hostname) | cut -d"." -f1)
    ls $CANDLEHOME/config/${short_hostname}_ms*.config | grep -v "PLACEHOLDER" > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
      foundRec=""
      for rec in $(ls $CANDLEHOME/config/${short_hostname}_ms_*.config | grep -v "PLACEHOLDER" | sort -t "_" -k 3)  # Sort by TEMS name.
      do
        rec=${rec##*/}  # Remove the directory path.
        rec=${rec%.*}   # Remove the ".config" extension.
        host=${rec%%_ms_*} # host -> vulcan      #IY89862
        cms=${rec##*_ms_}  # cms -> mycms
        if [ "$tMName" = "$cms" ]
        then
          #$NLS-E$ "TEMS \"$cms\" on host \"$host\""
          foundRec="`nls_replace 'KCI0632I' \\"$cms\\" \\"$host\\"`"
	  break
        fi
      done
      if [ -n "$foundRec" ]
      then
        procMS "$foundRec"
		#$NLS-E$ "... Done.\n"
		nls_replace 'KCI0649I'
        print " "
      else
	    #$NLS-E$ "TEMS \"$tMName\" not found in \"$CANDLEHOME\""
        Err_report fail "`nls_replace 'KCI0646E' \\"$tMName\\" \\"$CANDLEHOME\\"`"
      fi
    else
	  #$NLS-E$ "There are no configured TEMS's in \"$CANDLEHOME\""
      Err_report fail "`nls_replace 'KCI0647E' \\"$CANDLEHOME\\"`"
    fi
  fi

  exit 0
fi

# Process (in noninteractive mode) only those products provided as args.
# This operation is not documented.

for vFName in $*
do
  osCode=$(print $vFName | cut -c1,2)  # Get the 2-character product code.
  case $osCode in
    or|ox|oy)
      procDB $vFName
      ;;
    ul)
      procUL $vFName
      ;;
    um)
      procUM $vFName
      ;;
    ux)
      procUX $vFName
      ;;
    cz)
      procCZ $vFName
      ;;
  esac
  procLinkU $vFName
done

