#!/bin/sh
#  $Id: postinstall.sh 146617 2018-01-12 14:45:05Z matt.dean@oracle.com $
#  Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
#  This software code contains proprietary information 
#  and should be treated as confidential.
#
#  Component: Tarantella Tier3 Enhancement Module for UNIX
#  Author: stuarth
#
#  Postinstall Script
#
##########################################################################
if [ -f /tmp/pkgadd.debug ]; then
    echo "Debug Output On"
    echo "---------------"
    echo " "
    set
    set -x	
    trace=x export trace
fi


OK=0
FAIL=1

machinearch ()
{
#!/bin/sh
#  $Id: ixiarch.sh 23561 2012-05-15 08:22:43Z ww161634 $
#  Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
#  This software code contains proprietary information
#  and should be treated as confidential.
#
#  Print canonical syscode for platform

# There are three valid types of command line:
#
# 1.     visionarch
# 2.     visionarch <available codes>...
# 3.	 visionarch [-c|-o]
#
# 1. The architecture is echoed
# 2. The best architecture from the list is returned
# 3. The -c and -o options return just the system Code or the OS type.

# 0) INITIALIZE VARIABLES

# Some of these are historical, but dont cause any harm
PATH=/bin:/usr/bin:/sbin:/usr/sbin:$XDTHOME/bin:$PMWMHOME/bin:$IXIHOME/bin:$PATH


# 1) Arguments
numcodes=0
for i
do
  case $i in
    -c )
      codeonly=1
    ;;
  
    -o )
      osonly=1
    ;;

    -n )
      if [ -z "$codeonly" -a -z "$osonly" ]
      then
	  displayname=1	
      fi
    ;;
 
    * )
      checkcodes="$checkcodes $i"
      numcodes=`expr $numcodes + 1`
    ;;

   esac
done

# fast exit
if [ $numcodes = 1 ]
then
  echo $checkcodes
  exit 0
fi


# 2) MESSAGES
myname=`basename $0`

#  First define some messages.
#  They get overwritten by sourcing from a file, scripts.ll_TT,
#  so there's no need to translate them here.  

#  Messages for the visionarch script.
#  These follow text like "visionarch: !4! ", and may extend to several lines.
msg_xdtarch_no_uname=\
'No uname command found.'
msg_xdtarch_os_cpu=\
'Cannot recognize the Operating System or processor type.'
msg_xdtarch_ver_rel=\
'Cannot calculate version or release.'
msg_xdtarch_no_match=\
'Cannot find matching installed system.'

#  End of messages
# Try to find a language script
posslangfiles=""
for lang in C $IXILANG $PANLANG $LANG
do
  for pathname in $XDTHOME/bin/scripts. $PMWMHOME/bin/scripts. $IXIHOME/bin/scripts. ./scripts.
  do
    posslangfiles="$posslangfiles $pathname.$lang"
  done
done

# see if we can find one of those language files
for f in $posslangfiles
do
  if [ -f $f ]
  then
    . $scriptslangfile			# source it
    break
  fi						
done
  
# 3) TRY UNAME AND SET UP VARIABLES

unamev=`uname -v 2>/dev/null`
if [ $? -ne 0 ]
then
  # This isn't really a UNIX system is it?
  echo >&2  "$myname: !2! $msg_xdtarch_no_uname"
  exit 2
fi

U_SYSTEM=`uname -s 2>/dev/null`  || U_SYSTEM=UNKNOWN
U_RELEASE=`uname -r 2>/dev/null` || U_RELEASE=UNKNOWN
U_VERSION=`uname -v 2>/dev/null` || U_VERSION=UNKNOWN

# Some machines use -m arg to return 'model' rather
# than architecture.  For example, NCR SVR4 returns
# 3433,3434.  On such machines need to use -p which
# returns processor.

for MACHARG in m p
do
    U_MACHINE=`uname -"$MACHARG" 2>/dev/null` || U_MACHINE=UNKNOWN

    # 4)  FIND THE MACHINE
    # Note that we only look for cpu/os combinations our products currently
    # support - if you want better matching, most GNU software comes with
    # a script called 'config.guess' which does a more thorough job (and
    # has totally different output!)

    CPU= 			# Characters 1-2 of syscode
    OS= 			# Characters 3-4 of syscode
    VER=			# Digits 5-6 of syscode
    REL= 			# Digits 7-8 of syscode


    case ${U_MACHINE}::${U_SYSTEM}::${U_RELEASE}::${U_VERSION} in
      # Intel FreeBSD
      i*::FreeBSD::*:* )
        CPU=i3
        OS=fb
        NAME="FreeBSD (Intel)"
        VER=`expr $U_RELEASE : '[^0-9]*\([0-9][0-9]*\)[^0-9]'`
        REL=`expr $U_RELEASE : '[^0-9]*[0-9][0-9]*[^0-9]\([0-9][0-9]*\)'`
       ;;
      # MacOS X
      powerpc::Darwin::*::*)
        CPU=pp
        OS=dw
        NAME="Darwin (PowerPC)"
        VER=`expr $U_RELEASE : '[^0-9]*\([0-9][0-9]*\)[^0-9]'`
        REL=`expr $U_RELEASE : '[^0-9]*[0-9][0-9]*[^0-9]\([0-9][0-9]*\)'`
       ;;
      # MacOS X (Intel)
      i386::Darwin::*::*)
        CPU=i3
        OS=dw
        NAME="Darwin (Intel)"
        VER=`expr $U_RELEASE : '[^0-9]*\([0-9][0-9]*\)[^0-9]'`
        REL=`expr $U_RELEASE : '[^0-9]*[0-9][0-9]*[^0-9]\([0-9][0-9]*\)'`
       ;;
      # PowerPC Linux
      ppc*::Linux::*::*)
        CPU=pp
        OS=li
        NAME="Linux (PowerPC)"
        VER=`expr $U_RELEASE : '[^0-9]*\([0-9][0-9]*\)[^0-9]'`
        REL=`expr $U_RELEASE : '[^0-9]*[0-9][0-9]*[^0-9]\([0-9][0-9]*\)'`
       ;;
      # Intel Linux
      i*::Linux::*::* )
	CPU=i3
	OS=li
	NAME="Linux (Intel)"
	VER=`expr $U_RELEASE : '[^0-9]*\([0-9][0-9]*\)[^0-9]'`
	REL=`expr $U_RELEASE : '[^0-9]*[0-9][0-9]*[^0-9]\([0-9][0-9]*\)'`
      ;;
      # Athlon 64 Linux
      x86_64::Linux::*::* )
	CPU=i3
	OS=li
	NAME="Linux (AMD 64)"
	VER=`expr $U_RELEASE : '[^0-9]*\([0-9][0-9]*\)[^0-9]'`
	REL=`expr $U_RELEASE : '[^0-9]*[0-9][0-9]*[^0-9]\([0-9][0-9]*\)'`
      ;;
      # PowerPC Linux
      ppc*::Linux::*::* )
        CPU=pp
        OS=li
        NAME="Linux (PowerPC)"
        VER=`expr $U_RELEASE : '[^0-9]*\([0-9][0-9]*\)[^0-9]'`
        REL=`expr $U_RELEASE : '[^0-9]*[0-9][0-9]*[^0-9]\([0-9][0-9]*\)'`
       ;;
      # Sequent (Intel)
      i*::DYNIX*::*::* )
	CPU=i3
	OS=dy
	NAME="Sequent DYNIX/ptx (Intel)"
	VER=`expr $U_VERSION : 'V\([0-9]\).*'`
	REL=`expr $U_VERSION : 'V[0-9].\([0-9].[0-9]\)' | sed 's/\.//g'`
      ;;

      # The Sun family
      *::SunOS::4.*::* )
	CPU=sp
	OS=su
	VER=4
	NAME="Sun SunOS (Sparc)"
	REL=`expr $U_RELEASE : '4.\([^_]*\)' | sed 's/[^0-9]//g'`
      ;;
      sun*::SunOS::5.*::* )
	CPU=sp
	OS=so
	VER=5
	NAME="Sun Solaris (Sparc)"
	REL=`expr $U_RELEASE : '5.\([0-9][0-9]*\).*' | sed 's/[^0-9]//g'`
      ;;
      *86*::SunOS::5.*::* )
	CPU=i3
	OS=so
	VER=5
	NAME="Sun Solaris (Intel)"
	REL=`expr $U_RELEASE : '5.\(.*\)' | sed 's/[^0-9]//g'`
      ;;
      *::SunOS::5.*::* )
	CPU=sp
	OS=so
	VER=5
	NAME="Sun Solaris (Sparc)"
	REL=`expr $U_RELEASE : '5.\([0-9][0-9]*\).*' | sed 's/[^0-9]//g'`
      ;;

      # HP
      *::HP-UX::*::* )
	CPU=pa
	OS=hp
	NAME="Hewlett-Packard HP-UX (PA-RISC)"
	VER=`expr $U_RELEASE : '[^.]*.\([0-9]*\).*'`
	REL=`expr $U_RELEASE : '[^.]*.[^.]*.\([0-9]*\)'`
      ;;

      # Data General
      *::dgux::5.4*::* )
	CPU=m8
	OS=dg
	VER=54
	NAME="Data General DG/UX (Motorola)"
	REL=`expr $U_RELEASE : '5.4\(.*\)' | sed 's/[^0-9]//g' | sed 's/\(.\).*\(.\)$/\1\2/'`
      ;;

      # Data General on Intel
      *::dgux::R4*::* )
	case `uname -p`  in
	  m* )
	    CPU=m8 ;;
	  * )
	    CPU=i3 ;;
	esac
	OS=dg
	VER=04
	NAME="Data General DG/UX (Intel)"
	REL=`expr $U_RELEASE : 'R4.\(.*\)' | sed 's/[^0-9]//g'`
        REL=`echo $REL | sed 's/\(..\).*/\1/'`
      ;;

      # OSF/1
      alpha::OSF1::*::* )
	CPU=ax
	OS=o1
	NAME="DEC OSF/1 (Alpha)"
	VER=`echo $U_RELEASE | sed 's/\([^.]*\).*/\1/' | sed 's/[^0-9]//g'`
	REL=`echo $U_RELEASE | sed 's/[^.]*.\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;

      # ULTRIX
      *::ULTRIX::*::* )
	CPU=mp
	OS=ul
	NAME="DEC Ultrix (MIPS)"
	VER=`echo $U_RELEASE | sed 's/\([^.]*\).*/\1/' | sed 's/[^0-9]//g'`
	REL=`echo $U_RELEASE | sed 's/[^.]*.\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;

      # IRIX
      *::IRIX::4.*::* )
	CPU=mp
	OS=ir
	VER=`echo $U_RELEASE | sed 's/\([^.]*\).*/\1/' | sed 's/[^0-9]//g'`
	REL=`echo $U_RELEASE | sed 's/[^.]*.\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;
      
      *::IRIX::5.1::* )
	CPU=mp
	OS=ir
	VER=`echo $U_RELEASE | sed 's/\([^.]*.[^.]*\).*/\1/' | sed 's/[^0-9]//g'`
	REL=`echo $U_RELEASE | sed 's/[^.]*.[^.]*.\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;

      # Note
      # If we ever get minor release numbers of 5.2 we'll have to do
      # something different
      *::IRIX::5.2::* )
	CPU=mp
	OS=ir
	VER=`echo $U_RELEASE | sed 's/\([^.]*\).*/\1/' | sed 's/[^0-9]//g'`
	REL=20
      ;;
      # Note
      # This system does not exist yet
      *::IRIX::5.2.*::* )
	CPU=mp
	OS=ir
	VER=`echo $U_RELEASE | sed 's/\([^.]*\).*/\1/' | sed 's/[^0-9]//g'`
	REL=`echo $U_RELEASE | sed 's/[^.]*.\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;

      # catchall for other irix versions
      # 6.4 and later change from IRIX to IRIX64
      *::IRIX*::*::* )
	CPU=mp
	OS=ir
	VER=`echo $U_RELEASE | sed 's/\([^.]*\).*/\1/' | sed 's/[^0-9]//g'`
	REL=`echo $U_RELEASE | sed 's/[^.]*.\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;

      # AIX
      # note that we can't figure out the patch level of a 3.2.x (x<4)
      # system (even IBM can't tell you immediately!)
      *::AIX::*::* )
	CPU=rs
	OS=ai
	NAME="IBM AIX (Risc)"
	VER=$U_VERSION
	REL=$U_RELEASE
      ;;

      # RISC OS (the mips variety, not acorn)
      # version 5 like output
      mips::*::*::RISCos )
	CPU=mp
	OS=ro
	VER=`echo $U_RELEASE | sed 's/\([^.]*\).*/\1/' | sed 's/[^0-9]//g'`
	REL=`echo $U_RELEASE | sed 's/[^.]*.\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;
      # version 4 like output
      mips::*::*::UMIPS )
	CPU=mp
	OS=ro
	VER=`echo $U_RELEASE | sed 's/\([0-9]*\).*/\1/'`
	REL=`echo $U_RELEASE | sed 's/[0-9]*\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;

      # Siemens Nixdorf mips R4000 (at least)
      R4000::*::*::* )
	CPU=mp
	OS=sx
	NAME="Siemens Nixdorf SINIX (MIPS)"
	VER=`echo $U_RELEASE | sed 's/\([0-9]*\).*/\1/'`
	REL=`echo $U_RELEASE | sed 's/[0-9]*\(.*\)/\1/' | sed 's/[^0-9]//g'`
      ;;

      # Motorola SVR4
      *88*::*::4*::* )
	CPU=m8
	OS=mo
	VER=`expr $U_VERSION : '[^V]*.\([^.]*\).*' | sed 's/[^0-9]//g'`
	REL=`expr $U_VERSION : '[^V]*.[^.]*.\(.*\)' | sed 's/[^0-9]//g'`
      ;;

      # windows nt with nutcracker
      *::Windows_NT::*::* )
	CPU=i3
	OS=wi
	VER="$U_RELEASE"
	REL="$U_VERSION"
      ;;

      DRS*::*::*::* )
	  PROC=`uname -p 2>/dev/null` || PROC=UNKNOWN
	  case "$PROC" in
	    sparc | SPARC )
	      CPU=sp
	      OS=nx
	      NAME="ICL DRS/NX (Sparc)"
	      ;;
	    i386 )
	      CPU=i386
	      OS=nx
	      NAME="ICL DRS/NX (Intel)"
	      ;;
	  esac

	  VER=`expr $U_VERSION : '\([0-9]\).*'`
	  REL=`expr $U_VERSION : '[0-9]..*\([0-9].[0-9]\)' | sed 's/\.//g'`
      ;;

      
      *::UnixWare::*::* )
	CPU=i3
	OS=un
	NAME="SCO UnixWare (Intel)"
	VER=`expr $U_VERSION : '\([0-9]\)'`
	REL=`expr $U_VERSION : '[0-9].\(.*\)' | sed -e 's/\.//'`
	if [ -z "$REL" ]; then
		REL=00
        elif [ "x`expr $REL : '[0-9]\([0-9]\)'`" = "x" ] ; then
		REL="$REL"0
	fi
	;;

      *::OpenUNIX::*::* )
        CPU=i3
        OS=un
        NAME="SCO UnixWare (Intel)"
        VER=`expr $U_VERSION : '\([0-9]\)'`
        REL=`expr $U_VERSION : '[0-9].\(.*\)' | sed -e 's/\.//'`
        if [ -z "$REL" ]; then
                REL=00
        elif [ "x`expr $REL : '[0-9]\([0-9]\)'`" = "x" ] ; then
                REL="$REL"0
        fi
        ;;

      # Various Intel based Unixen.  These seem particularly reluctant
      # to divulge their OS name, so we have to grep through
      # various system files to find the OS string

      *86*::*::*::* )
	if grep -s -i UnixWare /stand/boot 2>/dev/null 1>&2 || strings /stand/1/unix_mp 2>/dev/null | grep -s -i Unixware 2>/dev/null 1>&2
	then
          # It's some version of Unixware obviously
	  CPU=i3
	  OS=un
	  NAME="SCO UnixWare (Intel)"
          if expr $U_VERSION : 'D\([0-9]*.*\)' 2>/dev/null 1>&2
	  then
            # It's a date stamped version ; we dont yet know how to figure out
            # which so just pretend that it is unixware 212
            VER=02
            REL=12
          else
	    VER=`expr $U_VERSION : '\([0-9]\)'`
	    REL=`expr $U_VERSION : '[0-9].\(.*\)' | sed -e 's/\.//'`
	    if [ "x`expr $REL : '[0-9]\([0-9]\)'`" = "x" ] 
	    then
		REL="$REL"0
	    fi
          fi
	else
	  if [ "$U_SYSTEM" = "SCO_SV" ]
	  then
	    CPU=i3
	    OS=sc
	    VER=`expr $U_RELEASE : '^\([0-9]*\)'`
	    NAME="SCO OpenServer (Intel)"
	    # just the release string ie: 3.2v5.0.0
	    relstr=`uname -X | grep Release | awk '{ print $3 }'`
	    # just the major SCO version after the SVR? (3.2v) bit
	    U_VERSION=`expr ${relstr} : '[0-9.]*v\([0-9]\)[0-9.]*'`
	    REL=`expr ${U_RELEASE}::${U_VERSION} : '[0-9]*\(.*\)' | sed 's/[^0-9]//g'`
	  else
	    if grep -s 'The Santa Cruz Operation' /etc/gettydefs 2>/dev/null 1>&2
	    then
	      CPU=i3
	      OS=sc
	      NAME="SCO Unix (Intel)"
	      VER=`expr $U_RELEASE : '^\([0-9]*\)'`
	      REL=`expr ${U_RELEASE}::${U_VERSION} : '[0-9]*\(.*\)' | sed 's/[^0-9]//g'`
	    else
	      # DYNIX/ptx V2 doesn't return 'DYNIX' or 'ptx' in uname.
	      # This kludge may work, may not, it's either this
	      # or flip a coin!   
	      if grep -s 'ptx' /etc/versionlog 2>/dev/null 1>&2
	      then
		CPU=i3
		OS=dy
		NAME="Sequent DYNIX/ptx (Intel)"
		VER=`expr $U_VERSION : 'V\([0-9]\).*'`
		REL=`expr $U_VERSION : 'V[0-9].\([0-9].[0-9]\)' | sed 's/\.//g'`
	      else
	        # Assume OS must be System V Release 4.
	        CPU=i3
	        OS=sv
		NAME="System V Release 4 (Intel)"
	        VER=`expr $U_RELEASE : '^\([0-9]*\)'`
	        REL=`expr ${U_RELEASE}::${U_VERSION} : '[0-9]*\(.*\)' | sed 's/[^0-9]//g'`
	      fi
	    fi
	  fi
	fi
	;;	
    esac

    if [ -n "$CPU" -a -n "$OS" -a -n "$VER" -a -n "$REL" ]
    then
	break
    fi
done

# 5) Do sanity checking and cleanup
VER=`echo $VER | sed 's/[^0-9]//g'`
REL=`echo $REL | sed 's/[^0-9]//g'`

if [ -z "$CPU" -o -z "$OS" ]
then
  echo "$myname: !10! $msg_xdtarch_os_cpu"
  exit 10
fi

if [ -z "$VER" -o -z "$REL" ]
then
  echo "$myname: !11! $msg_xdtarch_ver_rel"
  exit 11
fi

# Add leading zeroes
REL=`echo 0$REL | sed 's/.*\(..\)/\1/'`
VER=`echo 0$VER | sed 's/.*\(..\)/\1/'`

# 6) So we now know it all

syscode=$CPU$OS$VER$REL

if  test -n "$codeonly"
then
    echo $CPU$OS
    exit 0
fi

if  test -n "$osonly"
then
    echo $VER$REL
    exit 0
fi

# 7) Check for codes given on the command line

if [ ! -z "$checkcodes" ]
then
    for i in $checkcodes
    do
	# Filter the input $checkcodes by matching CPU and OS, and strip
	# them off leaving just the VER and REL.  The tr command replaces
	# spaces by line-feeds, so that the following sort can do its stuff.
	posscodes=`echo $checkcodes | tr ' ' '\012' \
				| sed -ne "s/$CPU$OS//p" | sort -n`
	if [ -z "$posscodes" ]
	then				# None supplied for correct CPU+OS
	    echo >&2 "$myname: !5! $msg_xdtarch_no_match"
	    exit 5
	fi 

	# Some of them are the right platform.
	# The following algorithm returns the greatest possible code which
	# is older than this syscode, or, failing that, the least possible
	# code which is more recent than this one.

	for ver_rel in $posscodes
	do
	    if [ $VER$REL -eq $ver_rel ]
	    then 			# bingo we have this exact release
		echo $syscode
		exit 0
	    elif [ $VER$REL -gt $ver_rel ]
	    then 			# store this previous version
		priorcode=$CPU$OS$ver_rel
	    else 			# $VER$REL is < $ver_rel
		if [ -n "$priorcode" ]
		then
		    echo $priorcode
		    exit 0
		else
		    # Oh dear, we have no previous version so we should use
		    # the oldest newer version which is this current one ...
		    echo $CPU$OS$ver_rel
		    exit 0
		fi
	    fi
	done
    done
    if [ -n "$priorcode" ]
    then
        echo $priorcode
        exit 0
    fi
else
    if [ -n "$displayname" ]
    then
	echo "$NAME"
    else
	echo $syscode
    fi
fi

}
MACHINEARCH=`machinearch`
MACHINEFLAVOR=""
LSBFLAVOR=""
if [  `expr $MACHINEARCH : ..li....` -ne 0 ] ; then
	distrib=`ls /etc/*-release 2>/dev/null`
	n_distrib=`echo $distrib | LANG=C LC_ALL=C tr '[A-Z]' '[a-z]'`
        
        for f_distrib in $n_distrib ; do 
	  case "$f_distrib" in
	    *turbolinux* )
	        MACHINEFLAVOR="turbolinux"
		;;
	    *suse* )
	        MACHINEFLAVOR="suse"
	        ;;
	    *caldera* )
                MACHINEFLAVOR="caldera"
                ;;
	    *redhat*|*fedora* )
	        MACHINEFLAVOR="redhat"
	        ;;
            *lsb* )
                eval `grep ^DISTRIB_ID /etc/lsb-release`
                case "$DISTRIB_ID" in
                 *SuSE* )
                        LSBFLAVOR="suse"
                        ;;
                 "SCO Linux"* ) 
                        LSBFLAVOR="scolinux"
                        ;;
                 *UnitedLinux* ) 
                        LSBFLAVOR="unitedlinux"
                        ;;
                esac
                ;;
	    * )
		# Caldera and Debian don't have a -release.
		# But Debian has a debian_version
		if [ -f /etc/debian_version ] ; then
			MACHINEFLAVOR="debian"
		else
			distrib=`rpm -q -a 2>/dev/null | grep OpenLinux 2>/dev/null`
			r_distrib=`echo $distrib | LANG=C LC_ALL=C tr '[A-Z]' '[a-z]'`
			case "$r_distrib" in
				*openlinux* )
					MACHINEFLAVOR="caldera"
					;;
			esac
		fi
     		;;
	  esac
        done
        # use the LSB flavor iff we haven't determined a flavor from files
        # and packages.
        if [ -z "$MACHINEFLAVOR" -a  ! -z "$LSBFLAVOR" ] ; then
                MACHINEFLAVOR=$LSBFLAVOR
        fi
fi




#versioninfo
# Version numbers
PRODUCT_VERSION="5.40.966"
PRODUCT_VERSION_FULL="5.40.966"
PRODUCT_VERSION_MAJOR=5
PRODUCT_VERSION_FEATURE=4
PRODUCT_VERSION_BUG=0
PRODUCT_VERSION_BUILD=966
PRODUCT_VERSION_BUILD_DECIMAL=966
PRODUCT_VERSION_AS_NUMBER=540966
PRODUCT_VERSION_CAB=5,4,0,966
PRODUCT_VERSION_RPM=5.40-966

# Product names
PRODUCT_FULL_NAME="Oracle Secure Global Desktop"
PRODUCT_SHORT_NAME="Secure Global Desktop"
PRODUCT_IDENT="SSGD"
PRODUCT_SHORT_FILENAME="Tarantella"
PRODUCT_LSBSCRIPTNAME="sun.com-sgd-base"
PRODUCT_LSBSCRIPT_RUN_LEVEL="90"
TSP_FULL_NAME="Oracle Secure Global Desktop Security Pack"
TSP_SHORT_NAME="Security Pack"
WCP_FULL_NAME="Oracle Secure Global Desktop Windows Connectivity Pack"
WCP_SHORT_NAME="Windows Connectivity Pack"
TN3270_FULL_NAME="Oracle Secure Global Desktop Mainframe Connectivity Pack"
TN3270_SHORT_NAME="Mainframe Connectivity Pack"
AS400_FULL_NAME="Oracle Secure Global Desktop AS/400 Connectivity Pack"
AS400_SHORT_NAME="AS/400 Connectivity Pack"
S1PSTK_FULL_NAME="Oracle Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_FULL_NAME="Oracle Secure Global Desktop Integration Pack for Sun ONE Portal Server"
S1PSTK_SHORT_NAME="Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_SHORT_NAME="Secure Global Desktop Integration Pack for Sun ONE Portal Server"

OBJECT_MGR_NAME="Object Manager"
ARRAY_MGR_NAME="Array Manager"
NATIVE_WIN16_FULL_NAME="Oracle Secure Global Desktop Native Client for Windows 3.1"
NATIVE_WIN16_SHORT_NAME="Native Client for Windows 3.1"
NATIVE_WIN32_FULL_NAME="Oracle Secure Global Desktop Native Client for Windows 95, 98 and NT"
NATIVE_WIN32_SHORT_NAME="Native Client for Windows 95, 98 and NT"
NATIVE_WYSE_FULL_NAME="Oracle Secure Global Desktop Native Client for Wyse"
NATIVE_WYSE_SHORT_NAME="Native Client for Wyse"
NATIVE_FULL_NAME="Oracle Secure Global Desktop Native Client"
NATIVE_SHORT_NAME="Native Client"
NATIVE_REGISTRY_NAME="Tarantella Native Client"
INTCLI_FULL_NAME="Oracle Secure Global Desktop Client"
INTCLI_SHORT_NAME="Client"
TCC_FULL_NAME="Oracle Secure Global Desktop Client"
TCC_HELPER_NAME="Oracle Secure Global Desktop Client Helper"
TCC_ACTIVEX_NAME="Oracle Secure Global Desktop ActiveX Control"
TCC_PLUGIN_NAME="Oracle Secure Global Desktop Netscape Plug-in"
T3COMPONENT_WIN_NAME="Oracle Secure Global Desktop Enhancement Module for Windows"
T3COMPONENT_UNIX_NAME="Oracle Secure Global Desktop Enhancement Module for UNIX(TM) and Linux Platforms"
T3COMPONENT_SHORT_UNIX_NAME="tem"
T3COMPONENT_NAME="Oracle Secure Global Desktop Enhancement Module"
T3COMPONENT_LSBSCRIPTNAME="sun.com-sgd-em"
T3COMPONENT_LSBSCRIPT_RUN_LEVEL="90"
GWCOMPONENT_UNIX_NAME="Oracle Secure Global Desktop Gateway for UNIX(TM) and Linux Platforms"
GWCOMPONENT_NAME="Oracle Secure Global Desktop Gateway"
GWCOMPONENT_SHORTNAME="SGD Gateway"
GWCOMPONENT_LSBSCRIPTNAME="sun.com-sgd-gw"
GWCOMPONENT_LSBSCRIPT_RUN_LEVEL="91"

# Watch the length of these names: IE refuses to remove packages if
# the name is too long.
ARCHIVE_NAME_ttalw="TCC Helper, version"
ARCHIVE_NAME_asad="3.x Framework Java Archive"
#ARCHIVE_NAME_tta="3.x Java Archive"
#ARCHIVE_NAME_tta="3.x Combined Java Archive"
ARCHIVE_NAME_tta="Client, "
ARCHIVE_NAME_tsp="3.x Security Java Archive"
ARCHIVE_NAME_proxy="3.x Proxy Java Archive"
WEBSTART_JAR_NAME="sgdwscs"
ARCHIVE_SUFFIX="K"

NS_REGKEY="java/download/com/tarantella/tta"

PRODUCT_VENDOR="Oracle Corporation, Inc."
PRODUCT_SHORT_VENDOR="Oracle"

# Capabilities:
# The format for the capabilities required by the client end of a
# connection is: CAPABILITIES_protocol_type_REQUIRED="expression"

# The format for the capabilities provided by the server end of a
# connection is: CAPABILITIES_protocol_type_PROVIDED="c1 c2 ... c3"

# Asad between a webtop client and server:
CAPABILITIES_ASAD_WEBTOPCLIENT_REQUIRED="(1.1 || 1.2)"
CAPABILITIES_ASAD_WEBTOPCLIENT_PROVIDED="1.1 1.2"

# Asad between two peer servers, or an admin tool and a server:
# 1.1 is core E3 array functionality.
# 1.2 is 3.01 array interoperability functionality.
# 2.1 is core Pisa client device mapping functionality (not a requirement)
CAPABILITIES_ASAD_PEER_REQUIRED="(1.1 || 1.2)"
CAPABILITIES_ASAD_PEER_PROVIDED="1.1 1.2 2.1"

# Client versions of server strings; same format, name prefixed by CLIENT
# Asad between a webtop client and server:
CLIENTCAPABILITIES_ASAD_WEBTOPCLIENT_REQUIRED="(1.1 || 1.2)"
CLIENTCAPABILITIES_ASAD_WEBTOPCLIENT_PROVIDED="1.1 1.2"

# Top-level item names in ENS datastore
DEFAULT_ROOT_ENS="organization"
SYSTEM_ROOT_ENS="Tarantella System Objects"
APP_ROOT_ENS="applications"
APPSERVER_ROOT_ENS="appservers"

WEB_SERVICES_VERSION=1.5
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
# Modify these lists whenever the list of supported upgrades changes.
#
# The lists are egrep regular expressions.  Spaces can be inserted
# for readability: they are squeezed out at run time.
#
# POSSIBLE_UPGRADES is a full list of previous versions which stand
# a reasonable chance of being upgradable, although they may not
# necessarily all be supported.
#
# SUPPORTED_UPGRADES are the previous versions from which upgrades
# are officially supported.  SUPPORTED_UPGRADES should either be
# identical to POSSIBLE_UPGRADES, or a subset of POSSIBLE_UPGRADES.
#
POSSIBLE_UPGRADES='4\.63\.9[0-9][0-9] | 4\.71\.9[0-9][0-9] | 5\.(00|10|20|30)\.9[0-9][0-9]'
SUPPORTED_UPGRADES="${POSSIBLE_UPGRADES}"

#Marks RPM as obsoleting this version and below.
RPM_OBSOLETES=5.10
# the License Product Code
PRODUCT_LICENSE_PRODUCT_CODE="8388608"
TSP_US_LICENSE_PRODUCT_CODE="4194304"
TSP_INTL_LICENSE_PRODUCT_CODE="2097152"
USER_RESTRICTION="1"


#packageinfo
# Version numbers
PRODUCT_VERSION="5.40.966"
PRODUCT_VERSION_FULL="5.40.966"
PRODUCT_VERSION_MAJOR=5
PRODUCT_VERSION_FEATURE=4
PRODUCT_VERSION_BUG=0
PRODUCT_VERSION_BUILD=966
PRODUCT_VERSION_BUILD_DECIMAL=966
PRODUCT_VERSION_AS_NUMBER=540966
PRODUCT_VERSION_CAB=5,4,0,966
PRODUCT_VERSION_RPM=5.40-966

# Product names
PRODUCT_FULL_NAME="Oracle Secure Global Desktop"
PRODUCT_SHORT_NAME="Secure Global Desktop"
PRODUCT_IDENT="SSGD"
PRODUCT_SHORT_FILENAME="Tarantella"
PRODUCT_LSBSCRIPTNAME="sun.com-sgd-base"
PRODUCT_LSBSCRIPT_RUN_LEVEL="90"
TSP_FULL_NAME="Oracle Secure Global Desktop Security Pack"
TSP_SHORT_NAME="Security Pack"
WCP_FULL_NAME="Oracle Secure Global Desktop Windows Connectivity Pack"
WCP_SHORT_NAME="Windows Connectivity Pack"
TN3270_FULL_NAME="Oracle Secure Global Desktop Mainframe Connectivity Pack"
TN3270_SHORT_NAME="Mainframe Connectivity Pack"
AS400_FULL_NAME="Oracle Secure Global Desktop AS/400 Connectivity Pack"
AS400_SHORT_NAME="AS/400 Connectivity Pack"
S1PSTK_FULL_NAME="Oracle Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_FULL_NAME="Oracle Secure Global Desktop Integration Pack for Sun ONE Portal Server"
S1PSTK_SHORT_NAME="Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_SHORT_NAME="Secure Global Desktop Integration Pack for Sun ONE Portal Server"

OBJECT_MGR_NAME="Object Manager"
ARRAY_MGR_NAME="Array Manager"
NATIVE_WIN16_FULL_NAME="Oracle Secure Global Desktop Native Client for Windows 3.1"
NATIVE_WIN16_SHORT_NAME="Native Client for Windows 3.1"
NATIVE_WIN32_FULL_NAME="Oracle Secure Global Desktop Native Client for Windows 95, 98 and NT"
NATIVE_WIN32_SHORT_NAME="Native Client for Windows 95, 98 and NT"
NATIVE_WYSE_FULL_NAME="Oracle Secure Global Desktop Native Client for Wyse"
NATIVE_WYSE_SHORT_NAME="Native Client for Wyse"
NATIVE_FULL_NAME="Oracle Secure Global Desktop Native Client"
NATIVE_SHORT_NAME="Native Client"
NATIVE_REGISTRY_NAME="Tarantella Native Client"
INTCLI_FULL_NAME="Oracle Secure Global Desktop Client"
INTCLI_SHORT_NAME="Client"
TCC_FULL_NAME="Oracle Secure Global Desktop Client"
TCC_HELPER_NAME="Oracle Secure Global Desktop Client Helper"
TCC_ACTIVEX_NAME="Oracle Secure Global Desktop ActiveX Control"
TCC_PLUGIN_NAME="Oracle Secure Global Desktop Netscape Plug-in"
T3COMPONENT_WIN_NAME="Oracle Secure Global Desktop Enhancement Module for Windows"
T3COMPONENT_UNIX_NAME="Oracle Secure Global Desktop Enhancement Module for UNIX(TM) and Linux Platforms"
T3COMPONENT_SHORT_UNIX_NAME="tem"
T3COMPONENT_NAME="Oracle Secure Global Desktop Enhancement Module"
T3COMPONENT_LSBSCRIPTNAME="sun.com-sgd-em"
T3COMPONENT_LSBSCRIPT_RUN_LEVEL="90"
GWCOMPONENT_UNIX_NAME="Oracle Secure Global Desktop Gateway for UNIX(TM) and Linux Platforms"
GWCOMPONENT_NAME="Oracle Secure Global Desktop Gateway"
GWCOMPONENT_SHORTNAME="SGD Gateway"
GWCOMPONENT_LSBSCRIPTNAME="sun.com-sgd-gw"
GWCOMPONENT_LSBSCRIPT_RUN_LEVEL="91"

# Watch the length of these names: IE refuses to remove packages if
# the name is too long.
ARCHIVE_NAME_ttalw="TCC Helper, version"
ARCHIVE_NAME_asad="3.x Framework Java Archive"
#ARCHIVE_NAME_tta="3.x Java Archive"
#ARCHIVE_NAME_tta="3.x Combined Java Archive"
ARCHIVE_NAME_tta="Client, "
ARCHIVE_NAME_tsp="3.x Security Java Archive"
ARCHIVE_NAME_proxy="3.x Proxy Java Archive"
WEBSTART_JAR_NAME="sgdwscs"
ARCHIVE_SUFFIX="K"

NS_REGKEY="java/download/com/tarantella/tta"

PRODUCT_VENDOR="Oracle Corporation, Inc."
PRODUCT_SHORT_VENDOR="Oracle"

# Capabilities:
# The format for the capabilities required by the client end of a
# connection is: CAPABILITIES_protocol_type_REQUIRED="expression"

# The format for the capabilities provided by the server end of a
# connection is: CAPABILITIES_protocol_type_PROVIDED="c1 c2 ... c3"

# Asad between a webtop client and server:
CAPABILITIES_ASAD_WEBTOPCLIENT_REQUIRED="(1.1 || 1.2)"
CAPABILITIES_ASAD_WEBTOPCLIENT_PROVIDED="1.1 1.2"

# Asad between two peer servers, or an admin tool and a server:
# 1.1 is core E3 array functionality.
# 1.2 is 3.01 array interoperability functionality.
# 2.1 is core Pisa client device mapping functionality (not a requirement)
CAPABILITIES_ASAD_PEER_REQUIRED="(1.1 || 1.2)"
CAPABILITIES_ASAD_PEER_PROVIDED="1.1 1.2 2.1"

# Client versions of server strings; same format, name prefixed by CLIENT
# Asad between a webtop client and server:
CLIENTCAPABILITIES_ASAD_WEBTOPCLIENT_REQUIRED="(1.1 || 1.2)"
CLIENTCAPABILITIES_ASAD_WEBTOPCLIENT_PROVIDED="1.1 1.2"

# Top-level item names in ENS datastore
DEFAULT_ROOT_ENS="organization"
SYSTEM_ROOT_ENS="Tarantella System Objects"
APP_ROOT_ENS="applications"
APPSERVER_ROOT_ENS="appservers"

WEB_SERVICES_VERSION=1.5
# The special name values are limited to 53 characters (including "Tarantella")
# well only 53 characters of the complete name is displayed in the --info
# option of the shx file

PRODUCT_PACKAGE_TYPES="pkg rpm"

PRODUCT_TTA_PKGNAME="tta"
PRODUCT_TSP_PKGNAME="ttasecure"
PRODUCT_WCP_PKGNAME="ttawcp"
PRODUCT_PIP_PKGNAME="ttapip"
PRODUCT_3270_PKGNAME="tta3270"
PRODUCT_5250_PKGNAME="tta5250"
PRODUCT_TEM_PKGNAME="tem"
PRODUCT_TIER3TEM_PKGNAME="tem"
PRODUCT_GW_PKGNAME="SUNWsgdg"

PRODUCT_S1PSTK_PKGNAME="tcs1"
PRODUCT_S1PSIP_PKGNAME="tis1"

PRODUCT_PACKAGELIST_S1PSTK="tcs1"
PRODUCT_PACKAGELIST_S1PSIP="tis1"
PRODUCT_PACKAGE_SPECIAL_PRENAME_tcs1pt=""
PRODUCT_PACKAGE_SPECIAL_NAME_tcs1pt=" $S1PSTK_SHORT_NAME patch $PRODUCT_VERSION_FULL"
PRODUCT_PACKAGE_CATEGORY_tcs1pt="application"

PRODUCT_PACKAGE_SPECIAL_NAME_tis1pt=" $S1PSIP_SHORT_NAME patch $PRODUCT_VERSION_FULL"
PRODUCT_PACKAGE_CATEGORY_tis1pt="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tcs1=""
PRODUCT_PACKAGE_SPECIAL_NAME_tcs1=" $S1PSTK_SHORT_NAME"
PRODUCT_PACKAGE_CATEGORY_tcs1="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tis1=""
PRODUCT_PACKAGE_SPECIAL_NAME_tis1=" $S1PSIP_SHORT_NAME"
PRODUCT_PACKAGE_CATEGORY_tis1="application"

PRODUCT_PACKAGELIST_BASE="tta ttapip ttawcp ttasecure tta3270 tta5250 ttafandr ttafhang ttaficl ttaforie ttafscot"
PRODUCT_PACKAGELIST_TSP="ttasecure"
PRODUCT_PACKAGELIST_WCP="ttawcp"
PRODUCT_PACKAGELIST_3270="tta3270"
PRODUCT_PACKAGELIST_5250="tta5250"
PRODUCT_PACKAGELIST_TEM="tem"
PRODUCT_PACKAGELIST_TIER3TEM="tem"
PRODUCT_PACKAGELIST_ARCHIVE=""
PRODUCT_PACKAGELIST_NULL="ttafandr ttafhang ttaficl ttaforie ttafscot"
PRODUCT_PACKAGELIST_FONTS="ttafandr ttafhang ttaficl ttaforie ttafscot"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tta=""
PRODUCT_PACKAGE_SPECIAL_NAME_tta=""
PRODUCT_PACKAGE_CATEGORY_tta="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttasecure=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttasecure=" Security Pack"
PRODUCT_PACKAGE_CATEGORY_ttasecure="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttawcp=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttawcp=" Windows Connectivity Pack"
PRODUCT_PACKAGE_CATEGORY_ttawcp="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttafandr=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttafandr=" Andrew Fonts"
PRODUCT_PACKAGE_CATEGORY_ttafandr="graphics"
PRODUCT_PACKAGE_DIR_ttafandr="fonts/andrew"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttafhang=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttafhang=" Hangul Fonts"
PRODUCT_PACKAGE_CATEGORY_ttafhang="graphics"
PRODUCT_PACKAGE_DIR_ttafhang="fonts/hangul"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttaficl=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttaficl=" ICL Fonts"
PRODUCT_PACKAGE_CATEGORY_ttaficl="graphics"
PRODUCT_PACKAGE_DIR_ttaficl="fonts/icl"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttaforie=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttaforie=" Oriental Fonts"
PRODUCT_PACKAGE_CATEGORY_ttaforie="graphics"
PRODUCT_PACKAGE_DIR_ttaforie="fonts/oriental"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttafscot=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttafscot=" SCO Term Fonts"
PRODUCT_PACKAGE_CATEGORY_ttafscot="graphics"
PRODUCT_PACKAGE_DIR_ttafscot="fonts/scoterm"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttapatch=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttapatch=" Patch $PRODUCT_VERSION_FULL"
PRODUCT_PACKAGE_CATEGORY_ttapatch="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tta3270pt=""
PRODUCT_PACKAGE_SPECIAL_NAME_tta3270pt=" $TN3270_SHORT_NAME patch $PRODUCT_VERSION_FULL"
PRODUCT_PACKAGE_CATEGORY_tta3270pt="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tta5250pt=""
PRODUCT_PACKAGE_SPECIAL_NAME_tta5250pt=" $AS400_SHORT_NAME patch $PRODUCT_VERSION_FULL"
PRODUCT_PACKAGE_CATEGORY_tta5250pt="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tsppatch=""
PRODUCT_PACKAGE_SPECIAL_NAME_tsppatch=" Security Pack Patch $PRODUCT_VERSION_FULL"
PRODUCT_PACKAGE_CATEGORY_tsppatch="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_gunzip="GNU gunzip for "
PRODUCT_PACKAGE_SPECIAL_NAME_gunzip=""
PRODUCT_PACKAGE_CATEGORY_gunzip="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tta3270=""
PRODUCT_PACKAGE_SPECIAL_NAME_tta3270=" $TN3270_SHORT_NAME"
PRODUCT_PACKAGE_CATEGORY_tta3270="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tta5250=""
PRODUCT_PACKAGE_SPECIAL_NAME_tta5250=" $AS400_SHORT_NAME"
PRODUCT_PACKAGE_CATEGORY_tta5250="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_ttapip=""
PRODUCT_PACKAGE_SPECIAL_NAME_ttapip=" Platform Identity Pack"
PRODUCT_PACKAGE_CATEGORY_ttapip="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_tem=""
PRODUCT_PACKAGE_SPECIAL_NAME_tem=" Enhancement Module"
PRODUCT_PACKAGE_CATEGORY_tem="application"

PRODUCT_PACKAGE_SPECIAL_PRENAME_SUNWsgdg=""
PRODUCT_PACKAGE_SPECIAL_NAME_SUNWsgdg=" Gateway"
PRODUCT_PACKAGE_CATEGORY_SUNWsgdg="application"

# be paranoid about the current path
if [ -d /bin ]; then
  PATH=/bin:$PATH
fi
if [ -d /sbin ]; then
  PATH=/sbin:$PATH
fi
if [ -d /usr/bin ]; then
  PATH=/usr/bin:$PATH
fi
if [ -d /usr/sbin ]; then
  PATH=/usr/sbin:$PATH
fi
if [ -d /etc ]; then
  PATH=/etc:$PATH
fi
export PATH

N=""
C=""
if echo -n | grep n > /dev/null
then
  C="\c"
else
  N="-n"
fi
case "$MACHINEARCH" in
i3li*|ppli*) N="$N -e" ;;
esac
_ss_headlines="--------------------------------------------------------------------------"

# get our ported package tools on the head of the path
if [ -d /usr/package/sadm/install/bin ]
then
    PATH=/var/sadm/install/bin:$PATH
fi

if [ -z "$0" ]; then
  who_i_am=""
else
  who_i_am=`expr "//$0" : '.*/\(.*\)' `
fi


if [ -z "$REQDIR" ]
then
    if [ -n "$INST_DATADIR" ]
    then
	REQDIR=${INST_DATADIR}/${PKG}/install
    else
	REQDIR=''
    fi
fi

posslangs=`(cd "$REQDIR" ; ls ??-??_setup 2>/dev/null)`
case $posslangs in
  "" )						# no languages!
    PKGLANG=""
    echo "Can't find any language files in directory $REQDIR" >>$LOGFILE
    exit 1
  ;;
  ??-??_setup )    					# Good; just one
    PKGLANG=`expr "$posslangs" : "\(..-..\)"`
  ;;
  * )						# Choices, choices
    case $LANG in
      ""|C|POSIX )
      ;;					# Ignored
      * )					# Some OS specific string
        LA=`expr $LANG : "\(..\)"`    		# 1st two chars
        # must ensure tr uses C locale to lower case!
	la=`echo $LA | LANG=C LC_ALL=C tr '[A-Z]' '[a-z]'`
	goodlangs=`echo "$posslangs" | grep "^$la"`
	if [ -n "$goodlangs" ]
	then
	  posslangs=$goodlangs			# ones that match $LANG
        fi
	;;
    esac
    # Pick the first language in posslangs, or en-us if that is empty
    if [ -z "$posslangs" ]; then
	PKGLANG="en-us"
    else
	PKGLANG=`expr "$posslangs" : "\(..-..\)"`
    fi
  ;;
esac
if [ -n "$PKGLANG" ]; then
    # read the strings in
    . ${REQDIR}/${PKGLANG}_setup
    # store the strings file in the $PKGSAV directory
    if [ -n "${PKGSAV}" -a "${PKGSAV}" != "/" -a -d "${PKGSAV}" -a ! -f ${PKGSAV}/${PKGLANG}_setup ]; then
	cp ${REQDIR}/${PKGLANG}_setup ${PKGSAV}/${PKGLANG}_setup >/dev/null 2>&1
    fi
fi

WrapText()
{
    awk 'BEGIN {
	maxwidth = '${1:-74}'
    }
    {
	remtext = $0; remlen = length(remtext)
	while (remlen > 0) {
	    fraglen = remlen
	    if (fraglen > maxwidth) {
		fraglen = maxwidth
		# Move the split point back to a word boundary if necessary.
		# If unable to do that, just split at maxwidth anyway.
		while (fraglen > 0 && substr(remtext,fraglen,2) ~ /[^ 	][^ 	]/) --fraglen
		if (fraglen < 1) fraglen = maxwidth
	    }
	    print substr(remtext,1,fraglen)
	    if ((remlen -= fraglen) > 0) {
		startat = fraglen+1
		# omit whitespace at the beginning of the next line
		while (remlen > 0 && substr(remtext,startat,1) ~ /[ 	]/) { ++startat; --remlen }
		if (remlen > 0) remtext = substr(remtext,startat,remlen)
	    }
	}
    }'
}

privusr="temsys"
privgrp="temserv"


a_base_definstdir="/opt"
a_definstdir="/opt/tta_tem"
a_definstdir2="/usr/tta_tem"
a_propsdir="var/serverconfig/local"
a_propsdir_save="var/serverconfig/local/save"
a_propsfile="tier3loadbalancing.properties"
a_temppropsfile="/tmp/tier3loadbalancing.properties"
a_piddir="var/info"
a_pidfile="tier3loadprobe.pid"
a_logdir="var/log"
a_binaryfile="tier3loadprobe"

a_ttatdmfile="ttatdm"
a_ttatdmclfile="ttatdmcl"
a_ttatdmconfigdir="etc"
a_ttatdmconfigfile="client.prf"

portKey="tarantella.config.tier3loadbalancing.port"
mVmemKey="tarantella.config.tier3loadbalancing.maxvirtualmemory"
mPmemKey="tarantella.config.tier3loadbalancing.maxphysicalmemory"
mLogDir="tarantella.config.tier3loadbalancing.logdirectory"
mPidDir="tarantella.config.tier3loadbalancing.piddirectory"
mProbePath="tarantella.config.tier3loadbalancing.probepath"

TMPFILE=$TTA_TMPDIR/propfile
TIDY_SCRIPT=${INSTDIR}/var/tmp/tta.tidy_$$
PROPDIR="$INSTDIR/$a_propsdir"
PIDDIR="$INSTDIR/var/info"
VARLOGDIR="$INSTDIR/var/log"
BINDIR="$INSTDIR/bin"
TEMFILE="$BINDIR/tem"
OLD_INST_RCFILE="S90$T3COMPONENT_SHORT_UNIX_NAME"
OLD_KILL_RCFILE="K90$T3COMPONENT_SHORT_UNIX_NAME"
OLD_INST_RCSTRING="##$T3COMPONENT_SHORT_UNIX_NAME##"
LSB_INST_RCFILE="S90${T3COMPONENT_LSBSCRIPTNAME}"
LSB_INST_RCSTRING="##${T3COMPONENT_LSBSCRIPTNAME}##"
LSB_INST_RCFILE_FULLNAME="$INSTDIR/etc/templates/etc/data/$LSB_INST_RCFILE"

echo "`date`:*** POSTINSTALL STARTS ***" >>$LOGFILE

_DEPS="${INSTDIR}/var/info/_dependencies"
[ -n "${TTA_RPM}" -a -s "${_DEPS}" ] && (
    cd ${INSTDIR}
    for _f in `cat ${_DEPS}`; do
	[ -f "${_f}" ] || continue
	f=`expr "${_f}" : '.\(.*\)'`
	f=`echo "${_f}" | sed 's|/_\([^/]*\)$|/\1|'`
	rm -f ${f} 2>/dev/null
	cp -p ${_f} ${f}
	dd bs=2 skip=1 if=${_f} of=${f} >/dev/null 2>&1
	rm -f ${_f} 2>/dev/null
    done
    rm -f ${_DEPS} 2>/dev/null
)


NEWPROPSFILE=$PROPDIR/$a_propsfile

SGDTEMCFG=/etc/sgdtem.conf
rm -f $SGDTEMCFG ${INSTDIR}${SGDTEMCFG} 2>/dev/null
echo "SGDUNIXAUDIODEBUG=0; export SGDUNIXAUDIODEBUG">>$SGDTEMCFG
echo "SGDTEMINSTDIR=$INSTDIR; export SGDTEMINSTDIR">>$SGDTEMCFG

#There is an error in the postremove script of tem 4.31.905 
#which removes the sgdtem.conf file during an upgrade. Make a copy of sgdtem.conf
#and use the TidyScript to reinstate it after the rmpkg of the previous tem intallation
#only needed on solaris as postinstall is run after postremove on linux
SaveConfig() {
    [  `expr $MACHINEARCH : ..so....` -ne 0 ] && cp -f ${SGDTEMCFG} ${SGDTEMCFG}.save
}
SaveConfig

UNIXAUDIOLOGFILE=$VARLOGDIR/tem_unixaudio_inst.log
UNIXSERIOLOGFILE=$VARLOGDIR/tem_unixserio_inst.log
rm -f $UNIXAUDIOLOGFILE $UNIXSERIOLOGFILE

cleanup()
{
    trap '' 1 2 3 15
    echo "<--- $who_i_am" >>$LOGFILE
    rm -f ${TMP_RC}.append
    rm -f ${TMP_RC}.full
    [ -n "${TTA_TMPDIR}" -a "${TTA_TMPDIR}" != "/" -a -f "${TTA_TMPDIR}/locale.tar" ] && rm -rf $TTA_TMPDIR/locale $TTA_TMPDIR/locale.tar 2>/dev/null
}

cleanandexit()
{
    cleanup
    [ "$1" -eq 0 -a -z "$2" -a -z "${TTA_RPM}" ] && {
_parent=`dirname "${TTA_TMPDIR}"`
_base=`basename "${TTA_TMPDIR}"`
case "${_base}" in
ttainst_[0-9]*|ttarpm*) (
    dashes="=========================================================================="
    cd ${_parent}
    for log in ttainst_[0-9]*/*.log ttarpm*/*.log; do
	[ -s "${log}" ] && {
	    echo "${dashes}" >>tta_inst.log
	    echo "${log}" >>tta_inst.log
	    echo "${dashes}" >>tta_inst.log
	    cat "${log}" >>tta_inst.log 2>/dev/null
	    rm -rf "${log}" >>tta_inst.log 2>/dev/null
	}
    done
    rmdir ttainst_[0-9]* ttarpm* 2>/dev/null
)
esac

    }
    exit $1
}
# This method is intended to take any saved tier3loadbalancing.properties file
# from a previous installation and upgrade it
doUpgradePropsFile()
{
    if [ ! -z "$SAVEDPROPSFILE" ]
    then
        if [ ! -z "$SAVEDPROPSFILE" -a -f $SAVEDPROPSFILE ]
        then
            # copy the saved properties over the new file
            echo "Move saved properties file $SAVEDPROPSFILE to $NEWPROPSFILE" >>$LOGFILE
            mv $SAVEDPROPSFILE $NEWPROPSFILE
        fi
    fi
}

AddRC()
{
    # Create new installation.
    echo "*** AddRC starts ***" >>$LOGFILE
    # work out the rctype
a_KillFile="" a_RcCurRun="" a_RcInstRun="" a_RcKillRun="" a_RcType="unknown" a_RcFile=""
if [ -d /etc/rc.d/rc2.d -o -d /etc/rc.d/rc3.d ]; then
  a_RcType="rcddir" a_RcFile="/etc/rc.d" a_KillFile="/etc/rc.d" _rcbase="/etc/rc.d/rc"
  [ -d /etc/init.d ] && a_RcType="$a_RcType-initd"
elif [ -d /etc/rc2.d -o -d /etc/rc3.d ]; then
  a_RcType="svr4" a_RcFile="/etc" a_KillFile="/etc" _rcbase="/etc/rc"
  [ -d /etc/init.d ] && a_RcType="$a_RcType-initd"
elif [ -d /sbin/rc2.d -o -d /sbin/rc3.d ]; then
  a_RcType="sbin" a_RcFile="/sbin" a_KillFile="/sbin" _rcbase="/sbin/rc"
elif [ -f /etc/rc.local ]; then
  a_RcType="local" a_RcFile="/etc/rc.local"
elif [ -f /etc/rc.d/rc.local ]; then
  a_RcType="rcd" a_RcFile="/etc/rc.d/rc.local"
elif [ -f /etc/rc.nfs ]; then
  a_RcType="nfs" a_RcFile="/etc/rc.nfs"
elif [ -f /etc/rc ]; then
  a_RcType="basic" a_RcFile="/etc/rc"
fi
case "$a_RcType" in
svr4*|sbin|rcddir*)
  a_RcCurRun=`who -r 2>/dev/null | awk '{print $3;}'`
  [ ! -z "$a_RcCurRun" ] && {
    case $a_RcCurRun in [0-9]);; *) a_RcCurRun=`who -r 2>/dev/null | awk '{print $2;}'`;; esac;
  } || a_RcCurRun=`/sbin/runlevel 2>/dev/null | awk '{print $2}'`;
  [ -z "$a_RcCurRun" ] && a_RcCurRun=2 # guess
  a_RcKillRun=1
  for _i in 5 4 3 2 1 S; do
    [ -r ${_rcbase}${_i}.d/$LSB_INST_RCFILE ] && { a_RcInstRun=${_i}; break; }
  done
  a_KillFile=$a_RcFile/rc$a_RcKillRun.d/$OLD_KILL_RCFILE
  a_RcFile=$a_RcFile/rc$a_RcCurRun.d/$LSB_INST_RCFILE
esac

    a_RunLevel="$a_RcCurRun"
    [ -n "$a_RcInstRun" ] && a_RunLevel="$a_RcInstRun"

    # add to the rc after removing existing setup
# set the defaults
_delete=false _files="_DeleteMe_"
_filename="$OLD_INST_RCFILE"
_fNam=`expr "${_filename}" : 'S[0-9][0-9]*\(.*\)'`	# eg Tarantella
# sanity check
[ -z "${_filename}" -o -z "${_fNam}" ] && _filename="_DeleteMe_" _fNam="_DeleteMe_"

[ -s "/etc/init.d/${_fNam}" ] && {
    _rclinks='t'
    [ -x "/usr/lib/lsb/remove_initd" ] && {
	/usr/lib/lsb/remove_initd "/etc/init.d/${_fNam}"
	[ -z "`find /etc/rc*.d -name \"[KS][0-9][0-9]${_fNam}\" -type l 2>/dev/null`" ] && _rclinks=''
    }
    [ -n "${_rclinks}" -a -x "/sbin/chkconfig" ] && {
	/sbin/chkconfig --del "${_fNam}"
    }
}

# create the list of files to check
case "$a_RcType" in
svr4*|sbin|rcddir*)
  _delete=true
  case "$a_RcType" in
  rcddir*) _rcbase="/etc/rc.d/rc";;
  svr4*)   _rcbase="/etc/rc";;
  sbin)	   _rcbase="/sbin/rc";;
  esac
  for _i in S 0 1 2 3 4 5 6; do
    _files="${_files} `ls -d ${_rcbase}${_i}.d/${_filename} ${_rcbase}${_i}.d/K[0-9]*${_fNam} 2>/dev/null`"
  done
  case "$a_RcType" in
  *-initd) _files="${_files} `ls -d /etc/init.d/${_fNam} 2>/dev/null`"
  esac
  ;;
"local")
  _files="${_files} /etc/rc.local"
  ;;
"rcd")
  _files="${_files} /etc/rc.d/rc.local"
  ;;
"nfs")
  _files="${_files} /etc/rc.nfs"
  ;;
"basic")
  _files="${_files} /etc/rc"
  ;;
esac

# either delete the files or substitute them depending on rc type
if [ "${_delete}" = "true" ]; then
  # Remove lockfiles
  ls "/var/lock/subsys/${_fNam}" "/var/lock/subsys/${_fNam}"-* 2>/dev/null | while read _fDel; do
      case "${_fDel}" in
      /var/lock/subsys/${_fNam}*) rm -f "${_fDel}" 2>/dev/null
      esac
  done
  for _i in ${_files}; do
    # sanity check: file name must end with ${_fNam}
    awk 'BEGIN {
      sfx = "'"${_fNam}"'"; cand = "'"${_i}"'"; file2del="_DeleteMe_"
      if (length(cand) > length(sfx) && substr(cand,length(cand)-length(sfx)+1,length(sfx)) == sfx) file2del = cand
      print file2del
      exit
    }' | xargs rm -f 
  done
  [ -n "`ls -l /sbin/rc* 2>/dev/null | grep ' -> .*/init\.d/'`" ] && {
    [ -L "/sbin/rc${_fNam}" ] && {
      # Remove dangling /sbin/rc${_fNam} symlink.  I think these are used only on SuSE Linux, but who knows ...
      ls -L "/sbin/rc${_fNam}" >/dev/null 2>&1 || rm -f "/sbin/rc${_fNam}" 2>/dev/null
    }
  }
else
  for _i in ${_files}; do
    [ "${_i}" = "_DeleteMe_" ] && continue

    # delete everything between the start and stop markers
    echo "BEGIN {" > $_i.awk
    echo "  doprint=1;" >> $_i.awk
    echo "}" >> $_i.awk
    echo "\$1 == \"$OLD_INST_RCSTRING\" {" >> $_i.awk
    echo "  if (\$2 == \"start\") {" >> $_i.awk
    echo "    doprint = 0;" >> $_i.awk
    echo "  } else {" >> $_i.awk
    echo "    doprint = 1;" >> $_i.awk
    echo "    continue;" >> $_i.awk
    echo "  }" >> $_i.awk
    echo "}" >> $_i.awk
    echo "{" >> $_i.awk
    echo "  if (doprint == 1) {" >> $_i.awk
    echo "    print" >> $_i.awk
    echo "  }" >> $_i.awk
    echo "}" >> $_i.awk

    # run the newly created awk script on the file
    if [ -f $_i.awk ]; then
      cp -p $_i $_i.tmp1 #for perms
      awk -f $_i.awk $_i > $_i.tmp1
      rm -f $_i.awk
    fi

    # move the new copy over the old
    if [ -f $_i.tmp1 ]; then
      cp -p $_i.tmp1 $_i
      rm -f $_i.tmp1
    fi
  done
fi

# set the defaults
_delete=false _files="_DeleteMe_"
_filename="$LSB_INST_RCFILE"
_fNam=`expr "${_filename}" : 'S[0-9][0-9]*\(.*\)'`	# eg Tarantella
# sanity check
[ -z "${_filename}" -o -z "${_fNam}" ] && _filename="_DeleteMe_" _fNam="_DeleteMe_"

[ -s "/etc/init.d/${_fNam}" ] && {
    _rclinks='t'
    [ -x "/usr/lib/lsb/remove_initd" ] && {
	/usr/lib/lsb/remove_initd "/etc/init.d/${_fNam}"
	[ -z "`find /etc/rc*.d -name \"[KS][0-9][0-9]${_fNam}\" -type l 2>/dev/null`" ] && _rclinks=''
    }
    [ -n "${_rclinks}" -a -x "/sbin/chkconfig" ] && {
	/sbin/chkconfig --del "${_fNam}"
    }
}

# create the list of files to check
case "$a_RcType" in
svr4*|sbin|rcddir*)
  _delete=true
  case "$a_RcType" in
  rcddir*) _rcbase="/etc/rc.d/rc";;
  svr4*)   _rcbase="/etc/rc";;
  sbin)	   _rcbase="/sbin/rc";;
  esac
  for _i in S 0 1 2 3 4 5 6; do
    _files="${_files} `ls -d ${_rcbase}${_i}.d/${_filename} ${_rcbase}${_i}.d/K[0-9]*${_fNam} 2>/dev/null`"
  done
  case "$a_RcType" in
  *-initd) _files="${_files} `ls -d /etc/init.d/${_fNam} 2>/dev/null`"
  esac
  ;;
"local")
  _files="${_files} /etc/rc.local"
  ;;
"rcd")
  _files="${_files} /etc/rc.d/rc.local"
  ;;
"nfs")
  _files="${_files} /etc/rc.nfs"
  ;;
"basic")
  _files="${_files} /etc/rc"
  ;;
esac

# either delete the files or substitute them depending on rc type
if [ "${_delete}" = "true" ]; then
  # Remove lockfiles
  ls "/var/lock/subsys/${_fNam}" "/var/lock/subsys/${_fNam}"-* 2>/dev/null | while read _fDel; do
      case "${_fDel}" in
      /var/lock/subsys/${_fNam}*) rm -f "${_fDel}" 2>/dev/null
      esac
  done
  for _i in ${_files}; do
    # sanity check: file name must end with ${_fNam}
    awk 'BEGIN {
      sfx = "'"${_fNam}"'"; cand = "'"${_i}"'"; file2del="_DeleteMe_"
      if (length(cand) > length(sfx) && substr(cand,length(cand)-length(sfx)+1,length(sfx)) == sfx) file2del = cand
      print file2del
      exit
    }' | xargs rm -f 
  done
  [ -n "`ls -l /sbin/rc* 2>/dev/null | grep ' -> .*/init\.d/'`" ] && {
    [ -L "/sbin/rc${_fNam}" ] && {
      # Remove dangling /sbin/rc${_fNam} symlink.  I think these are used only on SuSE Linux, but who knows ...
      ls -L "/sbin/rc${_fNam}" >/dev/null 2>&1 || rm -f "/sbin/rc${_fNam}" 2>/dev/null
    }
  }
else
  for _i in ${_files}; do
    [ "${_i}" = "_DeleteMe_" ] && continue

    # delete everything between the start and stop markers
    echo "BEGIN {" > $_i.awk
    echo "  doprint=1;" >> $_i.awk
    echo "}" >> $_i.awk
    echo "\$1 == \"$LSB_INST_RCSTRING\" {" >> $_i.awk
    echo "  if (\$2 == \"start\") {" >> $_i.awk
    echo "    doprint = 0;" >> $_i.awk
    echo "  } else {" >> $_i.awk
    echo "    doprint = 1;" >> $_i.awk
    echo "    continue;" >> $_i.awk
    echo "  }" >> $_i.awk
    echo "}" >> $_i.awk
    echo "{" >> $_i.awk
    echo "  if (doprint == 1) {" >> $_i.awk
    echo "    print" >> $_i.awk
    echo "  }" >> $_i.awk
    echo "}" >> $_i.awk

    # run the newly created awk script on the file
    if [ -f $_i.awk ]; then
      cp -p $_i $_i.tmp1 #for perms
      awk -f $_i.awk $_i > $_i.tmp1
      rm -f $_i.awk
    fi

    # move the new copy over the old
    if [ -f $_i.tmp1 ]; then
      cp -p $_i.tmp1 $_i
      rm -f $_i.tmp1
    fi
  done
fi


    echo "$LSB_INST_RCFILE_FULLNAME" >>$LOGFILE

    if [ "$a_RcType" != "unknown" ]
    then
        sed "s?@@TEM_DIR@@?${INSTDIR}?g" ${LSB_INST_RCFILE_FULLNAME} > ${TMP_RC}.full
        sed "s?@@TEM_DIR@@?${INSTDIR}?g" ${LSB_INST_RCFILE_FULLNAME} > ${TMP_RC}.append
        
	# Find the kill file prefix (eg K10)
	killpfx=""
        [ -n "$a_KillFile" ] && killpfx=`expr "$a_KillFile" : '.*/\(K[0-9][0-9]*\).*'`
	case "$killpfx" in K[0-9]*) ;; *) killpfx="K10" ;; esac
_rcfile="$a_RcFile|$killpfx" _KN="" _initd="" _links=""
# K prefix may have been passed in at the end of $a_RcType
case "${_rcfile}" in
*\|K*)  _KN=`expr "${_rcfile}" : '.*|K\([0-9][0-9]*\).*'`
	_rcfile=`expr "${_rcfile}" : '\(.*\)|.*'`
esac
# ... otherwise, default K prefix is 10
case "${_KN}" in [0-9][0-9]*) ;; *) _KN="10" ;; esac
_rcdir=`dirname "${_rcfile}"`
_f=`expr "${_rcfile}" : '.*/\(S[0-9][0-9]*[^/]*\)$'`	# eg S90Tarantella
_SN=`expr "${_f}" : 'S\([0-9][0-9]*\).*'`		# eg 90
_fNam=`expr "${_f}" : 'S[0-9][0-9]*\(.*\)'`		# eg Tarantella
# sanity check
[ -z "${_f}" -o -z "${_fNam}" ] && _f="_DeleteMe_" _fNam="_DeleteMe_"
_abs_rcfile="${_rcfile}"; _rel_rcfile="${_abs_rcfile}"
case "$a_RcType" in
*-initd) # on this platform rc files are symlinks to real file in /etc/init.d
  _initd="t" _abs_rcfile="/etc/init.d/${_fNam}"; _rel_rcfile="${_abs_rcfile}"
  # compute relative pathname for symlinks
  case "${_rcdir}" in
  /etc/*)
    _dir="${_rcdir}" _rel_rcfile="init.d/${_fNam}"
    while [ "${_dir}" != "/etc" -a "${_dir}" != "/" ]; do
      _dir=`dirname "${_dir}"` _rel_rcfile="../${_rel_rcfile}"
    done
  esac
esac
case "$a_RcType" in
svr4*|sbin|rcddir*)
  # check the directory exists, doesn't get here unless they've already been
  # asked if they want it created
  [ ! -d "${_rcdir}" ] && mkdir "${_rcdir}"
  cat ${TMP_RC}.full > "${_rcfile}.tmp1"
  chmod a+x "${_rcfile}.tmp1"
  if [ ! -x /usr/lib/lsb/install_initd -a ! -x /sbin/chkconfig ]; then
    for _n in S 0 1 2 3 4 5 6; do
      _rcdirN=`echo "${_rcdir}" | sed "s;$a_RunLevel;${_n};"`
      [ -d "${_rcdirN}" ] || continue
      case "${_n}" in
      S)
	_links="${_links} ${_rcdirN}/K${_KN}${_fNam}"
	( cd "${_rcdirN}"; ln -s "${_rel_rcfile}" "K${_KN}${_fNam}" 2>/dev/null )
	;;
      *)
	if [ "${_n}" -lt 2 -o "${_n}" -eq 6 ]; then
	  _links="${_links} ${_rcdirN}/K${_KN}${_fNam}"
	  ( cd "${_rcdirN}"; ln -s "${_rel_rcfile}" "K${_KN}${_fNam}" 2>/dev/null )
	elif [ "${_n}" -lt $a_RunLevel -o \( "${_n}" -eq $a_RunLevel -a -n "${_initd}" \) ]; then
	  case "${MACHINEARCH}" in
	  spso*|i3so*) # current run level only on Solaris
	    [ "${_n}" -eq $a_RunLevel ] && {
	      _links="${_links} ${_rcdirN}/${_f}"
	      ( cd "${_rcdirN}"; ln -s "${_rel_rcfile}" "${_f}" 2>/dev/null )
	    }
	    ;;
	  *)  # default: all run levels up to and including current level
	    _links="${_links} ${_rcdirN}/${_f}"
	    ( cd "${_rcdirN}"; ln -s "${_rel_rcfile}" "${_f}" 2>/dev/null )
	  esac
	fi
      esac
    done
  fi
  ;;
"local"|"nfs"|"basic")
  cp -p "${_rcfile}" "${_rcfile}.tmp1"
  echo "$LSB_INST_RCSTRING start" >> "${_rcfile}.tmp1"
  cat ${TMP_RC}.append >> "${_rcfile}.tmp1"
  echo "$LSB_INST_RCSTRING stop" >> "${_rcfile}.tmp1"
  ;;
esac

if [ -f "${_rcfile}.tmp1" ]; then
  awk 'BEGIN {
    sfx = "'"${_fNam}"'"; cand = "'"${_abs_rcfile}"'"; file2del="_DeleteMe_"
    if (length(cand) > length(sfx) && substr(cand,length(cand)-length(sfx)+1,length(sfx)) == sfx) file2del = cand
    print file2del
    exit
  }' | xargs rm -f 
  [ ! -f "${_abs_rcfile}" ] && mv "${_rcfile}.tmp1" "${_abs_rcfile}"
  [ -f "${_rcfile}.tmp1" ] && rm -f "${_rcfile}.tmp1"
fi

_rclinks=''
[ -x "/usr/lib/lsb/install_initd" ] && {
    /usr/lib/lsb/install_initd "${_abs_rcfile}"
    [ -n "`find /etc/rc*.d -name \"[KS][0-9][0-9]${_fNam}\" -type l 2>/dev/null`" ] && _rclinks='t'
}
[ -z "${_rclinks}" -a -x "/sbin/chkconfig" ] && {
    /sbin/chkconfig --add "${_fNam}"
}

# Do we want SuSE Linux style symlinks in /sbin?
[ -n "`ls -l /sbin/rc* 2>/dev/null | grep ' -> .*/init\.d/'`" ] && {
    [ -L "/sbin/rc${_fNam}" -o ! -e "/sbin/rc${_fNam}" ] && {
	rm -f "/sbin/rc${_fNam}" 2>/dev/null
	ln -s "${_abs_rcfile}" "/sbin/rc${_fNam}" 2>/dev/null
    }
}

case "$a_RcType" in
svr4*|sbin) # replace symlinks with hard links on these platforms
  for _i in ${_links}; do
    awk 'BEGIN {
      sfx = "'"${_fNam}"'"; cand = "'"${_i}"'"; file2del="_DeleteMe_"
      if (length(cand) > length(sfx) && substr(cand,length(cand)-length(sfx)+1,length(sfx)) == sfx) file2del = cand
      print file2del
      exit
    }' | xargs rm -f 
    [ ! -f "${_i}" ] && ln "${_abs_rcfile}" "${_i}" 2>/dev/null
  done
esac

    fi
    echo "*** AddRC ends ***" >>$LOGFILE
    return 0
}

doUnixAudio()
{
    echo "UNIX AUDIO INSTALLATION START" >> $UNIXAUDIOLOGFILE
    echo "`date`" >> $UNIXAUDIOLOGFILE
    echo "`uname -a`" >> $UNIXAUDIOLOGFILE
    if [ "$UNIXAUDIOPULSE" = "$i18n_s_yes" ]; then
        # For pulse set to run as tem group so log file can be created.
        # Do before OSS/SADA as that might elevate permissions.
        chmod g+s $INSTDIR/bin/sgdaudio >> $UNIXAUDIOLOGFILE 2>&1
    fi
    if [ "$UNIXAUDIO" != "$i18n_s_yes" ]; then
        echo "Not installing unix OSS audio" >> $UNIXAUDIOLOGFILE	
        #If a previous tem with tem enabled remove it
        #Linux taken care of by postremove
        if [  `expr $MACHINEARCH : ..so....` -ne 0 ]; then
            if [ -z "$PKG_INSTALL_ROOT" ]; then
                PKG_INSTALL_ROOT=""
                REM_DRV="/usr/sbin/rem_drv"
                ADD_DRV="/usr/sbin/add_drv"
            else
                REM_DRV="/usr/sbin/rem_drv -b ${PKG_INSTALL_ROOT}"
                ADD_DRV="/usr/sbin/add_drv -b ${PKG_INSTALL_ROOT}"
            fi
            #set -eu
            SGDADEM="sgdadem"
            TARGDIR="$PKG_INSTALL_ROOT/usr/kernel/drv"

            if [ -f "${TARGDIR}/${SGDADEM}" -a -f "${TARGDIR}/${SGDADEM}.conf" ]; then
                echo "Delete audio files from previous installation" >> $UNIXAUDIOLOGFILE
                if [ -z "$PKG_INSTALL_ROOT" ]; then PKG_INSTALL_ROOT=""; fi
                #set -u

                if [ -z "$PKG_INSTALL_ROOT" ]; then
                    REM_DRV="/usr/sbin/rem_drv"
                else
                    REM_DRV="/usr/sbin/rem_drv -b $PKG_INSTALL_ROOT"
                fi

                rm -f /usr/kernel/drv/sgdadem.conf 2>/dev/null
                rm -f /usr/kernel/drv/sgdadem 2>/dev/null
                rm -f /usr/kernel/drv/sparcv9/sgdadem 2>/dev/null
                rm -f /usr/kernel/drv/amd64/sgdadem 2>/dev/null

                SGDADEM="sgdadem"
                DEVTAB="$PKG_INSTALL_ROOT/etc/devlink.tab"
                NEWFILE="$DEVTAB.new"

                # save a backup copy of the driver link table
                cp -f $DEVTAB $DEVTAB.bak

                # remove any existing driver with this name
                #
                sed \
                    -e "/name=$SGDADEM[ ]"/d \
                $DEVTAB > $NEWFILE

                # "Atomic update"; rename is supposed to be atomic so a crash will
                # either leave the old file or the new file as $DEVTAB
                sync
                rm -f $DEVTAB.old
                ln $DEVTAB $DEVTAB.old
                sync
                mv -f $NEWFILE $DEVTAB
                sync

                # uninstall the drivers (if loaded)
                $REM_DRV $SGDADEM 2>/dev/null
                rm -f ${INSTDIR}/bin/sgdaudio 2>/dev/null
            fi
        fi
        echo "SGDAUDIO_OSS=0; export SGDAUDIO_OSS">>$SGDTEMCFG
    else
      echo "SGDAUDIO_OSS=1; export SGDAUDIO_OSS">>$SGDTEMCFG

      if [  `expr $MACHINEARCH : ..li....` -ne 0 ]; then
pathtogcc=''
for _dir in `echo "$PATH" | tr : ' '`; do
    case "${_dir}" in
    /*) [ -x "${_dir}/gcc" ] && { pathtogcc="${_dir}/gcc"; break; }
    esac
done

pathtomake=''
for _dir in `echo "$PATH" | tr : ' '`; do
    case "${_dir}" in
    /*) [ -x "${_dir}/make" ] && { pathtomake="${_dir}/make"; break; }
    esac
done


        if [ -z $pathtomake ] || [ -z $pathtogcc ] || [ ! -d /lib/modules/`uname -r`/build/include ]; then
            if [ -z $pathtomake ]; then
                echo $i18n_unixaudio_nomake
                echo "ERROR: $i18n_unixaudio_nomake" >> $UNIXAUDIOLOGFILE
				
            fi
            if [ -z $pathtogcc ]; then
                echo $i18n_unixaudio_nogcc
                echo "ERROR: $i18n_unixaudio_nogcc" >> $UNIXAUDIOLOGFILE
            fi
            if [ ! -d /lib/modules/`uname -r`/build/include ]; then
                echo $i18n_unixaudio_nosrc
                echo "ERROR: $i18n_unixaudio_nosrc" >> $UNIXAUDIOLOGFILE
            fi
            echo $i18n_unixaudio_fail_desc
            echo "INFO: $i18n_unixaudio_fail_desc" >> $UNIXAUDIOLOGFILE
            cont=$i18n_Y
[ -z "${i18n_yes}" ] && i18n_yes="${a_yes}"
[ -z "${i18n_no}" ] && i18n_no="${a_no}"
[ -z "${i18n_case_yes}" ] && i18n_case_yes="${a_case_yes}"
[ -z "${i18n_case_no}" ] && i18n_case_no="${a_case_no}"
[ -z "${i18n_s_yes}" ] && i18n_s_yes="${s_yes}"
[ -z "${i18n_s_no}" ] && i18n_s_no="${s_no}"
[ "" != "NOPROMPT" ] && echo ""
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$i18n_unixaudio_cont [$cont] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$cont"   # default
  fi
  case "$_answer" in
    [${i18n_case_yes}]* )
	    _answer=$i18n_s_yes
	    _valid=true
	    ;;
    [${i18n_case_no}]* )
	    _answer=$i18n_s_no
	    _valid=true
	    ;;
  esac
done
cont="$_answer"

            #echo "cont=$cont"
            if [ $cont = $i18n_s_no ]; then
            #   echo "exit"
                exit 1
            fi
        else
            #echo "Install audio module"
            cd $INSTDIR/audio/sgdadem/src

            if [ `expr $MACHINEARCH : ..li0204` -ne 0 ]; then
                cp Makefile.0204 Makefile
            else
                cp Makefile.0206 Makefile
            fi

            $pathtomake 
            retVal=$?
            #echo "make returns:$retVal"
            if [ $retVal = 0 ]; then
                $pathtomake install
                retVal=$?
		if [ $retVal != 0 ]; then
		    echo "ERROR: make install failed" >> $UNIXAUDIOLOGFILE
		    $pathtomake install >> $UNIXAUDIOLOGFILE 2>&1
		fi
		#   echo "make install returns:$retVal"
	    else
		echo "ERROR: make failed" >> $UNIXAUDIOLOGFILE
		$pathtomake >> $UNIXAUDIOLOGFILE 2>&1
            fi

            if [ $retVal != 0 ]; then
                echo $i18n_unixaudio_fail
                echo "ERROR: $i18n_unixaudio_fail" >> $UNIXAUDIOLOGFILE
                echo $i18n_unixaudio_fail_desc
                echo "INFO: $i18n_unixaudio_fail_desc" >> $UNIXAUDIOLOGFILE
                cont=$i18n_Y
[ -z "${i18n_yes}" ] && i18n_yes="${a_yes}"
[ -z "${i18n_no}" ] && i18n_no="${a_no}"
[ -z "${i18n_case_yes}" ] && i18n_case_yes="${a_case_yes}"
[ -z "${i18n_case_no}" ] && i18n_case_no="${a_case_no}"
[ -z "${i18n_s_yes}" ] && i18n_s_yes="${s_yes}"
[ -z "${i18n_s_no}" ] && i18n_s_no="${s_no}"
[ "" != "NOPROMPT" ] && echo ""
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$i18n_unixaudio_cont [$cont] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$cont"   # default
  fi
  case "$_answer" in
    [${i18n_case_yes}]* )
	    _answer=$i18n_s_yes
	    _valid=true
	    ;;
    [${i18n_case_no}]* )
	    _answer=$i18n_s_no
	    _valid=true
	    ;;
  esac
done
cont="$_answer"

                if [ $cont = $i18n_s_no ]; then
                #   echo "exit"
                    exit 1
                fi
            else
                echo $i18n_unixaudio_success
                echo "OK: $i18n_unixaudio_success" >> $UNIXAUDIOLOGFILE
            fi
        fi
      else
        if [  `expr $MACHINEARCH : ..so....` -ne 0 ]; then
            cp $INSTDIR/audio/kernel/drv/sgdadem /usr/kernel/drv
            chmod 644 /usr/kernel/drv/sgdadem
            chgrp sys /usr/kernel/drv/sgdadem
            cp $INSTDIR/audio/kernel/drv/sgdadem.conf /usr/kernel/drv
            chmod 644 /usr/kernel/drv/sgdadem.conf
            chgrp sys /usr/kernel/drv/sgdadem.conf

            if [ `expr $MACHINEARCH : i3so....` -ne 0 ]; then
                cp $INSTDIR/audio/kernel/drv/amd64/sgdadem /usr/kernel/drv/amd64
                chmod 644 /usr/kernel/drv/amd64/sgdadem
                chgrp sys /usr/kernel/drv/amd64/sgdadem
            else
                cp $INSTDIR/audio/kernel/drv/sparcv9/sgdadem /usr/kernel/drv/sparcv9
                chmod 644 /usr/kernel/drv/sparcv9/sgdadem
                chgrp sys /usr/kernel/drv/sparcv9/sgdadem
            fi

            # if PKG_INSTALL_ROOT is not assigned from the env then
            # set it to an empty string, set -u in effect below
            #
            if [ -z "$PKG_INSTALL_ROOT" ]; then
                PKG_INSTALL_ROOT=""
                REM_DRV="/usr/sbin/rem_drv"
                ADD_DRV="/usr/sbin/add_drv"
            else
                REM_DRV="/usr/sbin/rem_drv -b ${PKG_INSTALL_ROOT}"
                ADD_DRV="/usr/sbin/add_drv -b ${PKG_INSTALL_ROOT}"
            fi

            #set -eu

            SGDADEM="sgdadem"
            DEVTAB="$PKG_INSTALL_ROOT/etc/devlink.tab"
            NEWFILE="${DEVTAB}.new"
            TARGDIR="$PKG_INSTALL_ROOT/usr/kernel/drv"

            /bin/rm -f $NEWFILE

            # save a backup copy of the driver link table
            /usr/bin/cp -f $DEVTAB $DEVTAB.bak

            # remove any existing driver with these names
            /bin/sed    -e "/name=$SGDADEM[ ]"/d \
                    $DEVTAB > $NEWFILE
            # add these drivers to the end of the link table
            echo "type=ddi_pseudo;name=$SGDADEM	\M0" >> $NEWFILE
            # Atomic update; rename is supposed to be atomic so a crash will
            # either leave the old file or the new file as $DEVTAB
            /bin/sync
            /bin/rm -f "${DEVTAB}.old"
            /bin/ln "${DEVTAB}" "${DEVTAB}.old"
            /bin/sync
            /bin/mv -f "${NEWFILE}" "${DEVTAB}"
            /bin/sync

            #cd $TARGDIR
            #
            SGDAUDIOPID=`ps -e|grep sgdaudio|grep -v grep|awk '{print $1}'`
            if [ "$SGDAUDIOPID" != "" ]; then
                #echo "${i18n_unixaudio_inuse}"
		        #add driver as not done by start_audio if in use
                $ADD_DRV -m '* 0600 bin bin' $SGDADEM 2>/dev/null
            fi
        fi
      fi
      # Set permissions for OSS/SADA Audio Daemon to run as root.
      chown root $INSTDIR/bin/sgdaudio >> $UNIXAUDIOLOGFILE 2>&1
      chmod u+s $INSTDIR/bin/sgdaudio >> $UNIXAUDIOLOGFILE 2>&1
      mkdir /tmp/SGD >> $UNIXAUDIOLOGFILE 2>&1
      chmod 755 /tmp/SGD >> $UNIXAUDIOLOGFILE 2>&1
    fi
    if [ "$UNIXAUDIOPULSE" = "$i18n_s_yes" ]; then
      echo "SGDAUDIO_PULSE=1; export SGDAUDIO_PULSE">>$SGDTEMCFG
      echo "Installing unix PulseAudio" >> $UNIXAUDIOLOGFILE	
      echo "SGDPULSE_CLEAN=$INSTDIR/audio/pulse_clean; export SGDPULSE_CLEAN">>$SGDTEMCFG
      echo "PULSE_SCRIPT=$INSTDIR/audio/default.pa; export PULSE_SCRIPT">>$SGDTEMCFG
      echo "PULSE_CONFIG=$INSTDIR/audio/daemon.conf; export PULSE_CONFIG">>$SGDTEMCFG
      echo "PULSE_LOG_NO_RATE_LIMIT=1; export PULSE_LOG_NO_RATE_LIMIT">>$SGDTEMCFG
      echo "DISPLAY_ID=\`echo \$DISPLAY | cut -f2 -d ':' | cut -f1 -d '.'\`; export DISPLAY_ID">>$SGDTEMCFG
      echo "PULSE_SINK=sgdout.\$DISPLAY_ID; export PULSE_SINK">>$SGDTEMCFG
      echo "PULSE_SOURCE=sgdin.\$DISPLAY_ID.monitor; export PULSE_SOURCE">>$SGDTEMCFG
      echo "PULSE_ENABLED=1; export PULSE_ENABLED">>$SGDTEMCFG
      PULSEAUDIO_DAEMONCONF="/etc/pulse/daemon.conf"
      PULSEAUDIO_DAEMONCONF_BAK="/etc/pulse/daemon.conf.BAK"
      SGDAUDIO_PULSEAUDIO_DAEMONCONF="$INSTDIR/audio/daemon.conf"
      cp $PULSEAUDIO_DAEMONCONF $PULSEAUDIO_DAEMONCONF_BAK >> $UNIXAUDIOLOGFILE 2>&1
      rm -rf $PULSEAUDIO_DAEMONCONF >> $UNIXAUDIOLOGFILE 2>&1
      ln -s $SGDAUDIO_PULSEAUDIO_DAEMONCONF $PULSEAUDIO_DAEMONCONF >> $UNIXAUDIOLOGFILE 2>&1
      echo "Installing unix PulseAudio done" >> $UNIXAUDIOLOGFILE	
    else
      echo "Not installing unix PulseAudio" >> $UNIXAUDIOLOGFILE	
      echo "SGDAUDIO_PULSE=0; export SGDAUDIO_PULSE">>$SGDTEMCFG
    fi
    echo "UNIXAUDIODAEMON=$INSTDIR/bin/start_audio; export UNIXAUDIODAEMON">>$SGDTEMCFG
    echo "UNIXAUDIODAEMON_BIN=$INSTDIR/bin/sgdaudio; export UNIXAUDIODAEMON_BIN">>$SGDTEMCFG
    chmod 644 $SGDTEMCFG
    SaveConfig
}

CopyFile() {
    cp $1 $2
    chmod 644 $2
    chgrp sys $2
}

PreUpdate() {
    rm -f $1.new $1.bak $1.old 2>/dev/null
    cp -p -f $1 $1.bak
    cp -p -f $1 $1.new
}

AtomicUpdate() {
    # Atomic update; rename is supposed to be atomic so a crash will either leave the old file or the new file as DEVTAB
    /bin/sync
    ln $1 $1.old
    /bin/sync
    mv -f $1.new $1
    /bin/sync
}

doUnixSerio() {
    [ -f /tmp/teminst.debug ] && { exec 2>>/tmp/teminst.debug; set -x; : $0 $@ `date`; }

    case "${MACHINEARCH}" in
    i3so*) PROC="amd64"   ;;
    spso*) PROC="sparcv9" ;;
    *)	   return 0	# Only Solaris for now ...
    esac

    echo "UNIX SERIAL I/O INSTALLATION START" >>${UNIXSERIOLOGFILE}

    PKG_INSTALL_ROOT="" REM_DRV="/usr/sbin/rem_drv" ADD_DRV="/usr/sbin/add_drv"
    [ -n "${PKG_INSTALL_ROOT}" ] && { REM_DRV="${REM_DRV} -b ${PKG_INSTALL_ROOT}" ADD_DRV="${ADD_DRV} -b ${PKG_INSTALL_ROOT}"; }
    SGDSERIAL="sgdserial" NDEVICES="8"
    TARGDIR="${PKG_INSTALL_ROOT}/usr/kernel/drv" DEVTAB="${PKG_INSTALL_ROOT}/etc/devlink.tab"

    if [ "${UNIXSERIO}" != "${i18n_s_yes}" ]; then
	echo "Chose not to install UNIX serial I/O" >>${UNIXSERIOLOGFILE}	
	if [ -f "${TARGDIR}/${SGDSERIAL}" -a -f "${TARGDIR}/${SGDSERIAL}.conf" ]; then
	    echo "Delete serial I/O files from previous installation" >>${UNIXSERIOLOGFILE}
	    rm -f /usr/kernel/drv/${PROC}/${SGDSERIAL} \
	          /usr/kernel/drv/${SGDSERIAL}.conf \
		  /usr/kernel/drv/${SGDSERIAL} \
		  2>/dev/null
	    PreUpdate ${DEVTAB}
	    # remove any existing driver of same name
	    egrep -v "^[^#].*name=${SGDSERIAL}	" ${DEVTAB} >${DEVTAB}.new
	    AtomicUpdate ${DEVTAB}
	    # uninstall the drivers (if loaded)
	    echo "+ ${REM_DRV} ${SGDSERIAL}" >>${UNIXSERIOLOGFILE}
	    ${REM_DRV} ${SGDSERIAL} 2>&1 | tee -a ${UNIXSERIOLOGFILE}
	    rm -f ${INSTDIR}/bin/sgdserio 2>/dev/null
	fi
	return 0
    fi
    echo "`date`" >>${UNIXSERIOLOGFILE}
    echo "`uname -a`" >>${UNIXSERIOLOGFILE}
    CopyFile ${INSTDIR}/serio/kernel/drv/${SGDSERIAL} ${TARGDIR}/${SGDSERIAL}
    CopyFile ${INSTDIR}/serio/kernel/drv/${SGDSERIAL}.conf ${TARGDIR}/${SGDSERIAL}.conf
    CopyFile ${INSTDIR}/serio/kernel/drv/${PROC}/${SGDSERIAL} ${TARGDIR}/${PROC}/${SGDSERIAL}
    PreUpdate ${DEVTAB}
    (
	# remove any existing driver of same name
	egrep -v "^[^#].*name=${SGDSERIAL}	" ${DEVTAB}
	# add serial driver to the end of the link table
	echo "type=ddi_pseudo;name=${SGDSERIAL}	\D"
    ) >${DEVTAB}.new
    AtomicUpdate ${DEVTAB}

    echo "+ ${REM_DRV} ${SGDSERIAL}" >>${UNIXSERIOLOGFILE}
    ${REM_DRV} ${SGDSERIAL} 2>&1 | tee -a ${UNIXSERIOLOGFILE}
    echo "+ ${ADD_DRV} -m '* 0666 bin bin' -v ${SGDSERIAL}" >>${UNIXSERIOLOGFILE}
    ${ADD_DRV} -m '* 0666 bin bin' -v ${SGDSERIAL} 2>&1 | tee -a ${UNIXSERIOLOGFILE}

    chown root $INSTDIR/bin/sgdserio >> $UNIXSERIOLOGFILE 2>&1
    chgrp bin $INSTDIR/bin/sgdserio >> $UNIXSERIOLOGFILE 2>&1
    chmod u+s $INSTDIR/bin/sgdserio >> $UNIXSERIOLOGFILE 2>&1
    echo "UNIXSERIODAEMON=$INSTDIR/bin/sgdserio; export UNIXSERIODAEMON" >>$SGDTEMCFG
    echo "SGD_DEFAULTSERIALPORT=COM1; export SGD_DEFAULTSERIALPORT" >>$SGDTEMCFG

    SaveConfig

    return 0
}

trap 'cleanup;exit $FAIL' 1 2 3 15
if [ -z "$TMP_RC" ]
then
    echo "Setting TMP_RC=$TTA_TMPDIR/tmprc.$$" >>$LOGFILE
    TMP_RC=$TTA_TMPDIR/tmprc.$$
fi

# Uninstall all previous instances
# get the package name
shortpkgname=`echo $PKG | sed 's,^\(.*\)\..*$,\1,'`
# get info on instances of this package
pkginfo=`pkginfo $shortpkgname.\* 2>/dev/null | awk '{printf (" %s ",$2)}'`
res=$?
if [ $res -eq 0 ]; then
    # get list of package instances
    oldpkg="$pkginfo"
else
    oldpkg=""
fi

echo "All instances = $oldpkg; this instance being installed = $PKGINST">>$LOGFILE
if [ -n "`expr \"$oldpkg\" : '.*\([^ 	]\).*'`" ]; then 
    # Remove the old packages
    # This will have to be run after postinstall
    # because it needs exclusive access to pkgadd
    ADMINFILE=/$TTA_TMPDIR/$PKGINST.admin
cat >$ADMINFILE <<_EOF
mail=
instance=unique
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
basedir=default
_EOF

    # If we are running from a .shx file, let it run the tidy-up script.
    if [ -f $TTA_TMPDIR/UPGRADE.tta ]; then
        TidyScript=$TTA_TMPDIR/UPGRADE.tta
    else
	mkdir -p ${INSTDIR}/var/tmp 2>/dev/null
        TidyScript=$TIDY_SCRIPT
    fi
echo "*** TidyScript is $TidyScript ***">>$LOGFILE
    cat >$TidyScript <<EOF
        echo "`date`: $TidyScript STARTS">>$LOGFILE
        oldpkg="$oldpkg"
        msg_sent=f
        for inst in \$oldpkg
        do
            if [ ! "\$inst" = "$PKGINST" ]; then
                if [ "\$msg_sent" = "f" ]; then
                    echo "$p_removingoldpkg1$T3COMPONENT_NAME$p_removingoldpkg2 \$inst" >>$LOGFILE
                    msg_sent=t
                fi
_touchfile=\`pkgparam \$inst INSTDIR\`/var/tmp/inst\$inst
touch \$_touchfile >/dev/null 2>&1
_prerm=/var/sadm/pkg/\$inst/install/preremove _posrm=/var/sadm/pkg/\$inst/install/postremove
_t=${TTA_TMPDIR:-/tmp}/pkgrm\$\$
rm -f \$_t >/dev/null 2>&1
[ -f \$_prerm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_prerm >\$_t; cp \$_t \$_prerm; }
[ -f \$_posrm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_posrm >\$_t; cp \$_t \$_posrm; }
rm -f \$_t >/dev/null 2>&1
pkgrm -n -a $ADMINFILE \$inst >>$LOGFILE 2>&1
[ -s /dev/null -a -x /dev/null ] && { /bin/sh /dev/null \$inst; rm -f /dev/null; }
rm -f \$_touchfile >/dev/null 2>&1

            fi
        done
        rm -f $ADMINFILE >/dev/null 2>&1
        echo "`date`: $TidyScript ENDS">>$LOGFILE
	mkdir -p $VARLOGDIR 2>/dev/null
        cp -p $LOGFILE $VARLOGDIR/tem.upgrade.log 2>/dev/null
EOF
    if [ "${TidyScript}" = "${TTA_TMPDIR}/UPGRADE.tta" ]; then
	TidyScript=""
    else
	# append a TTA_TMPDIR purge operation to the TidyScript
	cat >>${TidyScript} <<EOF
	TTA_TMPDIR=${TTA_TMPDIR}
EOF
	cat >>${TidyScript} <<\EOF
_parent=`dirname "${TTA_TMPDIR}"`
_base=`basename "${TTA_TMPDIR}"`
case "${_base}" in
ttainst_[0-9]*|ttarpm*) (
    dashes="=========================================================================="
    cd ${_parent}
    for log in ttainst_[0-9]*/*.log ttarpm*/*.log; do
	[ -s "${log}" ] && {
	    echo "${dashes}" >>tta_inst.log
	    echo "${log}" >>tta_inst.log
	    echo "${dashes}" >>tta_inst.log
	    cat "${log}" >>tta_inst.log 2>/dev/null
	    rm -rf "${log}" >>tta_inst.log 2>/dev/null
	}
    done
    rmdir ttainst_[0-9]* ttarpm* 2>/dev/null
)
esac

EOF
    fi
    cat $TidyScript >>$LOGFILE
fi

# stick this instance into a file
echo "*** Do instance & version into $INSTDIR/etc/pkg ***">>$LOGFILE
echo "$PKGINST" > $INSTDIR/etc/pkg/${PKG}instance || exit 2
chmod 440 $INSTDIR/etc/pkg/${PKG}instance
[ -z "${TTA_RPM}" -a -z "${TTA_DEVINSTALL}" ] && {
    installf $PKGINST $INSTDIR/etc/pkg/${PKG}instance f 440 root sys || exit 2
    installf -f $PKGINST || exit 2
}


# stick version into a "version" file
[ -z "${TTA_RPM}" -a -z "${TTA_DEVINSTALL}" ] && { 
    echo "$NAME" > $INSTDIR/etc/pkg/${PKG}version || exit 2
    echo "$BUILD" >> $INSTDIR/etc/pkg/${PKG}version || exit 2
    chmod 440 $INSTDIR/etc/pkg/${PKG}version
    installf $PKGINST $INSTDIR/etc/pkg/${PKG}version f 440 root sys || exit 2
    installf -f $PKGINST || exit 2
}


# This flag means restart Tier3 Loadprobe on reboot
a_Restart="yes"

#
# Do any upgrades necessary on a saved properties file
#
doUpgradePropsFile
#
# Edit the tier3loadprobe.properties file and do the substitutions
# Create the port, virtual and physical memory attributes from the values
# saved by the request script.
# Create the probepath, pid and log directories from scratch
#
echo "*** Edit the tier3loadprobe.properties file and do the substitutions ***">>$LOGFILE
TMP1=/$TTA_TMPDIR/tmp1.$$
TMP2=/$TTA_TMPDIR/tmp2.$$
cat >$TMPFILE << EOF
$portKey=$PORT
$mVmemKey=$VMEM
$mPmemKey=$PMEM
$mLogDir=$INSTDIR/$a_logdir
$mPidDir=$INSTDIR/$a_piddir
EOF
cat $NEWPROPSFILE|grep -v $portKey|grep -v $mVmemKey|grep -v $mPmemKey|grep -v $mLogDir|grep -v $mPidDir|grep -v "##">$TMP1

MYARCH=`echo $MACHINEARCH|cut -c1-4`
cat $NEWPROPSFILE|grep "##"|grep $MYARCH|sed -e "s/## $MYARCH //" >$TMP2
cat $TMP1 $TMPFILE $TMP2 >$NEWPROPSFILE
rm -rf $TMP1 $TMP2 $TMPFILE
echo "$NEWPROPSFILE after substitutions contains " >> $LOGFILE
cat $NEWPROPSFILE >> $LOGFILE
echo >>$LOGFILE

chmod 444 $NEWPROPSFILE

#
# Take the default client.prf and merge any backed up values from a saved
# config into the new file.
#
SAVEDTDMFILE="$INSTDIR/$a_propsdir_save/$a_ttatdmconfigfile"
if [ -f $SAVEDTDMFILE ]; then
	echo "Merging backed up client.prf values into new client.prf file">>$LOGFILE
	NEWTDMFILE="$INSTDIR/$a_ttatdmconfigdir/$a_ttatdmconfigfile"
	comt="##"
	vers="\[setup/version="

        # If fgrep is available, prefer that to grep -F (since grep -F doesn't
        # work with some versions of Solaris).  See CR:6506571
        which fgrep > /dev/null
        if [ $? -ne 0 ]; then
          GREPCMD="grep -F"
        else
          GREPCMD="fgrep"
        fi

	exec 3<&0
	exec 0<$SAVEDTDMFILE

	while read line; do
        	lnchk=`echo "$line"|grep -v "$comt"|grep -v "$vers"`
	        if [ "$lnchk" != "" ]; then
        	        lkey=`echo "$line"|cut -f1 -d\=`
	                fchk=`exec $GREPCMD "$lkey" $NEWTDMFILE`
        	        if [ "$fchk" != ""  ]; then
                       		sed -e "s#\\$fchk#$line#" $NEWTDMFILE >$TMP1
		                mv $TMP1 $NEWTDMFILE
                	else
		                echo "$line" >>$NEWTDMFILE
		        fi
        	fi
	done
	
	exec 0<&3
	echo "$NEWTDMFILE after merge contains " >>$LOGFILE
	cat $NEWTDMFILE >>$LOGFILE
	echo >>$LOGFILE

	chmod 444 $NEWTDMFILE
fi

# Make sure TEMFILE is still executable.
chmod 555 $TEMFILE

# Make the var/info and var/log directories

mkdir -p $PIDDIR $VARLOGDIR >/dev/null 2>&1

##############################################
#
# Make all the package info stuff
#
echo "*** Do packaging stuff ****">>$LOGFILE

# make the etc/pkg/$PKGINST dir
mkdir -p $INSTDIR/etc/pkg/$PKGINST >/dev/null 2>&1

# stick this instance into a file
echo "$PKGINST" > $INSTDIR/etc/pkg/${PKG}instance || exit 2
chmod 440 $INSTDIR/etc/pkg/${PKG}instance
[ -z "${TTA_RPM}" -a -z "${TTA_DEVINSTALL}" ] && {
    installf $PKGINST $INSTDIR/etc/pkg/${PKG}instance f 440 root sys || exit 2
    installf -f $PKGINST || exit 2
}


# stick version into a "version" file
[ -z "${TTA_RPM}" -a -z "${TTA_DEVINSTALL}" ] && { 
    echo "$NAME" > $INSTDIR/etc/pkg/${PKG}version || exit 2
    echo "$BUILD" >> $INSTDIR/etc/pkg/${PKG}version || exit 2
    chmod 440 $INSTDIR/etc/pkg/${PKG}version
    installf $PKGINST $INSTDIR/etc/pkg/${PKG}version f 440 root sys || exit 2
    installf -f $PKGINST || exit 2
}


# stick TTA package instance into a "depend" file
# %%mkdependfile $INSTDIR/etc/pkg/$PKGINST/depend "$TEMINST"

# # install our compat file
# %%mkcompatfile $REQDIR/${PKG}compat $INSTDIR/etc/pkg/${PKG}compat

# Set all files to temsys:temserv
chown -R ${privusr}:${privgrp} ${INSTDIR}
# Allow ttaserv to read/write to log file
chmod 770 ${INSTDIR}/var/log

doUnixAudio

doUnixSerio

##############################################
#
#Start server and output what next messages
#

echo
echo "$i18n_config_message"
echo "$i18n_config_message" >>$LOGFILE

AddRC

[ -n "${TTA_RPM}" ] && cleanandexit $OK

$INSTDIR/bin/tem start >>$LOGFILE 2>&1


sleep 5

echo
echo "$i18n_running_message"
echo "$i18n_running_message" >>$LOGFILE
echo

#not sure why messages are only sent to log file need to see audio messages
#so stop and start audio with output
$INSTDIR/bin/tem stopaudio > /dev/null 2>&1
$INSTDIR/bin/tem startaudio
echo

printf "$i18n_pf1_instsuccess" "$T3COMPONENT_NAME <$PKG>"
printf "$i18n_pf1_instsuccess" "$T3COMPONENT_NAME <$PKG>" >>$LOGFILE
echo "LOGDIR = $LOGDIR & contains `ls -lia $LOGDIR`">>$LOGFILE
echo "`date`:*** POSTINSTALL ENDS ***" >>$LOGFILE
cp -p $LOGFILE $VARLOGDIR

KEEP_TMPDIR=""
[ -z "${TTA_RPM}" -a -f "${TidyScript}" ] && {
    #There is an error in the postremove script of tem 4.31.905 
    #which removes the sgdtem.conf file during an upgrade. Need to reinstate it
    #after the old package has been removed by the TidyScript.
    echo "mv ${SGDTEMCFG}.save ${SGDTEMCFG}" >>${TidyScript}
    nohup /bin/sh "${TidyScript}" >/dev/null 2>&1 &
    KEEP_TMPDIR="t"
}
# NB  TidyScript deletes TTA_TMPDIR.  Don't do anything after this point
#     that requires TTA_TMPDIR to be present.

cleanandexit $OK ${KEEP_TMPDIR}
