#!/bin/sh
#  $Id: request.sh,v 1.10 2005/08/26 15:47:43 billwe Exp $
#  Copyright 2005 Sun Microsystems, Inc. All rights reserved.
#  This software code contains proprietary information 
#  and should be treated as confidential.
#
#  Component: Tarantella Tier3 Enhancement Module
#  Author: stuarth
#
#  Request Script for the installation of the Tier3 Enhancement Module for UNIX
#
#########################################################################
# The aim of this file is to ask all questions before we have extracted
# any files from the pkg file. This should also carry out any checks necessary
# for this package to install, e.g. check versions of existing installed
# packages.
#########################################################################
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,v 10.38 2005/06/20 19:21:26 peterc Exp $
#  Copyright (C) 1996-2005 Tarantella, Inc.
#  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]*\)'`
       ;;
      # 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




stopspin ()
{
   [ ! -d "$TTA_TMPDIR" ] && return
   sleepcmd="sleep"
   sleeptime="1"
   if [ -z "$sleeptime" ]; then sleeptime=1; fi
   if [ -z "$sleepcmd" ]; then sleeptime=""; fi

   rm -f $TTA_TMPDIR/spinning >/dev/null 2>&1
   $sleepcmd $sleeptime
}

stopspin

# Version numbers
PRODUCT_VERSION="4.2"
PRODUCT_VERSION_FULL="4.20.983"
PRODUCT_VERSION_MAJOR=4
PRODUCT_VERSION_FEATURE=2
PRODUCT_VERSION_BUG=0
PRODUCT_VERSION_BUILD=983
PRODUCT_VERSION_CAB=4,2,0,983

# Product names
PRODUCT_FULL_NAME="Sun Secure Global Desktop Software"
PRODUCT_SHORT_NAME="Secure Global Desktop"
PRODUCT_SHORT_FILENAME="Tarantella"
TSP_FULL_NAME="Sun Secure Global Desktop Security Pack"
TSP_SHORT_NAME="Security Pack"
WCP_FULL_NAME="Sun Secure Global Desktop Windows Connectivity Pack"
WCP_SHORT_NAME="Windows Connectivity Pack"
TN3270_FULL_NAME="Sun Secure Global Desktop Mainframe Connectivity Pack"
TN3270_SHORT_NAME="Mainframe Connectivity Pack"
AS400_FULL_NAME="Sun Secure Global Desktop AS/400 Connectivity Pack"
AS400_SHORT_NAME="AS/400 Connectivity Pack"
S1PSTK_FULL_NAME="Sun Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_FULL_NAME="Sun 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="Sun Secure Global Desktop Native Client for Windows 3.1"
NATIVE_WIN16_SHORT_NAME="Native Client for Windows 3.1"
NATIVE_WIN32_FULL_NAME="Sun 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="Sun Secure Global Desktop Native Client for Wyse"
NATIVE_WYSE_SHORT_NAME="Native Client for Wyse"
NATIVE_FULL_NAME="Sun Secure Global Desktop Native Client"
NATIVE_SHORT_NAME="Native Client"
NATIVE_REGISTRY_NAME="Tarantella Native Client"
TCC_FULL_NAME="Sun Secure Global Desktop Client"
TCC_HELPER_NAME="Sun Secure Global Desktop Client Helper"
TCC_ACTIVEX_NAME="Sun Secure Global Desktop ActiveX Control"
TCC_PLUGIN_NAME="Sun Secure Global Desktop Netscape Plug-in"
T3COMPONENT_WIN_NAME="Sun Secure Global Desktop Enhancement Module for Windows"
T3COMPONENT_UNIX_NAME="Sun Secure Global Desktop Enhancement Module for UNIX/Linux"
T3COMPONENT_SHORT_UNIX_NAME="tem"
T3COMPONENT_NAME="Sun Secure Global Desktop Enhancement Module"

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

ARCHIVE_SUFFIX="F"

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

PRODUCT_VENDOR="Sun Microsystems, Inc."
PRODUCT_SHORT_VENDOR="Sun"

# 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"
# Reboot and cron names
INST_RCFILE="S90$PRODUCT_SHORT_FILENAME"
INST_RCSTRING="##$PRODUCT_SHORT_FILENAME##"

# Tarantella Web Server
TWS_INST_RCFILE="S89${PRODUCT_SHORT_FILENAME}WebServer"
TWS_INST_RCSTRING="##${PRODUCT_SHORT_FILENAME}WebServer##"

# Modify this list whenever the list of supported upgrades changes.
# Version numbers may contain wildcards.
PRIOR_UPGRADES="3.3*.* 3.40.* 3.42.* 4.00.* 4.10.* 4.20.*"
SUPPORTED_UPGRADES="$PRODUCT_VERSION_FULL $PRIOR_UPGRADES"
# the License Product Code
PRODUCT_LICENSE_PRODUCT_CODE="8388608"
TSP_US_LICENSE_PRODUCT_CODE="4194304"
TSP_INTL_LICENSE_PRODUCT_CODE="2097152"
USER_RESTRICTION="1"


# Version numbers
PRODUCT_VERSION="4.2"
PRODUCT_VERSION_FULL="4.20.983"
PRODUCT_VERSION_MAJOR=4
PRODUCT_VERSION_FEATURE=2
PRODUCT_VERSION_BUG=0
PRODUCT_VERSION_BUILD=983
PRODUCT_VERSION_CAB=4,2,0,983

# Product names
PRODUCT_FULL_NAME="Sun Secure Global Desktop Software"
PRODUCT_SHORT_NAME="Secure Global Desktop"
PRODUCT_SHORT_FILENAME="Tarantella"
TSP_FULL_NAME="Sun Secure Global Desktop Security Pack"
TSP_SHORT_NAME="Security Pack"
WCP_FULL_NAME="Sun Secure Global Desktop Windows Connectivity Pack"
WCP_SHORT_NAME="Windows Connectivity Pack"
TN3270_FULL_NAME="Sun Secure Global Desktop Mainframe Connectivity Pack"
TN3270_SHORT_NAME="Mainframe Connectivity Pack"
AS400_FULL_NAME="Sun Secure Global Desktop AS/400 Connectivity Pack"
AS400_SHORT_NAME="AS/400 Connectivity Pack"
S1PSTK_FULL_NAME="Sun Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_FULL_NAME="Sun 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="Sun Secure Global Desktop Native Client for Windows 3.1"
NATIVE_WIN16_SHORT_NAME="Native Client for Windows 3.1"
NATIVE_WIN32_FULL_NAME="Sun 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="Sun Secure Global Desktop Native Client for Wyse"
NATIVE_WYSE_SHORT_NAME="Native Client for Wyse"
NATIVE_FULL_NAME="Sun Secure Global Desktop Native Client"
NATIVE_SHORT_NAME="Native Client"
NATIVE_REGISTRY_NAME="Tarantella Native Client"
TCC_FULL_NAME="Sun Secure Global Desktop Client"
TCC_HELPER_NAME="Sun Secure Global Desktop Client Helper"
TCC_ACTIVEX_NAME="Sun Secure Global Desktop ActiveX Control"
TCC_PLUGIN_NAME="Sun Secure Global Desktop Netscape Plug-in"
T3COMPONENT_WIN_NAME="Sun Secure Global Desktop Enhancement Module for Windows"
T3COMPONENT_UNIX_NAME="Sun Secure Global Desktop Enhancement Module for UNIX/Linux"
T3COMPONENT_SHORT_UNIX_NAME="tem"
T3COMPONENT_NAME="Sun Secure Global Desktop Enhancement Module"

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

ARCHIVE_SUFFIX="F"

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

PRODUCT_VENDOR="Sun Microsystems, Inc."
PRODUCT_SHORT_VENDOR="Sun"

# 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"
# 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_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"
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_pkgprog=""
PRODUCT_PACKAGE_SPECIAL_NAME_pkgprog=" Application Packaging Tools"
PRODUCT_PACKAGE_CATEGORY_pkgprog="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"

# 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


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"

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"


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

# if we're being run from a shx file, then that'll have set up a tmpdir for us
TTA_TMPDIR=`echo $REQDIR | sed -n 's;^\(.*/ttainst_[0-9][0-9]*\)/.*;\1;p'`
if [ -z "$TTA_TMPDIR" -o ! -d "$TTA_TMPDIR" ]
then
# override by setting $TMPDIR
tmpdir_try=0
tmpdir_prefix="ttainst_"
TTA_TMPDIR=${TMPDIR:-/tmp}
oldcwd=`pwd`
mkdir -p $TTA_TMPDIR 2>/dev/null
cd $TTA_TMPDIR
mkdir -m 700 ${tmpdir_prefix}${tmpdir_try} 2>/dev/null
while [ $? -ne 0 -a $tmpdir_try -lt 100 ]; do
    tmpdir_try=`expr $tmpdir_try + 1`
    mkdir -m 700 ${tmpdir_prefix}${tmpdir_try} 2>/dev/null
done
cd "$oldcwd"
if [ $tmpdir_try -ge 100 ]; then
    # something amiss here, someone trying to mess with us?
    echo "Failed 100 times to create a safe temp dir. Exiting."
    echo "Please check for $tmpdir_prefix directories in $TTA_TMPDIR"
    exit 1
else
    TTA_TMPDIR=${TTA_TMPDIR}/${tmpdir_prefix}${tmpdir_try}
    export TTA_TMPDIR
    chown nobody ${TTA_TMPDIR} 2>/dev/null
    chmod 777 ${TTA_TMPDIR} 2>/dev/null
fi

fi
LOGDIR=$TTA_TMPDIR
LOGFILE=$LOGDIR/$PKG.inst.log
scriptname=`expr "//$0" : '.*/\(.*\)' `
chmod 644 $LOGFILE >/dev/null 2>&1
echo "---> $scriptname" >>$LOGFILE
chmod 644 $LOGFILE >/dev/null 2>&1
export LOGFILE


port=3579
pmem=0
vmem=0

cleanup()
{
    trap '' 1 2 3 15
    echo "<--- $who_i_am" >>$LOGFILE
}

cleanandexit()
{
    cleanup
    exit $1
}

trap 'cleanup;exit $FAIL' 1 2 3 15

echo "`date`:*** REQUEST STARTS ***" >>$LOGFILE
echo "LOGFILE = $LOGFILE" >>$LOGFILE
echo "TTA_TMPDIR = $TTA_TMPDIR" >>$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 [ ! -f ${PKGSAV}/${PKGLANG}_setup ]; then
	cp ${REQDIR}/${PKGLANG}_setup ${PKGSAV}/${PKGLANG}_setup >/dev/null 2>&1
    fi
fi


# target architecture check (unless we are running from an SHX file,
# which will have done the check already)
[ -z "${TTA_RPM}" ] && [ ! -f "${TTA_TMPDIR}/SHX" ] && {
    _INTENDEDARCH=`expr "${PSTAMP}" : '.*\.\(.*\)\..*'`
    _SHORT_IARCH=`expr "${_INTENDEDARCH}" : '\(....\).*'`
    case "${MACHINEARCH}" in
    ${_SHORT_IARCH}* )
	# arch code is OK: check the version
	_PKG_VERSION=`expr "${_INTENDEDARCH}" : '....\(.*\)'`
	_SYS_VERSION=`expr "${MACHINEARCH}"  : '....\(.*\)'`
	if [ "0${_PKG_VERSION}" -gt "0${_SYS_VERSION}" ]; then
	    qprompt="${l_warnprefix}${l_versionmismatch}"
	    echo " "
	    answer="$a_no"
echo "$qprompt"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_continue [$answer] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$answer"   # default
  fi
  case "$_answer" in
    [${a_case_yes}]* )
	    _answer=$s_yes
	    _valid=true
	    ;;
    [${a_case_no}]* )
	    _answer=$s_no
	    _valid=true
	    ;;
  esac
done
answer="$_answer"

	    [ "$answer" != "$s_yes" ] && { echo "Exiting."; exit 9; }
	fi
	;;
    *)  if [ "$_SHORT_IARCH" != "null" ]; then
	    qprompt="${l_warnprefix}${l_archmismatch}"
	    echo " "
	    answer="$a_no"
echo "$qprompt"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$l_continue [$answer] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$answer"   # default
  fi
  case "$_answer" in
    [${a_case_yes}]* )
	    _answer=$s_yes
	    _valid=true
	    ;;
    [${a_case_no}]* )
	    _answer=$s_no
	    _valid=true
	    ;;
  esac
done
answer="$_answer"

	    [ "$answer" != "$s_yes" ] && { echo "Exiting."; exit 9; }
	fi
    esac		
}


#
# Start of dialog for setup.
#
echo

# see if there is already an existing version of this package
oldver=""
[ -z "${TTA_RPM}" ] && oldver="`pkgparam $PRODUCT_TIER3TEM_PKGNAME VERSION 2>/dev/null`" 
pkgname=$PRODUCT_TIER3TEM_PKGNAME

# see if it is a newer version
# ::TODO:: do I want to tie the version of Tier3TEM to the Tarantella version?
if [ ! -z "$oldver" ]; then
  oldcheck="`echo $oldver | tr . 0`"
  newcheck="`echo $PRODUCT_VERSION_FULL | tr . 0`"

  [ "$oldcheck" -gt "$newcheck" ] 2>&1
  if [ "$?" = "0" ]; then
    echo "$m_oldver1$oldver$m_oldver2$PRODUCT_VERSION_FULL$m_oldver3$pkgname"
    echo "<--- $who_i_am" >>$LOGFILE
    exit $FAIL
  fi
fi
#
# Do the platform dependent stuff to get the physical (PMEM) and virtual (VMEM)
# memory
#
case "$MACHINEARCH" in
i3li*|ppli*)
    vmem=`cat /proc/meminfo|grep SwapTotal|awk '{print int($2/1024)}'`
    ;;
i3un*)
    echo "UNIXWARE"            # TEMPORARY
    SWAP=`swap -s`
    echo $SWAP
    # UnixWare counts swap in 512 byte blocks so divide by 2048 to get Mb
    vmem=`echo $SWAP|awk '{print int(($8 + $11)/2048)}'`
    echo "VMEM= $vmem"
    ;;
spso*)
    SWAP=`swap -s`
    vmem=`echo $SWAP|sed -g 's/k//'|awk '{print int(($9 + $11)/1024)}'`
    ;;
i3so*)
    SWAP=`swap -s`
    vmem=`echo $SWAP|sed -g 's/k//'|awk '{print int(($9 + $11)/1024)}'`
    ;;
rsai*)
    vmem=`lsps -s|grep MB|sed -g s/MB//|awk '{print $1}'`
    ;;
pahp*)
    SWAPTOTAL=`swapinfo -mt|grep total`
    vmem=`swapinfo -mt|grep total|awk '{print $2}'`
    ;;
*)  echo "ERROR: UNKNOWN ARCHIRECTURE"
    ;;
esac

findvmstat()
{
    for dir in /usr/bin /bin /usr/sbin /sbin /usr/local/bin /usr/local/sbin; do
	[ -x "${dir}/vmstat" ] && { echo "${dir}/vmstat"; return 0; }
    done
    return 1
}

#
# Setup default values
#
a_InstDir=$a_definstdir

# loop till we're done
a_damage=$a_n
firsthdr=

[ -n "${TTA_RPM}" ] && a_damage="${a_y}"

while [ "$a_damage" = $a_n ]; do
  # display the summary
  summarystr="$m_summary"
echo $_ss_headlines
echo "$summarystr"
echo $_ss_headlines

  
  if [ "${firsthdr}0" -eq 0 ]; then
      echo "$m_recommend"; echo " "
      firsthdr=1
  else
      echo " "; echo " "
  fi
        
  echo "$m_instdir$a_InstDir"

  # tell them if there's already one installed
  if [ ! -z "$oldver" ]; then
    echo "$m_already$oldver"
  fi

  [ -z "`findvmstat`" ] && echo "${m_cantfindvmstat}"

  # see if they like the current answers
  echo " "
  a_damage="Y"
echo "$p_damage"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_damage [$a_damage] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_damage"   # default
  fi
  case "$_answer" in y|Y|n|N|q|Q)_valid=true;;esac
done
a_damage="$_answer"

# the language can alter the behaviour of tr
a_damage=`echo $a_damage | LANG=C LC_ALL=C tr '[a-z]' '[A-Z]'`


  case "$a_damage" in
  q|Q)
      # Quit setup
      echo " "
echo $_ss_headlines
echo "$h_nochange"
echo $_ss_headlines

      exit 1                          # Go no further; user has quit
      ;;
   y|Y)
      # All is OK
      export a_InstDir
      break ;;
   n|N)
      # User wants to change a setting
      # loop again
      a_damage=$a_n

      echo " "; echo " "
echo $_ss_headlines
echo "$h_instdir"
echo $_ss_headlines

echo "$p_instdir"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  _valid2=false
  _tmp_dirname=""
  echo $N "$q_instdir [$a_InstDir] $C"
  read _dirname
  _tmp_dirname=`echo $N "$_dirname$C" | tr -ds '[\001-\037]@#$%^&*()|{}~?><' '+'`
  if [ "$_tmp_dirname" != "$_dirname" ]
  then
     _valid=false
  elif [ -z "$_dirname" ]
  then
    _dirname="$a_InstDir"   # default
    _valid=true
  fi
  if [ -d "$_dirname" ]
  then
    if [ "$_dirname" = "/" ]
    then
       _valid=false
    else
       _valid=true
       _valid2=true
       a_makeinstdir=$a_yes
    fi
  else
    _valid=true
    a_makeinstdir=$a_yes
  fi
  if [ -f "$_dirname" ]
  then
    echo "$m_isafile"
    _valid=false
  fi
  if [ "$_valid" = "true" ]
  then
     # find out if the first character is a / if not then _dirname is invalid
     case "$_dirname" in
     /*)  _valid=true ;;
     Q|q) _valid=true ;;
     *)   _valid=false
     esac
  fi
  if [ "$_valid" = "true" ]
  then
    while [ $_valid2 = false -a -n "" ]
    do
      echo $N " [$a_makeinstdir] $C"
      read _answer
      if [ -z "$_answer" ]
      then
        _answer="$a_makeinstdir"   # default
      fi
      case "$_answer" in
      [${a_case_yes}]*)
        a_makeinstdir=$s_yes
        _valid2=true
        _valid=true
        ;;
      [${a_case_no}]*)
        a_makeinstdir=$s_no
        _valid=false
        _valid2=true
      esac
    done
  fi
done
a_InstDir="$_dirname"

      insist=""
      case "$a_InstDir" in
          *\!) a_InstDir=`expr "$a_InstDir" : '\(.*\).$'`; insist="t"
      esac
    esac
done
#
# If there's a properties file already, use the contents as overrides
#
# find the latest instance of the package
instver=0
instance=''
# get the package name
shortpkgname=`echo $PKG | sed 's,^\(.*\)\..*$,\1,'`
# get info on instances of this package
pkginfo=`pkginfo $shortpkgname.\* 2>/dev/null`
res=$?
if [ $res -eq 0 ]; then
    pkginfo=`echo "$pkginfo" | awk '{printf (" %s ",$2)}'`
    # return the first one (in case none have INSTVER set)
    instance=`echo $pkginfo | awk '{print $1}'`
    for inst in $pkginfo
    do
	thisinst=`pkgparam $inst INSTVER 2>/dev/null`
	if [ -n "$thisinst" ]; then
	    if [ "$thisinst" -gt "$instver" ]; then
		instver=$thisinst
		instance=$inst
	    fi
	fi
    done
fi

#
# if there is a running tier3loadprobe, stop it
# 
props=""
echo "instance = $instance, instver = $instver" >>$LOGFILE
if [ -n "$instance" ]; then
    [ -z "${TEMDIR}" ] && TEMDIR=`pkgparam $instance INSTDIR`
    echo "TEMDIR = $TEMDIR" >>$LOGFILE
    if [ -n "$TEMDIR" -a -d "$TEMDIR" ]
    then
        PROPS1="$TEMDIR/$a_propsdir/$a_propsfile"
        if [ -f "$PROPS1" ]
        then
            echo "Saved properties file $PROPS1  exists & contains" >>$LOGFILE
            cat $PROPS1 >>$LOGFILE
            props=$PROPS1
        else
            echo "Saved properties file $PROPS1 does not exist" >>$LOGFILE
            PROPS2="$TEMDIR/$a_propsdir_save/$a_propsfile"
            if [ -f "$PROPS2" ]
            then
                echo "Saved properties file $PROPS2 exists & contains" >>$LOGFILE
                cat $PROPS2 >>$LOGFILE
                props=$PROPS2
            else
                echo "Saved properties file $PROPS2 does not exist" >>$LOGFILE
            fi
        fi
    fi
fi
echo "Saved properties in $props" >>$LOGFILE

if [ "$props" != "" ]
then
    valid="false"
    tempport=`grep $portKey $props|cut -d"=" -f2`
    tempvmem=`grep $mVmemKey $props|cut -d"=" -f2`

    echo "$props exists: tempport= $tempport, tempvmem= $tempvmem" >>$LOGFILE
_valid=false
_pp="`echo $tempport|sed 's/[0-9]//g'`"
if [ -z "$_pp" ]
then
    _valid=true
fi
valid=$_valid

    if [ "$valid" = "true" ]
    then
        echo "Setting port to $tempport from $props" >>$LOGFILE
        port=$tempport
    fi
_valid=false
_pp="`echo $tempvmem|sed 's/[0-9]//g'`"
if [ -z "$_pp" ]
then
    _valid=true
fi
valid=$_valid

    if [ "$valid" = "true" ]
    then
        echo "Setting vmem to $tempvmem from $props" >>$LOGFILE
        vmem=$tempvmem
    fi

    # Copy the pre-existing properties file so that we don't scribble over it
    cp $props $a_temppropsfile
    props=$a_temppropsfile
fi

#
# if there is a running tier3loadprobe, stop it
# 
echo "instance = $instance, instver = $instver" >>$LOGFILE
TEM_SCRIPT=tem
if [ -n "$TEMDIR" ]; then
    if [ -x "$TEMDIR/bin/$TEM_SCRIPT" ];
    then
	if [ -n "${TTA_RPM}" ]; then
	    VERSION=`tail -1 "${TEMDIR}/etc/pkg/temversion"`
	else
	    VERSION=`pkgparam $instance VERSION`
	fi
        echo "VERSION is $VERSION">>$LOGFILE
        echo "$stopping_message" >> $LOGFILE
        $TEMDIR/bin/$TEM_SCRIPT stop >>$LOGFILE 2>&1
    else
        # if the tem script has been deleted, get the PID from ps and stop it
        echo "$TEMDIR/bin/$TEM_SCRIPT non-existant or not executable">>$LOGFILE
    fi
fi
# If everything about the package has been deleted, we still want to stop
# any running tier3loadprobe else the new one won't be able to bind to port
# 3579
RUNPID=`ps -e|grep $a_binaryfile|grep -v grep|awk '{print $1}'`
if [ ! -z "$RUNPID" ]
then
    echo "$a_binaryfile still running with pid $RUNPID; killing it">>$LOGFILE
    kill -15 $RUNPID
fi
#%%asknumeric "$p_pmem" "$q_pmem" pmem "$_check_mem_error"
# keep script happy by setting something for pmem
[ "$pmem" -eq 0 ] && pmem=256

echo "$p_vmem"
_valid=false
while [ $_valid = false ]
do
#   echo "N = $N; C = $C"
  echo $N "$q_vmem [$vmem] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$vmem"   # default
  fi
  _pp="`echo $_answer|sed 's/[0-9]//g'`"
  if [ -z "$_pp" ]
  then
      vmem=$_answer
      _valid=true
  else
      echo "$_check_mem_error"
  fi
done


# echo "Running tier3loadprobe will show up here: `ps -e|grep tier3loadprobe|grep -v grep `">>$LOGFILE
cat >$1 << EOF
INSTDIR="$a_InstDir"
PORT=$port
PMEM=$pmem
VMEM=$vmem
SAVEDPROPSFILE="$props"
TTA_TMPDIR="$TTA_TMPDIR"
LOGFILE="$LOGFILE"
LOGDIR="$LOGDIR"
EOF

echo "$p_T3install" 
echo "$p_T3install" >>$LOGFILE
echo "`date`:*** REQUEST ENDS ***" >>$LOGFILE
echo "<--- $who_i_am" >>$LOGFILE
exit $OK
