#!/bin/bash
# Copyright (c) 1997, 2020, Oracle and/or its affiliates.
#
##########################################
##########################################
if [ -f /tmp/pkgadd.debug ]; then
    echo "Debug Output On"
    echo "---------------"
    echo " "
    set
    set -x	
    trace=x export trace
fi


ans_host=`hostname`
if [ -f "$TTADIR/$ans_host.answers" ]; then
    echo "Loading Answers from ${TTADIR}/$ans_host.answers"
    . "$TTADIR/$ans_host.answers"
fi

source "${TTADIR}/bin/scripts/common.sh"
source "${TTADIR}/bin/scripts/common-env.sh"

OK=0
FAIL=1

umask 022

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`

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="--------------------------------------------------------------------------"

#versioninfo
# Version numbers
PRODUCT_VERSION="5.60.514"
PRODUCT_VERSION_FULL="5.60.514"
PRODUCT_VERSION_MAJOR=5
PRODUCT_VERSION_FEATURE=6
PRODUCT_VERSION_BUG=0
PRODUCT_VERSION_BUILD=514
PRODUCT_VERSION_BUILD_DECIMAL=514
PRODUCT_VERSION_AS_NUMBER=560514
PRODUCT_VERSION_CAB=5,6,0,514
PRODUCT_VERSION_RPM=5.60-514

# 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.9
# 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.60.514"
PRODUCT_VERSION_FULL="5.60.514"
PRODUCT_VERSION_MAJOR=5
PRODUCT_VERSION_FEATURE=6
PRODUCT_VERSION_BUG=0
PRODUCT_VERSION_BUILD=514
PRODUCT_VERSION_BUILD_DECIMAL=514
PRODUCT_VERSION_AS_NUMBER=560514
PRODUCT_VERSION_CAB=5,6,0,514
PRODUCT_VERSION_RPM=5.60-514

# 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.9
# 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

# 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


LOGDIR=$TTA_TMPDIR

[ -n "${TTA_DEVINSTALL}" ] && { PKG="tta" PKGINST="tta"; [ "${TTA_DEVINSTALL}" = "tx" ] && set -x; }
LOGFILE=$LOGDIR/$PKG.log
scriptname=`expr "//$0" : '.*/\(.*\)' `
chmod 640 $LOGFILE >/dev/null 2>&1
echo "---> $scriptname" >>$LOGFILE
chmod 640 $LOGFILE >/dev/null 2>&1
export LOGFILE


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


# Purge old installation tmp dirs
case "${TTA_TMPDIR}" in
*/ttainst_[0-9]* | */ttarpm* ) (
    cd `dirname "${TTA_TMPDIR}"`
    for d in ttainst_[0-9]* ttarpm*; do
	case "`pwd`/$d" in
	$TTA_TMPDIR) # keep this one
	    ;;
	*)  rm -rf $d
	esac
    done
)
esac

[ -n "${TTA_DEVINSTALL}" ] && PKGSAV=${TTA_TMPDIR}
INST_SAVE_FILE=${PKGSAV}/inst_save_file

TMP_RC=$TTA_TMPDIR/tta$$rc
SAVE_FILE=$TTA_TMPDIR/tta.resp
TIDY_SCRIPT=${INSTDIR}/var/tmp/tta.tidy_$$

[ -s ${SAVE_FILE} ] && . ${SAVE_FILE}

# Make sure we have sane values in the required config variables
[ -z "${a_PeerDNS}" ] && a_PeerDNS=`${INSTDIR}/bin/bin/ttahostname` export a_PeerDNS
[ -z "${a_AsadPort}" ] && a_AsadPort=3144 export a_AsadPort
[ -z "${a_httpport}" ] && a_httpport=80 export a_httpport
[ -z "${a_httpsport}" ] && a_httpsport=443 export a_httpsport
[ -z "${a_Archive}" ] && a_Archive=yes export a_Archive
[ -z "${a_CronDay}" ] && a_CronDay=0 export a_CronDay
[ -z "${a_CronTime}" ] && a_CronTime=3 export a_CronTime
[ -z "${a_Restart}" ] && a_Restart=yes export a_Restart

PortOffset=`expr $a_AsadPort - 3144`
PEERPORT=`expr 5427 + $PortOffset`
SECUREPORT=`expr 5307 + $PortOffset`

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

cleanandexit()
{
    [ "$1" -eq 0 -a -f "${INSTDIR}/etc/pkg/rpm_tta_upgradefrom" ] && {
       find "${INSTDIR}/etc/pkg" \( -name preremove_ -o -name postremove_ \) -print |
       sed 's/_$//' |
       xargs -i@ mv @_ @
       rm -f "${INSTDIR}/etc/pkg/rpm_tta_upgradefrom" 2>/dev/null
    }
    cleanup
    exit $1
}

trap 'echo "$who_i_am: Trapped a signal." >> $LOGFILE; cleanup;exit 1' 1 2 3 15

TTA_CONFIGURE=`cat ${INSTDIR}/var/configure 2>/dev/null`

[ -z "${TTA_DEVINSTALL}" ] && {
_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
)

}

# print driver stuff
PRT_PRINTERINFO="${INSTDIR}/etc/data/default.printerinfo.txt"
PRT_OLD_DRIVER="HP Color LaserJet 8500 PS"
PRT_NEW_DRIVER="Microsoft PS Class Driver"
PRT_OLD_DEFAULT_DRIVER='"_Default" = "'${PRT_OLD_DRIVER}'"'
PRT_NEW_DEFAULT_DRIVER='"_Default" = "'${PRT_NEW_DRIVER}'"'
[ -n "`grep \"^${PRT_OLD_DEFAULT_DRIVER}\" ${PRT_PRINTERINFO} 2>/dev/null`" ] && PRT_DEFAULT_DRIVER="t" || PRT_DEFAULT_DRIVER=""

BEANS="$INSTDIR/var/serverconfig/global/beans/com.sco.tta.server"
BEANSTPL="$INSTDIR/etc/templates/serverresources/serverconfig/global/beans/com.sco.tta.server"

pruneJavaRefList() {
    # Explicitly remove an item ($2) from the javareferenceaddress list in a properties file ($1).
    # If $3 is non-empty then it specifies a space-separated list of attrs to replace the removed one.
    b="$1"; cp ${b} ${b}.$$
    (
	REFADDR="javareferenceaddress="
	sed "/^${REFADDR}/q" ${b}.$$ | grep -v "^${REFADDR}"
	# Temporarily convert the comma-separated list to a newline-separated list
	# to simplify parsing.
	grep "^${REFADDR}" ${b}.$$ | tr , '\012' |
	awk 'BEGIN {
	    FS = "#"; comma = ""; number = 0; newattrs = "'"$3"'"
	}
	/'"$2"'/ {
	    # Save the index number of this entry so that
	    # we can use it as the base for subsequent entries.
	    number = substr($2,1,length($2)-1)
	    if (length(newattrs) == 0) {
		# We are removing this entry
	    } else {
		# We are inserting stuff after this entry
		if (number == 0)
		    printf "%s%s", comma, $0
		else {
		    backslash = index(substr($0,2,length($0)-1),"\\") + 1
		    printf "%s\\#%d%s", comma, number++, substr($0,backslash,length($0)-backslash+1)
		}
		comma = ","
		while (length(newattrs) > 0 && newattrs != "__END__") {
		    sp = index(newattrs, " ")
		    if (sp < 2) break
		    attr = substr(newattrs,1,sp-1)
		    sl = index(attr, "/")
		    if (sl < 2) break
		    attr0 = substr(attr,1,sl-1)
		    attr1 = substr(attr,sl+1,length(attr)-sl)
		    printf "%s\\#%d\\%s\\%s", comma, number++, attr0, attr1
		    newattrs = substr(newattrs, sp+1, length(newattrs)-sp)
		}
	    }
	    next
	}
	{
	    # Reinstate the original comma-separated format
	    if (number == 0)
		printf "%s%s", comma, $0
	    else {
		backslash = index(substr($0,2,length($0)-1),"\\") + 1
		printf "%s\\#%d%s", comma, number++, substr($0,backslash,length($0)-backslash+1)
	    }
	    comma = ","
	}
	END {
	    printf "\n"
	}'
	sed "1,/^${REFADDR}/d" ${b}.$$
    ) >${b}
    rm -f ${b}.$$ >/dev/null 2>&1
}

GetPrivUsrGrp()
{
    cat $INSTDIR/var/serverconfig/global/array.properties 2>/dev/null | awk -F= \
	'BEGIN { u="ttasys"; wu="ttaserv"; g="ttaserv" }
	$1 == "tarantella.config.array.privilegeduser" { u = $2 }
	$1 == "tarantella.config.array.webserveruser" { wu = $2 }
	$1 == "tarantella.config.array.privilegedgroup" { g = $2 }
	END { print u " " wu " " g }'
}
_privusrgrp=`GetPrivUsrGrp`
privusr=`expr "$_privusrgrp" : '\([^ ]*\) .*'`
webservusr=`expr "$_privusrgrp" : '.* \([^ ]*\) .*'`
privgrp=`expr "$_privusrgrp" : '.* \([^ ]*\)$'`

MkTtaDir()
{
    _newdirs="" _pflag=""
    case "$1" in
    -p) _pflag="-p"; shift
    esac
    for _d in "$@"; do
	while [ -n "$_d" ]; do
	    [ -d "$_d" ] && break
	    _newdirs="$_newdirs $_d"
	    _d=`dirname $_d`
	done
    done
    mkdir $_pflag "$@"
    [ -n "$_newdirs" ] && { chgrp $privgrp $_newdirs 2>/dev/null; chown $privusr $_newdirs 2>/dev/null; }
}


export ENTERPRISE

# Save install stuff for removal.
cp $SAVE_FILE $INST_SAVE_FILE >/dev/null 2>&1

proplist=$TTA_TMPDIR/upgrade_$$.properties export proplist
:>$proplist

ADMINFILE=$TTA_TMPDIR/$PKGINST.admin
export ADMINFILE

# Create a README file for any words of wisdom from the setup scripts.
README_TTA_SETUP="${TTA_TMPDIR}/README.tta.setup"
:>$README_TTA_SETUP 2>/dev/null
[ -f "$README_TTA_SETUP" ] && export README_TTA_SETUP

MkTtaDir -p \
    "${INSTDIR}/etc/data" \
    "${INSTDIR}/var/tmp" \
    "${INSTDIR}/var/log" \
    "${INSTDIR}/var/password/tier3cache" \
    "${INSTDIR}/var/password/tokencache" \
    "${INSTDIR}/var/password/webcache" \
    "${INSTDIR}/var/info" \
    "${INSTDIR}/var/info/tokens" \
    "${INSTDIR}/var/info/licenseuse" \
    "${INSTDIR}/var/preferences" \
    "${INSTDIR}/var/userresources" \
    "${INSTDIR}/var/print" \
    "${INSTDIR}/var/state" \
    2>/dev/null

chmod 751 "${INSTDIR}/var"
chmod 711 "${INSTDIR}/var/log"
chmod 770 "${INSTDIR}/var/tmp"
chmod 710 "${INSTDIR}/var/password/tier3cache"
chmod 710 "${INSTDIR}/var/password/tokencache"

pcfile=".pc" tcfile=".tc"

if ! ${UPGRADE}
then
    # Create passcache and tokencache passwords
    pushd "${INSTDIR}/var/password"
    "${INSTDIR}/bin/bin/ttarandom" --keysize 32 >${pcfile}
    chgrp $privgrp ${pcfile}; chown $privusr ${pcfile}; chmod 400 ${pcfile}
    rm -f ${tcfile} 2>/dev/null
    ln ${pcfile} ${tcfile}
    popd
fi

mkfifo -m 622 $INSTDIR/var/print/fifo 2>/dev/null

##########################################################################
# Create writeable log files for the lp/lpr interface script
#
(
    cd ${INSTDIR}/var/log
    :>print.log; :>print_error.log
    chmod 600 print.log print_error.log 2>/dev/null
    chgrp $privgrp print.log print_error.log 2>/dev/null
    chown $privusr print.log print_error.log 2>/dev/null
)

# fitz/604599
[ ! -f $INSTDIR/var/info/primary ] && echo "$a_PeerDNS" > $INSTDIR/var/info/primary
[ ! -f $INSTDIR/var/info/secondaries ] && touch $INSTDIR/var/info/secondaries

# Create the pkg directory
MkTtaDir -p $INSTDIR/etc/pkg 2>/dev/null

TTAINSTDIR=$INSTDIR
TTADATADIR=$INSTDIR/var
export TTAINSTDIR TTADATADIR

SHORT_IARCH=`echo $MACHINEARCH | sed 's/^\(....\).*/\1/'`
SCOARCH=$MACHINEARCH export SCOARCH


echo "${p_74}${i18n_configuring}"
PEERHOST=$a_PeerDNS
PortOffset=`expr $a_AsadPort - 3144`
PEERPORT=`expr 5427 + $PortOffset`
SECUREPORT=`expr 5307 + $PortOffset`

# If we're performing a dev install run the following configuration logic
if [ -n "${TTA_DEVINSTALL}" ]
then
    # We installing tta package so run the tta package specific logic
    #
    ##########################################################################
    # set up the java environment
    #

    # always have classpath include TTA class files
    JINST="${INSTDIR}/bin/java"
    CLASSPATH="${JINST}"
    CLASSPATH_EXP="${JINST}"

    for jar in `ls ${JINST}/*.jar ${JINST}/*.zip 2>/dev/null`
    do
        CLASSPATH="${CLASSPATH}:${JINST}/`basename ${jar}`"
        CLASSPATH_EXP="${CLASSPATH_EXP}:\${JINST}/`basename ${jar}`"
    done
   
    ADMINCONFIG="${INSTDIR}/var/serverresources/adminconfig"
    CLASSPATH="${CLASSPATH}:${ADMINCONFIG}"
    CLASSPATH_EXP="${CLASSPATH_EXP}:${ADMINCONFIG}"

    for jar in `ls ${JINST}/ext/*.jar ${JINST}/ext/*.zip 2>/dev/null`
    do
        CLASSPATH="${CLASSPATH}:${JINST}/ext/`basename ${jar}`"
        CLASSPATH_EXP="${CLASSPATH_EXP}:\${JINST}/ext/`basename ${jar}`"
    done

    CLASSPATH="${CLASSPATH}:${JINST}/ext/jnet.jar"
    CLASSPATH_EXP="${CLASSPATH_EXP}:\${JINST}/ext/jnet.jar"

    ##########################################################################
    # create bootstrap values. remove the existing files which the build
    # creates because they may be read-only. PEERHOST should, ultimately,
    # be provided by the request script (which should run ttahostname to
    # work out a default).
    #

    MkTtaDir -p "${INSTDIR}/var/serverconfig/global" "${INSTDIR}/var/serverconfig/local" \
                "${INSTDIR}/var/serverconfig/global/services" 2>/dev/null

    chmod 700 "${INSTDIR}/var/serverconfig" "${INSTDIR}/var/serverconfig/global" \
              "${INSTDIR}/var/serverconfig/local" \
              "${INSTDIR}/var/serverconfig/global/services"


    if [ ! -f "${INSTDIR}/var/serverconfig/global/bootstrap.properties" ]
    then
        cat > "${INSTDIR}/var/serverconfig/global/bootstrap.properties" <<EOF
# This file was build by postinstall
tarantella.config.name=arraybootstrap
tarantella.config.type=server
tarantella.config.array.externalport=$a_AsadPort
tarantella.config.array.port=$PEERPORT
tarantella.config.array.secureport=$SECUREPORT
EOF
        chmod 600 "${INSTDIR}/var/serverconfig/global/bootstrap.properties"
        chgrp "$privgrp" "${INSTDIR}/var/serverconfig/global/bootstrap.properties"
        chown "$privusr" "${INSTDIR}/var/serverconfig/global/bootstrap.properties"
    fi

    localbootstrap="${INSTDIR}/var/serverconfig/local/bootstrap.properties"
    if [ ! -f "$localbootstrap" ]
    then
        cat > "$localbootstrap" <<EOF
# This file was build by postinstall
tarantella.config.name=serverbootstrap
tarantella.config.type=server
tarantella.config.server.dns.external=$PEERHOST
tarantella.config.server.dns.peer=$PEERHOST
tarantella.config.server.webserver.port=$a_httpport
EOF
    else
        # may have changed peer dns name at setup time
        sed "s;^\(tarantella.config.server.dns.peer=\).*;\1$PEERHOST;" \
            "$localbootstrap" > "$localbootstrap.$$"

        rm -f "$localbootstrap"
        mv "$localbootstrap.$$" "$localbootstrap"
    fi

    chmod 600 "$localbootstrap"
    chgrp "$privgrp" "$localbootstrap"
    chown "$privusr" "$localbootstrap"

    ###########################################################################
    # base64 mangle dirnames
    #

    Base="${INSTDIR}/var"
    toconvert="ens password/tier3cache password/webcache preferences"
    check=`ls -d $Base/ens/o\=* 2>/dev/null`

    # now we can mangle
    if [ ! -z "$check" ]
    then
        for tomangle in $toconvert
        do
            mangle="$Base/$tomangle"
            if [ -d $mangle ]
            then
                ${INSTDIR}/bin/bin/ttab64conv $mangle | tee -a $LOGFILE
            fi
        done
    fi
else

    # set variables based on cmd line args
    java_dir="${INSTDIR}/bin/java"
    ext_dir="${java_dir}:/ext"

    ########## set up the java environment ##########
    # put main java dir & adminconfig dir  on the class path
    CLASSPATH="${java_dir}"
    CLASSPATH="${CLASSPATH}:${INSTDIR}/var/serverresources/adminconfig"

    # put all .jar & .zip files in the main java dir on the class path
    for jar in $(ls "${java_dir}/"* "${java_dir}/"*.zip 2>/dev/null); do
        CLASSPATH="${CLASSPATH}:${jar}"
    done

    # put all .jar & .zip files in the ext dir on the class path
    for jar in $(ls "${ext_dir}/"*.jar "${ext_dir}/"*.zip 2>/dev/null); do
        CLASSPATH="${CLASSPATH}:${jar}"
    done

    if ! ${UPGRADE}
    then
        # Run the initial config script if we don't already have initial config
        $TTABINDIR/scripts/install_scripts/rpm_post_install_init_config \
            --install-dir "${INSTDIR}" \
            --asad-port $a_AsadPort \
            --peer-dns $a_PeerDNS \
            --tta-group $privgrp \
            --tta-user $privusr \
            --http-port $a_httpport \
            --peer-port $PEERPORT \
            --secure-port $SECUREPORT \
            --log-file $LOGFILE
    fi
fi

##########################################################################
# Setup script arguments.
#
old_args='' jive_args=''
TTABINDIR=$INSTDIR/bin export TTABINDIR

##########################################################################

# Run the templates script if we are
# Run setup scripts.


xflag=""
[ "$trace" = "x" ] && xflag="-x"

# If we're a dev install we need to run the templates script
if [ -n "${TTA_DEVINSTALL}" ]
then
    setup_scripts="$setup_scripts templates"
fi
 
setup_scripts="$setup_scripts dbcreate extended_templates loadprobe_config"


for script in $setup_scripts
do
    printf "${i18n_pf1_runningscript}" "${script}" | tee -a $LOGFILE
    sh $xflag $TTABINDIR/scripts/install_scripts/setup $script\
	--instdir "$INSTDIR"\
	--datadir "$INSTDIR/var"\
	--version "$PRODUCT_VERSION"\
	--pkginst "$PKGINST"\
	--peerdns "$PEERHOST"\
	$old_args --savefile "$SAVE_FILE" >>$LOGFILE 2>&1
    res=$?
    if [ $res -ne 0 ]; then
	echo "${m_scriptfail}${res}" | tee -a $LOGFILE
	printf "${i18n_pf1_seesetuplog}" "${INSTDIR}/var/log/setup.log" >>$LOGFILE
	cleanandexit 1 		# if one of the setup scripts failed
    else
	echo "${i18n_scriptok}" | tee -a $LOGFILE
    fi
done

if ! ${UPGRADE}
then
    pckf="${INSTDIR}/var/serverconfig/local/passwdcachekey.properties"
    id="tarantella.config.passcache.cryptkey"
    pck=`${TTABINDIR}/bin/ttarandom --hex --keysize 128`
    sed "s/${id}=.*/${id}=${pck}/" ${pckf} >${pckf}, && cp ${pckf}, ${pckf} && rm -f ${pckf},
fi

PATH=$INSTDIR/bin/bin:$PATH export PATH

##########################################################################
# Make sure all directories are world-readable (apart from some specific
# exclusions).
#
FIXOWNERSHIP=${TTA_TMPDIR}/fix$$
find $INSTDIR -type d -print |
    egrep -v "^$INSTDIR/var/(ens|log|password|print|spool|serverresources|serverconfig|tmp)" |
    egrep -v "^$INSTDIR/webserver/.*/logs\$" >${FIXOWNERSHIP}
xargs chmod ugo+x <${FIXOWNERSHIP}
xargs chmod ug+r <${FIXOWNERSHIP}
xargs chmod o-rw <${FIXOWNERSHIP}
rm -f ${FIXOWNERSHIP} 2>/dev/null
MkTtaDir $INSTDIR/etc/pkg/$PKGINST 2>/dev/null
chgrp $privgrp $INSTDIR/etc/pkg/$PKGINST/extras 2>/dev/null
chown $privusr $INSTDIR/etc/pkg/$PKGINST/extras 2>/dev/null
chmod 751 $INSTDIR/etc/pkg/$PKGINST 2>/dev/null
chmod 640 $INSTDIR/etc/pkg/$PKGINST/extras 2>/dev/null

# ensure other files are safe
find $INSTDIR/var/serverconfig -type f -print | xargs chmod 600 2>/dev/null
chmod 700 $INSTDIR/var/serverconfig $INSTDIR/var/serverconfig/global $INSTDIR/var/serverconfig/local

getTTAfiles()
{
    X11BASEPORT=6000
    find . ! -type d -print | while read fnam; do
	# extract the numeric component from a name like "X13"
	offset=`expr "$fnam" : '[^0-9]*\([0-9][0-9]*\)$'`
	case "$offset" in
	[0-9]*)
	    if [ "$offset" -ge 10 ]; then
		# check to see if there's a listener on the corresponding X11 TCP port:
		# we don't want to delete sockets that are active
		tcpport=`expr "$X11BASEPORT" + "$offset"`
		$INSTDIR/bin/bin/ttahostname --probeport $tcpport && echo $fnam
	    fi
	esac
    done
    return 0
}

# relax permissions on local X directories
(
    cd /dev/X 2>/dev/null
    if [ `pwd` = /dev/X ]; then
	find . -perm -400 -print | xargs chmod go+r 2>/dev/null
	find . -perm -200 -print | xargs chmod go+w 2>/dev/null
	find . -perm -100 -print | xargs chmod go+x 2>/dev/null
    fi
)

# delete UNIX domain sockets that "probably" belong to TTA
# (filename is a string ending with a number >= 10)
(
    cd /tmp/.X11-unix 2>/dev/null
    if [ `pwd` = /tmp/.X11-unix ]; then
	fnames=`getTTAfiles`
	[ -n "$fnames" ] && rm -f $fnames >/dev/null 2>&1
    fi
)

##########################################################################
# for files in var which do not need to be read-write to root only

# make the tier3 loadbalancing per-server properties template readable by all
chmod 644 $INSTDIR/var/serverconfig/global/t3hostdata/template.properties
chgrp $privgrp $INSTDIR/var/serverconfig/global/t3hostdata
chown $privusr $INSTDIR/var/serverconfig/global/t3hostdata

##########################################################################
# create var/info/productcode file
grep product.type $INSTDIR/var/serverconfig/local/server.properties |
    cut -d'=' -f 2 > $INSTDIR/var/info/productcode

##########################################################################
# fix ownerships in the var tree
FIXOWNERSHIP=${TTA_TMPDIR}/fix$$
    rm -rf ${FIXOWNERSHIP} 2>/dev/null
    find ${INSTDIR}/var \( ! -group $privgrp \) \( ! -type l \) -print >${FIXOWNERSHIP}
    find ${INSTDIR}/var \( ! -group $privgrp \) -type l -print |
    xargs ls -ld |
    awk 'BEGIN {
	INCLUDE = "'"${INSTDIR}"'"
	INCLUDELEN = length(INCLUDE)
	EXCLUDE = "'"_DUMMY_"'"
	EXCLUDELEN = length(EXCLUDE)
    }
    substr($NF,1,EXCLUDELEN) == EXCLUDE {
	next
    }
    substr($NF,1,1) != "/" || substr($NF,1,INCLUDELEN) == INCLUDE {
	src = NF-2
	print $src
    }' >>${FIXOWNERSHIP}

[ -s "${FIXOWNERSHIP}" ] && xargs chgrp $privgrp <${FIXOWNERSHIP} 2>/dev/null
    rm -rf ${FIXOWNERSHIP} 2>/dev/null
    find ${INSTDIR}/var \( ! -user $privusr \) \( ! -type l \) -print >${FIXOWNERSHIP}
    find ${INSTDIR}/var \( ! -user $privusr \) -type l -print |
    xargs ls -ld |
    awk 'BEGIN {
	INCLUDE = "'"${INSTDIR}"'"
	INCLUDELEN = length(INCLUDE)
	EXCLUDE = "'"_DUMMY_"'"
	EXCLUDELEN = length(EXCLUDE)
    }
    substr($NF,1,EXCLUDELEN) == EXCLUDE {
	next
    }
    substr($NF,1,1) != "/" || substr($NF,1,INCLUDELEN) == INCLUDE {
	src = NF-2
	print $src
    }' >>${FIXOWNERSHIP}

[ -s "${FIXOWNERSHIP}" ] && xargs chown $privusr <${FIXOWNERSHIP} 2>/dev/null
rm -rf ${FIXOWNERSHIP} 2>/dev/null
chown -h ${privusr}:${privgrp} ${INSTDIR}/var/serverresources/expect/windows.exp 2>/dev/null

###########################################################################
# Set the initial, max and absmax JVM heap size based on the available memory.
# Also set a few other attributes.
pmem=""
case ${SCOARCH} in
i3li*)
    pmem=`grep -i '^memtotal' /proc/meminfo | LANG=C LC_ALL=C tr -cd '[0-9]'`
    _units=`grep -i '^memtotal' /proc/meminfo | awk '{print $NF}' | LANG=C LC_ALL=C tr '[A-Z]' '[a-z]'`
    [ -n "${pmem}" ] && {
	case "${_units}" in
	gb|gigabytes) pmem=`expr ${pmem} \* 1024`;;
	mb|megabytes) ;;
	*)  pmem=`expr ${pmem} / 1024`
	esac
    }
    ;;
*)  _prtconf=''
    for _dir in `echo "/usr/sbin:${PATH}" | tr : ' '`; do
	case "${_dir}" in
	/*) [ -x "${_dir}/prtconf" ] && { _prtconf="${_dir}/prtconf"; break; }
	esac
    done
    [ -x "${_prtconf}" ] && {
	pmem=`LANG=C LC_ALL=C ${_prtconf} 2>/dev/null | grep -i '^memory' | LANG=C LC_ALL=C tr -cd '[0-9]'`
	_units=`LANG=C LC_ALL=C ${_prtconf} 2>/dev/null | grep -i '^memory' | awk '{print $NF}' | LANG=C LC_ALL=C tr '[A-Z]' '[a-z]'`
    }
    [ -n "${pmem}" ] && {
	case "${_units}" in
	gb|gigabytes) pmem=`expr ${pmem} \* 1024`;;
	kb|kilobytes) pmem=`expr ${pmem} / 1024`;;
	esac
    }
esac
_value=`echo "${pmem}" | tr -cd '[0-9]'`
[ -z "${_value}" ] && pmem=0

if [ "${pmem:-0}" -lt 2048 ]; then
    # phys mem less than 2GB
    Vinit=128 Vmax=256 Vabsmax=256
else
    # phys mem more than 2GB
    Vinit=256 Vmax=512 Vabsmax=512
fi

TC="tarantella.config"
LC="${INSTDIR}/var/serverconfig/local"

Kinit="${TC}.tuning.heapsize.initial" 
Finit="${LC}/tuning.properties"

Kmax="${TC}.tuning.heapsize.max"
Fmax="${Finit}"

Kabsmax="${TC}.tuning.heapsize.absmax"
Fabsmax="${Finit}"

Kmaxwrk="${TC}.server.calc.maxworkers"
Vmaxwrk=14
Fmaxwrk="${LC}/server.properties"

Kwrkpool="${TC}.server.soapworkerpoolconfig"
Vwrkpool="utility|:15,\
webtopsession|:24,\
webtopcontent|:9,\
emulatorsession/startSession|#emulatorsession/resumeSession|:24,\
emulatorsession|:7,\
print|:7,\
event|:15,\
user|:9,\
admin|#datastore|:9"
Fwrkpool="${Fmaxwrk}"

Ksslmin="${TC}.ssldaemon.minprocesses"
Vsslmin=4
Fsslmin="${LC}/ssldaemon.properties"

Ksslmax="${TC}.ssldaemon.maxprocesses"
Vsslmax=4
Fsslmax="${Fsslmin}"

ReplaceAttr() {
    echo "ReplaceAttr $1 $2 $3" >>${INSTDIR}/var/log/setup.log
    cp -p $3 $3,
    (grep -v "^$1=" $3; echo "$1=$2"|tr '|' '\\') >$3,
    [ `wc -l <$3,` -ge `wc -l <$3` ] && cp -p $3, $3
    rm -f $3,
}

if ! ${UPGRADE}
then
    ReplaceAttr ${Kinit} ${Vinit} ${Finit}
    ReplaceAttr ${Kmax} ${Vmax} ${Fmax}
    ReplaceAttr ${Kabsmax} ${Vabsmax} ${Fabsmax}
    ReplaceAttr ${Kmaxwrk} ${Vmaxwrk} ${Fmaxwrk}

    ReplaceAttr ${Ksslmin} ${Vsslmin} ${Fsslmin}
    ReplaceAttr ${Ksslmax} ${Vsslmax} ${Fsslmax}

    ReplaceAttr ${Kwrkpool} ${Vwrkpool} ${Fwrkpool}
fi


##########################################################################
# set up apache / tomcat

[ -s "$TTA_TMPDIR/ttainst.cmds_to_webwrap" ] && . $TTA_TMPDIR/ttainst.cmds_to_webwrap
[ -s "${INSTDIR}/var/tmp/ttainst.cmds_to_webwrap" ] && . ${INSTDIR}/var/tmp/ttainst.cmds_to_webwrap

echo ${N} "${i18n_config_webservices}${C}" | tee -a $LOGFILE
cd ${INSTDIR}/webserver
# Tomcat and Apache packages are now "default"
for package in apache tomcat; do
(
    echo "default" >"${INSTDIR}/var/info/${package}version"
)
done
A_VER="default"
T_VER="default"

# Set security context on dynamically loadable Apache modules, if applicable (SELinux).
# First try to find a security context that we can copy:
sec_con_reference=""
for sec_con_preferred in textrel_shlib_t texrel_shlib_t shlib_t; do
sec_con_reference=`find /usr/lib -name '*.so' -print | xargs ls -dZ 2>/dev/null | grep ":${sec_con_preferred}" | sed 1q`
[ -n "${sec_con_reference}" ] && {
    reference_file=`expr "${sec_con_reference}" : '.* \(/usr/lib/.*\)'`
    [ -n "${reference_file}" ] && (
	cd "${INSTDIR}/webserver/apache/${A_VER}/modules"
	chcon --reference="${reference_file}" *.so 2>/dev/null
    )
    break
}
done


PFILE="${INSTDIR}/webserver/tomcat/${T_VER}/shared/classes/com/tarantella/tta/webservices/client/apis/Resources.properties"
mkdir -p `dirname ${PFILE}` 2>/dev/null

if ! ${UPGRADE}
then  
    # Generate and store web server auth credentials
    t=${TMPDIR:-/tmp}/ttatomcat$$
    rm -f $t >/dev/null 2>&1
    tomcatDir="${INSTDIR}/webserver/tomcat/${T_VER}"
    trustedUsername="sgd_trusted_user"
    trustedPassword=`${TTABINDIR}/bin/ttarandom --keysize 20 --printable`
    (
        _views="com/tarantella/tta/webservices/client/views"
        _fp_views="${tomcatDir}/shared/classes/com/tarantella/tta/webservices/client/views"
        mkdir -p ${_fp_views}
        cd ${_fp_views}
        [ -z "`grep '^sgdkey=........' Resources.properties 2>/dev/null`" ] && {
            sgdkey=`${TTABINDIR}/bin/ttarandom --hex --keysize 32`
            grep -v "^sgdkey=" Resources.properties >$t 2>/dev/null
            cp $t Resources.properties
            echo "sgdkey=${sgdkey}" >>Resources.properties
        }
        encodedAuth=`${SGD_JAVA_DIR}/java -cp ${INSTDIR}/bin/java/jserver* com.tarantella.tta.webservices.client.views.SgdPasswd --encode "${trustedUsername}:${trustedPassword}"`
        ret=$?
        if [ ${ret} -ne 0 ]
        then
            printf "${i18n_pf1_scriptfail}" "${ret}" | tee -a $LOGFILE
            printf "${i18n_pf1_seesetuplog}" "${INSTDIR}/var/log/setup.log" >>$LOGFILE
            cleanandexit 1
        fi

        grep -v "^sgdaccess=" Resources.properties >$t 2>/dev/null
        cp $t Resources.properties
        echo "sgdaccess=${encodedAuth}" >>Resources.properties
    )

    # Create a digest of the password and grab it from the output
    digestedPassword="$(${tomcatDir}/bin/digest.sh -a SHA-256 "${trustedPassword}" | sed -n "s/${trustedPassword}://p")"
    ret=$?
    if [ ${ret} -ne 0 ]
    then
        printf "${i18n_pf1_scriptfail}" "${ret}" | tee -a $LOGFILE
        printf "${i18n_pf1_seesetuplog}" "${INSTDIR}/var/log/setup.log" >>$LOGFILE
        cleanandexit 1
    fi

    tomcatUsers="${tomcatDir}/conf/tomcat-users.xml"
    sed -i "s/%%proxyuser/${trustedUsername}/;s/%%proxypass/${digestedPassword}/" "${tomcatUsers}" 2>/dev/null
fi 

echo "${i18n_scriptok}" | tee -a $LOGFILE

    # Developers' Note: don't change the *format* of the next line, since
    # devinstall.sh relies on it.  The quoted string can be changed, however.
    _artemisurl="sgdadmin"

    _tomcatDir="${INSTDIR}/webserver/tomcat/`cat ${INSTDIR}/var/info/tomcatversion`"
    _attempts=0
    while [ ! -d "${_tomcatDir}/webapps/${_artemisurl}" ]; do
	sleep 3
	_attempts=`expr "${_attempts}" + 1`
	[ "${_attempts}" -gt 10 ] && break
    done
    _d="${_tomcatDir}/webapps/${_artemisurl}/security"
    [ -d "${_d}" ] || {
	mkdir -p "${_d}" 2>/dev/null; chown $webservusr "${_d}"; chgrp $privgrp "${_d}"; chmod 750 "${_d}"
    }
    (
	cd "${_d}"
	rm -f sslkeystore 2>/dev/null; ln -s ${INSTDIR}/var/info/certs/sslkeystore .
	rm -f key 2>/dev/null; ln -s ${INSTDIR}/var/info/key .
    )
    _d="${_tomcatDir}/webapps/${_artemisurl}/images"
    [ -d "${_d}" ] || {
	mkdir -p "${_d}" 2>/dev/null; chown $webservusr "${_d}"; chgrp $privgrp "${_d}"; chmod 750 "${_d}"
    }
    (
	cd "${_d}"
	rm -f icons 2>/dev/null; ln -s ../../sgd/resources/images/icons .
    )


# Create a link to ther server.keys file so the webserver can authenticate
# itself to the Tarantella server.
SERVERKEYS_SOAP="$INSTDIR/webserver/tomcat/${T_VER}/webapps/soap/WEB-INF/server.keys"
rm -f "${SERVERKEYS_SOAP}" 2>/dev/null
ln -s "$INSTDIR/var/info/server.keys" "${SERVERKEYS_SOAP}"


# Sort out webserver file/directory permissions.
# Default permissions are:
# 	directories:	rwxr-x--- / root / ttaserv
#	files:		rw-r----- / root / ttaserv
# unless specifically overridden below
A_VER=`cat "${INSTDIR}/var/info/apacheversion"`
T_VER=`cat "${INSTDIR}/var/info/tomcatversion"`

PERMS="${TTA_TMPDIR}/perms$$"; rm -f ${PERMS} 2>/dev/null

[ -z "${TTA_DEVINSTALL}" ] && {
find ${INSTDIR}/webserver ! \( -type l -o -user root \) -print | tee -a ${PERMS} | xargs chown root 2>/dev/null
}
find ${INSTDIR}/webserver ! \( -type l -o -group $privgrp \) -print | tee -a ${PERMS} | xargs chgrp $privgrp 2>/dev/null
find ${INSTDIR}/webserver ! \( -type l -o -type d -o -perm 640 \) -print | tee -a ${PERMS} | xargs chmod 640 2>/dev/null
find ${INSTDIR}/webserver -type d ! -perm 750 -print | tee -a ${PERMS} | xargs chmod 750 2>/dev/null

# Fitz 605456: Make Tomcat's conf directory 770.
find ${INSTDIR}/webserver/tomcat -type d -name conf ! -perm 770 -print | tee -a ${PERMS} | xargs chmod 770 2>/dev/null

# Log directories:	rwxrwx--- / ttaserv / ttaserv
# - files therein:	rw-rw---- / ttaserv / ttaserv
A_VER=`cat "${INSTDIR}/var/info/apacheversion"`
T_VER=`cat "${INSTDIR}/var/info/tomcatversion"`
LOGDIRS=`find "${INSTDIR}/webserver/apache/${A_VER}" "${INSTDIR}/webserver/tomcat/${T_VER}" -type d \( -name log -o -name logs -o -name work \) -print`
if [ -n "$LOGDIRS" ]; then
find $LOGDIRS -type d ! -perm 770 -print | tee -a ${PERMS} | xargs chmod 770 2>/dev/null
find $LOGDIRS ! \( -type d -o -perm 660 \) -print | tee -a ${PERMS} | xargs chmod 660 2>/dev/null
find $LOGDIRS ! -user $webservusr -print | tee -a ${PERMS} | xargs chown $webservusr 2>/dev/null
fi

# Executable files:	rwxr-x--- / root / ttaserv
BINDIRS=`find ${INSTDIR}/webserver -type d \( -name bin -o -name build \) -print`
[ -n "$BINDIRS" ] && find $BINDIRS ! \( -type d -o -perm 750 \) -print | tee -a ${PERMS} | xargs chmod 750 2>/dev/null

# Shell scripts:	rwxr-x--- / ttaserv / ttaserv
find ${INSTDIR}/webserver ! \( -type l -o -type d -o -perm 750 \) \( -name '*.sh' -o -name '*.ini' -o -name 'libtool' \) -print | egrep -v '/ttatcc\.sh$' | tee -a ${PERMS} | xargs chmod 750 2>/dev/null
find ${INSTDIR}/webserver ! \( -type l -o -type d -o -user $webservusr \) \( -name '*.sh' -o -name '*.ini' -o -name 'libtool' \) -print | tee -a ${PERMS} | xargs chown $webservusr 2>/dev/null

# Odds and ends
file1="${INSTDIR}/webserver/tomcat/${T_VER}/webapps/soap/WEB-INF"
echo "${file1}" >>${PERMS}
chmod 770 "${file1}"

# create a minimal webapps/soap/index.html
cat >${INSTDIR}/webserver/tomcat/${T_VER}/webapps/soap/index.html <<\!
<!DOCTYPE html>
<html>
<head>
<title>Oracle Secure Global Desktop</title>
</head>
<body>
</body>
</html>
!

cp $LOGFILE $INSTDIR/var/log/${PKGINST}_postinstall.log 2>/dev/null

rot13() {
    echo $1 | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ NOPQRSTUVWXYZABCDEFGHIJKLM
}

# Create tmp file that indicates to create default profile.
# It will get deleted after the profile has been created.
DEFAULTPROFILE_FLAG=${INSTDIR}/var/tmp/defaultprofile.tmp
rm -f ${DEFAULTPROFILE_FLAG} 2>/dev/null
DEFAULTPROFILE=".../_ens/o=Tarantella System Objects/_service/sco/tta/resources/Default"
if [ -n "${TTA_DEVINSTALL}" ]
then 
    # Create the file to trigger the profile for a devinstall only.
    ${INSTDIR}/bin/tarantella object list_attributes --name "${DEFAULTPROFILE}" >/dev/null 2>&1 || touch ${DEFAULTPROFILE_FLAG}
fi

# Reset the REST port if the port offset is non-zero
if [ ${PortOffset} -ne 0 ]
then
    RESTPort=`expr 8427 + $PortOffset`
    ${INSTDIR}/bin/tarantella config edit --tarantella-config-rest-apiport "${RESTPort}" >/dev/null 2>&1
fi

rm -rf ${INSTDIR}/var/postpostinstall 2>/dev/null

# some printing files need to be readable by CUPS
(
    cd ${INSTDIR}/etc/data
    chmod ugo+r \
	default.printerinfo.txt \
	hostnamemap.txt \
	printernamemap.txt \
	printertypes.txt
)

# bin/scripts/shell needs to be world-executable, as it is run during launch
chmod ugo+rx ${INSTDIR}/bin/scripts/shell

# Check if the ios_profile_create link is there
IOS_PROFILE_CREATE=${INSTDIR}/bin/scripts/ios_profile_create.sh
[ -f $IOS_PROFILE_CREATE ] && [ ! -h $IOS_PROFILE_CREATE ] && {
    # Not a symlink, move it out of the way
    mv ${IOS_PROFILE_CREATE} ${IOS_PROFILE_CREATE}.orig
}

[ ! -f ${IOS_PROFILE_CREATE} ] && {
    # Link SGD 5.0 ios_profile_create to SGD 5.1 mobile_profile_create
    ln -s ${INSTDIR}/bin/scripts/mobile_profile_create.sh \
        ${IOS_PROFILE_CREATE}
}

[ ! -e ${INSTDIR}/var/info/registered-extensions/unixcdm/unixcdm.cfg ] && {
    # Create a link for the unixcdm config
    ln -s ${INSTDIR}/var/info/registered-extensions/unixcdm/nfs.cfg \
        ${INSTDIR}/var/info/registered-extensions/unixcdm/unixcdm.cfg
}

# NB  TidyScript deletes TTA_TMPDIR.  Don't do anything after this point
#     that requires TTA_TMPDIR to be present.

rm -f ${INSTDIR}/var/UPGRADE 2>/dev/null

ls -1d \
    ${INSTDIR}/var/info/* \
    ${INSTDIR}/var/log/* \
    ${INSTDIR}/var/tmp/* 2>/dev/null |
    egrep -v 'gsbindir' |
    xargs chmod o-rw
cleanandexit ${OK} ${KEEP_TMPDIR}


