#!/bin/sh
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# $Id: postinstall.sh,v 1.201.6.1 2006/03/23 16:55:08 billwe Exp $
#
##########################################
##########################################
if [ -f /tmp/pkgadd.debug ]; then
    echo "Debug Output On"
    echo "---------------"
    echo " "
    set
    set -x	
    trace=x export trace
fi


OK=0
FAIL=1

umask 022

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



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


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
}


# 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

# 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
LOGFILE=$LOGDIR/$PKG.log
scriptname=`expr "//$0" : '.*/\(.*\)' `
chmod 644 $LOGFILE >/dev/null 2>&1
echo "---> $scriptname" >>$LOGFILE
chmod 644 $LOGFILE >/dev/null 2>&1
export LOGFILE

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

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

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


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_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
[ -z "${a_RcType}" ] && {
_dummy_="" a_RunLevel="" _dummy_="" _dummy_="" a_RcType="unknown" a_RcFile=""
if [ -d /etc/rc.d/rc2.d -o -d /etc/rc.d/rc3.d ]; then
  a_RcType="rcddir" a_RcFile="/etc/rc.d" _dummy_="/etc/rc.d" _rcbase="/etc/rc.d/rc"
  [ -d /etc/init.d ] && a_RcType="$a_RcType-initd"
elif [ -d /etc/rc2.d -o -d /etc/rc3.d ]; then
  a_RcType="svr4" a_RcFile="/etc" _dummy_="/etc" _rcbase="/etc/rc"
  [ -d /etc/init.d ] && a_RcType="$a_RcType-initd"
elif [ -d /sbin/rc2.d -o -d /sbin/rc3.d ]; then
  a_RcType="sbin" a_RcFile="/sbin" _dummy_="/sbin" _rcbase="/sbin/rc"
elif [ -f /etc/rc.local ]; then
  a_RcType="local" a_RcFile="/etc/rc.local"
elif [ -f /etc/rc.d/rc.local ]; then
  a_RcType="rcd" a_RcFile="/etc/rc.d/rc.local"
elif [ -f /etc/rc.nfs ]; then
  a_RcType="nfs" a_RcFile="/etc/rc.nfs"
elif [ -f /etc/rc ]; then
  a_RcType="basic" a_RcFile="/etc/rc"
fi
case "$a_RcType" in
svr4*|sbin|rcddir*)
  a_RunLevel=`who -r 2>/dev/null | awk '{print $3;}'`
  [ ! -z "$a_RunLevel" ] && {
    case $a_RunLevel in [0-9]);; *) a_RunLevel=`who -r 2>/dev/null | awk '{print $2;}'`;; esac;
  } || a_RunLevel=`/sbin/runlevel 2>/dev/null | awk '{print $2}'`;
  [ -z "$a_RunLevel" ] && a_RunLevel=2 # guess
  _dummy_=1
  for _i in 5 4 3 2 1 S; do
    [ -r ${_rcbase}${_i}.d/S90${PRODUCT_SHORT_FILENAME} ] && { _dummy_=${_i}; break; }
  done
  _dummy_=$a_RcFile/rc$_dummy_.d/_dummy_
  a_RcFile=$a_RcFile/rc$a_RunLevel.d/S90${PRODUCT_SHORT_FILENAME}
esac

export a_RcType a_RcFile a_RunLevel
}

# If we are upgrading from a pre-4.00 installation, a couple of property files
# need tweaking.
case "$UPGRADE" in
3.*) t=${TTA_TMPDIR}/propfile$$; rm -f $t >/dev/null 2>&1
    propfile="$INSTDIR/var/serverconfig/global/array.properties"
    if [ -f "$propfile" ]; then
	key="tarantella.config.array.privilegeduser" value="ttasys"
	(grep -v "^${key}=" "$propfile"; echo "${key}=${value}") >$t
	[ `wc -l <$t` -ge `wc -l <"$propfile"` ] && cp $t "$propfile"
	rm -f $t
    fi
    propfile="$INSTDIR/var/serverconfig/local/server.properties"
    if [ -f "$propfile" ]; then
	key="tarantella.config.server.keyfile" value="%%INSTALLDIR%%/var/info/server.keys"
	(grep -v "^${key}=" "$propfile"; echo "${key}=${value}") >$t
	[ `wc -l <$t` -ge `wc -l <"$propfile"` ] && cp $t "$propfile"
	rm -f $t
    fi
    BEANS="$INSTDIR/var/serverconfig/global/beans" BEANSTPL="$INSTDIR/etc/templates/serverresources/serverconfig/global/beans"
    # Remove obsolete SOAP beans
    rm -f\
	"$BEANSTPL/com.sco.tta.server.soapcommands.Configuration.properties"\
	"$BEANSTPL/com.sco.tta.server.soapcommands.Session.properties"\
	"$BEANSTPL/com.sco.tta.server.soapcommands.Webtop.properties"\
	"$BEANS/com.sco.tta.server.soapcommands.Configuration.properties"\
	"$BEANS/com.sco.tta.server.soapcommands.Session.properties"\
	"$BEANS/com.sco.tta.server.soapcommands.Webtop.properties"\
	>/dev/null 2>&1
esac

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; }
}


# If upgrading from a pre-4.00 installation, set file ownership to ttasys
case "$UPGRADE" in
3.*) 
    _packageclean="${TTA_TMPDIR}/_packageclean$$"
    rm -f ${_packageclean} 2>/dev/null
    find ${INSTDIR} ! \( -group $privgrp -o -perm -4000 -o -perm -2000 \) -print |
	tee -a ${_packageclean} | xargs chgrp $privgrp 2>/dev/null
    find ${INSTDIR}/webserver ! \( -user root -o -user $webservusr -o -perm -4000 -o -perm -2000 \) -print |
	tee -a ${_packageclean} | xargs chown $webservusr 2>/dev/null
    find ${INSTDIR}/bin ${INSTDIR}/etc ${INSTDIR}/var ! \( -user $privusr -o -perm -4000 -o -perm -2000 \) -print |
	tee -a ${_packageclean} | xargs chown $privusr 2>/dev/null
    sort -u ${_packageclean} >${_packageclean}.1; mv ${_packageclean}.1 ${_packageclean}
  [ -z "${TTA_RPM}" ] && {
    _reinstallf="${TTA_TMPDIR}/_reinstallf$$"; _reinstallf1="${_reinstallf}.1"
    rm -f ${_reinstallf} ${_reinstallf1} 2>/dev/null
    pkgchk -l $PKGINST | sed '/^Pathname:/!d;s/^Pathname:[ 	]*//' | sort -u >${_reinstallf}
    comm -12 ${_packageclean} ${_reinstallf} |
    xargs ls -ld |
    awk '{
	mode=substr($1,1,1)
	if (NF==9 && (mode=="d" || mode=="l" || mode=="-")) {
	    owner=$3; group=$4; filename=$9
	    if (mode=="l") mode="s"
	    else if (mode=="-") mode="f"
	    perm=0; for (i=2; i<=10; ++i) {
		perm *= 2
		if (substr($1,i,1)!="-") ++perm 
	    }
	    printf "%s %s %03o %s %s\n", filename, mode, perm, owner, group
	}
    }' |
    tee ${_reinstallf1} |
    installf $PKGINST -
    [ -s ${_reinstallf1} ] && installf -f $PKGINST
    rm -f ${_reinstallf} ${_reinstallf1} 2>/dev/null
  }

    rm -f ${_packageclean} 2>/dev/null

esac

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

cleanup()
{
    trap '' 1 2 3 15
    stopspin
    rm -f $TMP_RC.full $TMP_RC.append $SAVE_FILE $proplist $TTA_TMPDIR/spinning $README_TTA_SETUP 2>/dev/null
    echo "<--- $who_i_am" >>$LOGFILE
}

cleanandexit()
{
    [ -n "${TTA_RPM}" -a "$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
    [ "$1" -eq 0 -a -z "$2" ] && {
_parent=`dirname "${TTA_TMPDIR}"`
_base=`basename "${TTA_TMPDIR}"`
case "${_base}" in
ttainst_[0-9]*) (
    cd ${_parent}
    [ -d "${_base}" ] && [ ! -f "${_base}/SHX" ] && rm -rf "${_base}" 2>/dev/null
)
esac

    }
    exit $1
}

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

TidyScript=""

# oldpkg is now set in setup_dialog
if [ -n "`expr \"$oldpkg\" : '.*\([^ 	]\).*'`" ]; then 
    # Remove the old package ignoring any dependencies
    # This will have to be run after the postinstall
    # because it needs exclusive access to pkgadd
    cat >$ADMINFILE <<EOF
mail=
instance=unique
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
basedir=default
EOF
    # If we are running from a .shx file, let it run the tidy-up script.
    if [ -f $TTA_TMPDIR/UPGRADE.tta ]; then
	TidyScript=$TTA_TMPDIR/UPGRADE.tta
    else
	TidyScript=$TIDY_SCRIPT
    fi
    cat >$TidyScript <<EOF
if [ -f /tmp/pkgadd.debug ]; then
    exec 2>>"$INSTDIR/var/log/pkgrm.log"
    echo "Debug Output On" >&2
    echo "---------------" >&2
    echo " " >&2
    set -x
    trace=x export trace
fi

	oldpkg="$oldpkg"
	msg_sent=f
        hackdir=\`pkgparam $PKGINST DATADIR 2>/dev/null\`
        hackfile=\$hackdir/tmp/.delme
        touch \$hackfile
	for inst in \$oldpkg
	do
	    idir=\`pkgparam \$inst INSTDIR\`
	    case "\$inst" in
		$PKGINST ) ;;
		ttapatch* )
		    if [ "\$msg_sent" = "f" ]; then
			msg="$p_removingoldpkg1"$PRODUCT_SHORT_NAME"$p_removingoldpkg2"; echo "\$msg"; echo "\$msg" >>$LOGFILE
			msg_sent=t
		    fi
_touchfile=\`pkgparam \$inst INSTDIR\`/var/tmp/inst\$inst
touch \$_touchfile >/dev/null 2>&1
_prerm=/var/sadm/pkg/\$inst/install/preremove _posrm=/var/sadm/pkg/\$inst/install/postremove
_t=${TTA_TMPDIR:-/tmp}/pkgrm\$\$
rm -f \$_t >/dev/null 2>&1
[ -f \$_prerm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_prerm >\$_t; cp \$_t \$_prerm; }
[ -f \$_posrm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_posrm >\$_t; cp \$_t \$_posrm; }
rm -f \$_t >/dev/null 2>&1
pkgrm -n -a $ADMINFILE \$inst >>$LOGFILE 2>&1
rm -f \$_touchfile >/dev/null 2>&1

		    # get rid of any saved files
		    rm -rf \$idir/etc/pkg/saved_files \$idir/etc/pkg/\$inst/saved_files >/dev/null 2>&1
		;;
		ttasecure* )
		    if [ "\$msg_sent" = "f" ]; then
			msg="$p_removingoldpkg1"$PRODUCT_SHORT_NAME"$p_removingoldpkg2"; echo "\$msg"; echo "\$msg" >>$LOGFILE
			msg_sent=t
		    fi		    
		    thispkg=\`pkginfo "$PKGINST"\`
		    last=\`pkginfo 'tta.*' | grep -v "\$thispkg" | tail -1 | cut -d' ' -f2\`
		    ddir=\`pkgparam \$last DATADIR 2>/dev/null\`
_touchfile=\`pkgparam \$inst INSTDIR\`/var/tmp/inst\$inst
touch \$_touchfile >/dev/null 2>&1
_prerm=/var/sadm/pkg/\$inst/install/preremove _posrm=/var/sadm/pkg/\$inst/install/postremove
_t=${TTA_TMPDIR:-/tmp}/pkgrm\$\$
rm -f \$_t >/dev/null 2>&1
[ -f \$_prerm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_prerm >\$_t; cp \$_t \$_prerm; }
[ -f \$_posrm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_posrm >\$_t; cp \$_t \$_posrm; }
rm -f \$_t >/dev/null 2>&1
pkgrm -n -a $ADMINFILE \$inst >>$LOGFILE 2>&1
rm -f \$_touchfile >/dev/null 2>&1

		    # are standard connections enabled?
		    if [ -z "\`grep 'tarantella.config.server.security.mechanism=' \$ddir/serverconfig/local/server.properties 2>/dev/null | sed 's/.*=//' | grep std\`" ]; then
			msg="${p_stdconnsdisabled1}""${TSP_FULL_NAME}""${p_stdconnsdisabled2}""${TSP_FULL_NAME}""${p_stdconnsdisabled3}"; echo "\$msg"; echo "\$msg" >>$LOGFILE
		    fi
		;;
		ttawcp* ) 
		    if [ "\$msg_sent" = "f" ]; then
			msg="$p_removingoldpkg1"$PRODUCT_SHORT_NAME"$p_removingoldpkg2"; echo "\$msg"; echo "\$msg" >>$LOGFILE
			msg_sent=t
		    fi
		    thispkg=\`pkginfo "$PKGINST"\`
_touchfile=\`pkgparam \$inst INSTDIR\`/var/tmp/inst\$inst
touch \$_touchfile >/dev/null 2>&1
_prerm=/var/sadm/pkg/\$inst/install/preremove _posrm=/var/sadm/pkg/\$inst/install/postremove
_t=${TTA_TMPDIR:-/tmp}/pkgrm\$\$
rm -f \$_t >/dev/null 2>&1
[ -f \$_prerm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_prerm >\$_t; cp \$_t \$_prerm; }
[ -f \$_posrm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_posrm >\$_t; cp \$_t \$_posrm; }
rm -f \$_t >/dev/null 2>&1
pkgrm -n -a $ADMINFILE \$inst >>$LOGFILE 2>&1
rm -f \$_touchfile >/dev/null 2>&1

		;;
		* )
		    if [ "\$msg_sent" = "f" ]; then
			msg="$p_removingoldpkg1"$PRODUCT_SHORT_NAME"$p_removingoldpkg2"; echo "\$msg"; echo "\$msg" >>$LOGFILE
			msg_sent=t
		    fi
_touchfile=\`pkgparam \$inst INSTDIR\`/var/tmp/inst\$inst
touch \$_touchfile >/dev/null 2>&1
_prerm=/var/sadm/pkg/\$inst/install/preremove _posrm=/var/sadm/pkg/\$inst/install/postremove
_t=${TTA_TMPDIR:-/tmp}/pkgrm\$\$
rm -f \$_t >/dev/null 2>&1
[ -f \$_prerm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_prerm >\$_t; cp \$_t \$_prerm; }
[ -f \$_posrm ] && { sed 's|"/tmp/inst\\\$PKGINST"|"'\$_touchfile'"|' \$_posrm >\$_t; cp \$_t \$_posrm; }
rm -f \$_t >/dev/null 2>&1
pkgrm -n -a $ADMINFILE \$inst >>$LOGFILE 2>&1
rm -f \$_touchfile >/dev/null 2>&1

		    #
		    # Fitz Task 515581:2 - remove old jre directory if empty.
		    # (These were incorrect omitted from the package contents
		    # in version 3.0, and were therefore not removed by pkgrm.)
		    #
		    rmdir \$idir/bin/jre.???? \$idir/bin/jre.???????? >/dev/null 2>&1
                ;;
	    esac
	done
        rm \$hackfile
	rm -f $ADMINFILE >/dev/null 2>&1
EOF
    if [ "${TidyScript}" = "${TTA_TMPDIR}/UPGRADE.tta" ]; then
	TidyScript=""
    else
	# append a TTA_TMPDIR purge operation to the TidyScript
	cat >>${TidyScript} <<EOF
	TTA_TMPDIR=${TTA_TMPDIR}
EOF
	cat >>${TidyScript} <<\EOF
_parent=`dirname "${TTA_TMPDIR}"`
_base=`basename "${TTA_TMPDIR}"`
case "${_base}" in
ttainst_[0-9]*) (
    cd ${_parent}
    [ -d "${_base}" ] && [ ! -f "${_base}/SHX" ] && rm -rf "${_base}" 2>/dev/null
)
esac

EOF
    fi
fi

MkTtaDir -p \
    $INSTDIR/var/tmp \
    $INSTDIR/var/log \
    $INSTDIR/var/password/tier3cache \
    $INSTDIR/var/password/webcache \
    $INSTDIR/var/info \
    $INSTDIR/var/info/tokens \
    $INSTDIR/var/info/licenseuse \
    $INSTDIR/var/preferences \
    $INSTDIR/var/state \
    2>/dev/null

chmod 755 $INSTDIR/var
chmod 711 $INSTDIR/var/log
chmod 770 $INSTDIR/var/tmp
chmod 711 $INSTDIR/var/password/tier3cache

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

#write the datadir file
MkTtaDir -p $INSTDIR/etc/pkg 2>/dev/null
echo $INSTDIR/var > $INSTDIR/etc/pkg/datadir || exit 2
chmod 444 $INSTDIR/etc/pkg/datadir
[ -z "${TTA_RPM}" ] && {
    installf $PKGINST $INSTDIR/etc/pkg/datadir f 444 root sys || exit 2
    installf -f $PKGINST || exit 2
}


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


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


# install our compat file
[ -z "${TTA_RPM}" ] && { 
    removef $PKGINST $INSTDIR/etc/pkg/${PKG}compat | while read rem_file; do 
        [ -f $rem_file ] && rm -f $rem_file
    done
    removef -f $PKGINST
}
cp $REQDIR/${PKG}compat $INSTDIR/etc/pkg/${PKG}compat
chmod 444 $INSTDIR/etc/pkg/${PKG}compat
[ -z "${TTA_RPM}" ] && {
    installf $PKGINST $INSTDIR/etc/pkg/${PKG}compat f 444 root sys || exit 2
    installf -f $PKGINST || exit 2
}


# update previous "depend" files
pkgs=`/bin/ls -d $INSTDIR/etc/pkg/*`
for dir in $pkgs
do
    if [ -f $dir/depend ]; then
shortdir=""
if [ -z "$dir" ]; then
  shortdir=""
else
  shortdir=`expr "//$dir" : '.*/\(.*\)' `
fi

echo $PKGINST > $dir/depend || exit 2
chmod 444 $dir/depend
[ -z "${TTA_RPM}" ] && {
    installf $shortdir $dir/depend f 444 root sys
    installf -f $shortdir
}

    fi
done

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

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

echo "$p_instsuccess1$NAME <$PKG>$p_instsuccess2" | WrapText
echo "
$p_configuring"

##########################################################################
# set up the java environment
#
JHOME=""
if [ -n "`ls -d $INSTDIR/bin/jdk.*_* 2>/dev/null`" ]; then
    # We have at least one JRE in the package: choose the best fit according
    # to the local host arch code.  JRE arch codes may be either 4-char or
    # 8-char codes.
    #
    # Fitz 515581: JRE directory names are now of the form jre.<arch>_<version>
    # eg: jre.i3un_3.01.901 or jre.pahp1100_3.01.901
    #
    BestJRE=`ls -d $INSTDIR/bin/jdk.*_* 2>/dev/null |
    sed "s|\($INSTDIR/bin/jdk\.[^_]*\).*|\1|" |
    awk 'BEGIN {
	arch = "'"$SCOARCH"'"
	arch12 = substr(arch, 1, 2)
	arch34 = substr(arch, 3, 2)
	arch56 = substr(arch, 5, 2)
	arch78 = substr(arch, 7, 2)
    }  
    {  
	x = 0
	if (substr($0, length($0)-8, 1) == ".")
	    jre = substr($0, length($0)-7, 8)
	else
	    jre = substr($0, length($0)-3, 4)
	if (substr(jre, 1, 2) == arch12) {
	    x += 2; if (substr(jre, 3, 2) == arch34) {
		x += 2; if (substr(jre, 5, 2) == arch56) {
		    x += 2; if (substr(jre, 7, 2) == arch78)
			x += 2
		}
	    }
	}
	print x " " jre
    }' | sort +0rn | sed 's/.* //;1q'`
    [ -n "$BestJRE" ] && JHOME=`LANG=C LC_ALL=C ls -d $INSTDIR/bin/jdk.${BestJRE}_*/jre 2>/dev/null | tail -1`
elif [ -x /usr/jdk_base/bin/jre ]; then
    JHOME=/usr/jdk_base
elif [ -x /usr/bin/jre ]; then
    JHOME=/usr
elif [ -x /opt/java/bin/jre ]; then
    JHOME=/opt/java
fi

if [ -z "$JHOME" ]; then
    echo "${m_nojre}"
    cleanandexit 1
fi

# Create a handy link to the jdk directory
rm ${INSTDIR}/bin/jre 2>/dev/null
ln -s ${JHOME} ${INSTDIR}/bin/jre

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

if [ -f "${JHOME}/lib/classes.zip" ]; then
    CLASSPATH="${JHOME}/lib/classes.zip:${JINST}"
    CLASSPATH_EXP='${JHOME}/lib/classes.zip:${JINST}'
elif [ -f "${JHOME}/lib/rt.jar" ]; then
    CLASSPATH="${JHOME}/lib/rt.jar:${JINST}"
    CLASSPATH_EXP='${JHOME}/lib/rt.jar:${JINST}'
else
    CLASSPATH=${JINST}
    CLASSPATH_EXP=${JINST}
fi

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"

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

##########################################################################
# 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).
#
PEERHOST=$a_PeerDNS

MkTtaDir -p $INSTDIR/var/serverconfig/global $INSTDIR/var/serverconfig/local 2>/dev/null
chmod 700 $INSTDIR/var/serverconfig $INSTDIR/var/serverconfig/global $INSTDIR/var/serverconfig/local


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


THREADS_FLAG=native
case "$SCOARCH" in 
i3sc*) THREADS_FLAG=green ;;
esac

##########################################################################
# Create a java environment script that can be sourced by any scripts
# that need it.  Be careful with shell variable usage in this bit ...
#
cat >$INSTDIR/var/javaenv <<!
unset JAVA_HOME
JHOME=$JHOME export JHOME
JINST=$JINST export JINST
JREDIR=\${JHOME}/bin export JREDIR
PATH=\${JREDIR}:\${PATH} export PATH
THREADS_FLAG=$THREADS_FLAG export THREADS_FLAG
if [ -d \$JINST/lib ]; then
    ADD_CLASSPATH="
        \`for newlib in \\\`find \$JINST/lib \( -name '*.jar' -o -name '*.zip' \) -print\\\`; do
            tmp_path="\${newlib}:\$tmp_path"
          done; echo \$tmp_path\`"
fi
CLASSPATH=$CLASSPATH_EXP:\${ADD_CLASSPATH}\$TTA_USER_CLASSPATH export CLASSPATH
jrecommand="jre"
TTAJIT="-nojit"
#JAPAN
##ifdef ja-jp
# == case "$SCOARCH" in
# == i3un*) THR_INCR_CONC="" export THR_INCR_CONC;;
# == rsai*)  TTAJIT=""
# ==         LIBPATH=$JHOME/bin:$JHOME/bin/classic:$INSTDIR/bin/bin
# ==         LANG=ja_JP LC_MESSAGES=C
# ==         export LIBPATH LANG LC_MESSAGES
# ==         jrecommand="java"
# ==         ;;
# == spso*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == i3so*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == i3li*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == axo1*)  TTAJIT=""
# ==         LANG=ja_JP
# ==         export LANG
# ==         if [ -f /tmp/java_classic ]; then
# ==                 jrecommand="java -classic"
# ==         else
# ==                 jrecommand="java"
# ==         fi
# ==         ;;
# == pahp*)  LANG=ja_JP.eucJP LC_ALL=ja_JP.eucJP
# ==         export LANG LC_ALL
# ==         TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == esac
##endif
# Korean
##ifdef ko-kr
# == case "$SCOARCH" in
# == i3un*) THR_INCR_CONC="" export THR_INCR_CONC;;
# == rsai*)  TTAJIT=""
# ==         LIBPATH=$JHOME/bin:$JHOME/bin/classic:$INSTDIR/bin/bin
# ==         LANG=ko_KR LC_MESSAGES=C
# ==         export LIBPATH LANG LC_MESSAGES
# ==         jrecommand="java"
# ==         ;;
# == spso*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == i3so*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == i3li*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == axo1*)  TTAJIT=""
# ==         LANG=ko_KR
# ==         export LANG
# ==         if [ -f /tmp/java_classic ]; then
# ==                 jrecommand="java -classic"
# ==         else
# ==                 jrecommand="java"
# ==         fi
# ==         ;;
# == pahp*)  LANG=ko_KR LC_ALL=ko_KR
# ==         export LANG LC_ALL
# ==         TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == esac
##endif
# Chinese
##ifdef zh-cn
# == case "$SCOARCH" in
# == i3un*) THR_INCR_CONC="" export THR_INCR_CONC;;
# == rsai*)  TTAJIT=""
# ==         LIBPATH=$JHOME/bin:$JHOME/bin/classic:$INSTDIR/bin/bin
# ==         LANG=zh_CN LC_MESSAGES=C
# ==         export LIBPATH LANG LC_MESSAGES
# ==         jrecommand="java"
# ==         ;;
# == spso*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == i3so*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == i3li*)  TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == axo1*)  TTAJIT=""
# ==         LANG=zh_CN
# ==         export LANG
# ==         if [ -f /tmp/java_classic ]; then
# ==                 jrecommand="java -classic"
# ==         else
# ==                 jrecommand="java"
# ==         fi
# ==         ;;
# == pahp*)  LANG=zh_CN LC_ALL=zh_CN
# ==         export LANG LC_ALL
# ==         TTAJIT=""
# ==         jrecommand="java"
# ==         ;;
# == esac
##endif
#English/US
##ifdef en-us
case "$SCOARCH" in
i3un*) 
jrecommand="java"
TTAJIT=""
#THR_INCR_CONC="" export THR_INCR_CONC
;;
rsai*)
# Note that JDK 1.3 only works on AIX 4.3.3.10+
jrecommand="java"
TTAJIT=""
JAVA_SYSTEM_PROPERTIES=\${JAVA_SYSTEM_PROPERTIES}" -Djava.library.path=${INSTDIR}/bin/bin"
;;
i3li*|ppli*) 
jrecommand="java"
TTAJIT=""
;;
spso*) 
jrecommand="java"
TTAJIT=""
;;
i3so*) 
jrecommand="java"
TTAJIT=""
;;
pahp*) 
jrecommand="java"
TTAJIT=""
;;
esac
##endif

gc=""
verbose=""
for o in "\$@"; do
    case "\$o" in
    -v )
	verbose="-verbose";;
    -nojit )
	jrecommand="\$jrecommand -nojit";;
    -D* )
	defines="\$defines \$o";;
    -vgc )
	gc="-verbosegc";;
    esac
done
jrecommand="\$jrecommand \$verbose \$gc"

# Allow JRE to be overridden (for profiling etc.)
jrecommand=\${TTA_USER_JRE:-\$jrecommand}

case "$SCOARCH" in
i3sc*) 
# Cannot increase per-process open file descriptor limit at
# run time, use idtune NOFILES 4096 and idbuild to increase limit.
;;
i3un*)
ulimit -c unlimited >/dev/null 2>&1
ulimit -v unlimited >/dev/null 2>&1
;;
*)
 # We do not want to run out of file descriptors. 4096 per process is 
 # the minimum acceptable value.
 req_fds=4096
 n_fds=\`ulimit -n\`
 case \$n_fds in
   unlimited ) n_fds=\$req_fds;;
   [0-9]* );;
   * ) n_fds=0;; # ???
 esac
 [  \$n_fds -lt \$req_fds ] && ulimit -SHn \$req_fds >/dev/null 2>&1
esac

!
chgrp $privgrp $INSTDIR/var/javaenv
chown $privusr $INSTDIR/var/javaenv

##########################################################################
# base64 mangle dirnames
#
chmod 500 $REQDIR/ttab64conv
if [ -n "$jive_PkgInst" ]; then
    Base=$jive_DataDir
    toconvert="ens password/tier3cache password/webcache preferences"
    check=`ls -d $Base/ens/o\=* 2>/dev/null`
    oldversion=$UPGRADE
else
    Base="$INSTDIR/var"
    toconvert="ens password/tier3cache password/webcache preferences"
    check=`ls -d $Base/ens/o\=* 2>/dev/null`
    oldversion=$UPGRADE
fi

# If there is an ens database already present, back it up before continuing.
if [ -d "$Base/ens" -o -d "$Base/_ens" ]; then
(
    enspath="$Base/ens"
    [ ! -d "$enspath" ] && enspath="$Base/_ens"
    cd $Base
    ensdir=`basename $enspath`
    backupens=$ensdir.$oldversion
    if [ -d $backupens ]; then
      suffix=0
      while [ -d $backupens.$suffix ]; do
          suffix=`expr $suffix + 1`
      done
      backupens=$backupens.$suffix
    fi
    mv $ensdir $backupens
    MkTtaDir -p $enspath
    cd $backupens
    find . -print | cpio -pdum "$enspath" 2>/dev/null
    cd $Base
    # backup EII _dns if there is one
    if [ -d _dns ]; then
	backupdns=_dns.$oldversion
	if [ -d $backupdns ]; then
	    suffix=0
	    while [ -d $backupdns.$suffix ]; do
		suffix=`expr $suffix + 1`
	    done
	    backupdns=$backupdns.$suffix
	fi
	mv _dns $backupdns
	MkTtaDir -p _dns
	cd $backupdns
	tar cf - . | (cd ../_dns; tar xf -)
    fi

)
fi

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

##########################################################################
# Setup script arguments.
#
old_args='' jive_args=''
if [ -n "$jive_PkgInst" ]; then
    old_args=" --oldinstdir $jive_InstDir --olddatadir $jive_DataDir --oldversion $jive_Build --oldpkginst $jive_PkgInst"
fi
TTABINDIR=$INSTDIR/bin export TTABINDIR
export INST_RCFILE INST_RCSTRING

##########################################################################
# Run setup scripts.
#
xflag=""
[ "$trace" = "x" ] && xflag="-x"

for script in\
    templates\
    files_rename\
    dbcreate\
    extended_templates\
    config\
    printing\
    sysadmin\
    loadprobe_config
do
    echo "${m_runningscript1}${script}${m_runningscript2}" | tee -a $LOGFILE

##ifdef ja-jp
# ==     # JAPAN
# ==     SCOARCH=`$INSTDIR/bin/scoarch`
# ==     case "$SCOARCH" in
# ==     spso*) LANG=ja LC_ALL=ja; export LANG LC_ALL ;;
# ==     i3so*) LANG=ja LC_ALL=ja; export LANG LC_ALL ;;
# ==     i3li*) LANG=ja_JP LC_ALL=ja_JP; export LANG LC_ALL ;;
# ==     rsai*) LANG=ja_JP LC_MESSAGES=C; export LANG LC_MESSAGES ;;
# ==     axo1*) LANG=ja_JP LC_ALL=ja_JP; export LANG LC_ALL ;;
# ==     pahp*) LANG=ja_JP.eucJP LC_ALL=ja_JP.eucJP; export LANG LC_ALL ;;
# ==     *) ;;
# ==     esac
##endif

    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"
    res=$?
    if [ $res -ne 0 ]; then
	echo "${m_scriptfail}${res}" | tee -a $LOGFILE
	echo "${l_seesetuplog1}${INSTDIR}/var/log/setup.log${l_seesetuplog2}" >>$LOGFILE
	cleanandexit 1 		# if one of the setup scripts failed
    else
	echo "${m_scriptok}" | tee -a $LOGFILE
    fi
done

##########################################################################
# Build document TOCs
#
PATH=$INSTDIR/bin/bin:$PATH export PATH
##ifdef en-us
sh $xflag $INSTDIR/var/docroot/help/scripts/make_tocs.sh
##endif

##########################################################################
# Make sure all directories are world-readable (apart from some specific
# exclusions).
#
find $INSTDIR -type d -print | 
    egrep -v "^$INSTDIR/var/(ens|log|password|print|spool|serverresources|serverconfig|tmp)" |
    egrep -v "^$INSTDIR/webserver/.*/logs\$" |
    xargs chmod ugo+rx
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 755 $INSTDIR/etc/pkg/$PKGINST 2>/dev/null
chmod 644 $INSTDIR/etc/pkg/$PKGINST/extras 2>/dev/null

# ensure other files are safe
find $INSTDIR/var/serverconfig -type f -print | xargs chmod 600
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 444 $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
find ${INSTDIR}/var \( ! -group $privgrp \) -print | xargs chgrp $privgrp 2>/dev/null
find ${INSTDIR}/var \( ! -user  $privusr \) -print | xargs chown $privusr 2>/dev/null

##########################################################################
# Install license numbers that the user entered during request phase
#
[ -n "$LKEYS" ] && $TTABINDIR/tarantella license add $LKEYS >>${INSTDIR}/var/log/setup.log 2>&1

##########################################################################
# Install license keys that were upgraded by the TTA web site, and then
# remove the old ones.
echo "Adding upgraded keys" >>${INSTDIR}/var/log/setup.log
[ -n "$NEWKEYS" ] && $TTABINDIR/tarantella license add $NEWKEYS >>${INSTDIR}/var/log/setup.log 2>&1
echo "Removing old keys" >>${INSTDIR}/var/log/setup.log
[ -n "$OLDKEYS" ] && $TTABINDIR/tarantella license remove $OLDKEYS >>${INSTDIR}/var/log/setup.log 2>&1


##########################################################################
# 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
# if we are upgrading, try to find the HTTP port that was used in the old installation
# so that we can reuse it
PREVIOUS_HTTPD_CONF="${INSTDIR}/webserver/apache/${PREVIOUS_apache}/conf/httpd.conf"
[ "${a_httpport}" = "%%oldhttpport" -a -n "${UPGRADE}" -a -r "${PREVIOUS_HTTPD_CONF}" ] && {
    a_httpport=`awk '$1=="Port"{print $2}' "${PREVIOUS_HTTPD_CONF}"`
    case "${a_httpport}" in
    [0-9][0-9]*) ;;	# OK
    *)	PREVIOUS_HTTPD_CONF="${INSTDIR}/webserver/apache/${PREVIOUS_apache}/conf.${UPGRADE}/httpd.conf"
    	[ -r "${PREVIOUS_HTTPD_CONF}" ] && a_httpport=`awk '$1=="Port"{print $2}' "${PREVIOUS_HTTPD_CONF}"`
	case "${a_httpport}" in
	[0-9][0-9]*) ;;	# OK
	*)	a_httpport=80	# oh well, we tried ... just set it to 80 and hope for the best
	esac
    esac
}
nextfreeport() {
    [ -z "$1" ] && return
    [ "$1" -lt 1 ] && return
    port=$1
    probe="$INSTDIR/bin/bin/ttahostprobe localhost:"
    while [ "${port}" -eq "${a_httpport}" -o "`${probe}${port}`" = "y" ]; do
	port=`expr $port + 1`
    done
    echo $port
}
OLD_WEBSERVER_CONFIG="${TTA_TMPDIR}/OLD_WEBSERVER_CONFIG"; rm -f ${OLD_WEBSERVER_CONFIG} 2>/dev/null
if [ -f ${INSTDIR}/webserver/config_install.sh ]; then
(
    echo "${m_configscript}${l_config_webservices}"
    . $INSTDIR/var/javaenv
    JAVA_HOME=`dirname $JHOME` export JAVA_HOME
    cd ${INSTDIR}/webserver
    # Find out which apache/tomcat versions we should be using
    for package in apache tomcat; do
    (
	cd ${package}
	if [ `ls | wc -l` -eq 1 ]; then
	    # only one version present
	    ls >"${INSTDIR}/var/info/${package}version"
	else
	    # more than one version - check which one belongs to this package
	    for version in *; do
		if [ -z "${TTA_RPM}" ]; then
		    [ -n "`pkgchk -l -p \"${INSTDIR}/webserver/${package}/${version}\" \"${PKGINST}\"`" ] && echo "${version}" >"${INSTDIR}/var/info/${package}version"
		elif [ -s "${INSTDIR}/etc/pkg/tta/rpm.pkg" ]; then
		    rpm_p=`cat ${INSTDIR}/etc/pkg/tta/rpm.pkg`
		    [ -n "`rpm -ql \"${rpm_p}\" | grep \"/webserver/${package}/${version}/\" | sed 1q`" ] && echo "${version}" >"${INSTDIR}/var/info/${package}version"
		fi
	    done
	fi
    )
    done
    A_VER=`cat "${INSTDIR}/var/info/apacheversion"`
    T_VER=`cat "${INSTDIR}/var/info/tomcatversion"`
    HTTP_PORT=$a_httpport
    HTTPS_PORT=443
    WARP_PORT=`nextfreeport 8009`
    SHUTDOWN_PORT=`nextfreeport 8005`
    REDEPLOY=""; [ -n "$UPGRADE" ] && REDEPLOY="--redeploy"
    # config_install will move the lw archives; prepare to remove them from the package database
    ls ${INSTDIR}/var/docroot/java/ttalw*.* >${TTA_TMPDIR}/lwarchives 2>/dev/null
    [ -z "${TTA_RPM}" ] && [ -s ${TTA_TMPDIR}/lwarchives ] && removef $PKGINST `cat ${TTA_TMPDIR}/lwarchives` >/dev/null 2>&1
    ./config_install.sh --ttaversion `echo ${PRODUCT_VERSION_FULL}|tr -d .` \
	${REDEPLOY} $A_VER $T_VER $HTTP_PORT $HTTPS_PORT \
	$WARP_PORT $SHUTDOWN_PORT $PEERPORT $webservusr $privgrp \
	${INSTDIR} >> $LOGFILE
    ret=$?
    # if the lw archives have gone, remove them from the package database
    [ -z "${TTA_RPM}" ] && [ -s ${TTA_TMPDIR}/lwarchives ] && removef -f $PKGINST >/dev/null 2>&1
    if [ $ret -ne 0 ]; then
	echo "${m_scriptfail}${?}" | tee -a $LOGFILE
	echo "${l_seesetuplog1}${INSTDIR}/var/log/setup.log${l_seesetuplog2}" >>$LOGFILE
	cleanandexit 1
    fi
    # if upgrading, compare webserver config with saved config from upgraded version
    if [ -n "$UPGRADE" -a -n "$PREVIOUS_apache" -a -n "$PREVIOUS_tomcat" -a "$A_VER" != "$PREVIOUS_apache" -a "$T_VER" != "$PREVIOUS_tomcat" ]; then
	# Apache and Tomcat versions have changed.  Leave old config intact.
	echo "\
${p_oldwebserverconfig1}
${p_oldwebserverconfig2}

   ${INSTDIR}/webserver/apache/${PREVIOUS_apache}
   ${INSTDIR}/webserver/tomcat/${PREVIOUS_tomcat}

${p_oldwebserverconfig4}

   ${INSTDIR}/webserver/apache/${A_VER}
   ${INSTDIR}/webserver/tomcat/${T_VER}\
" >${OLD_WEBSERVER_CONFIG} 
    elif [ -n "$UPGRADE" -a -n "$PREVIOUS_apache" -a -n "$PREVIOUS_tomcat" ]; then
	# Find all saved config dirs from the old (upgraded) installation
	find "$INSTDIR/webserver/apache/${PREVIOUS_apache}" "$INSTDIR/webserver/tomcat/${PREVIOUS_tomcat}" \
	    -type d -name "*.$UPGRADE" -print 2>/dev/null |
	while read CONFDIR_OLD; do
	    case "$CONFDIR_OLD" in
	    */webserver/apache/*) VER_NEW=${A_VER} ;;
	    */webserver/tomcat/*) VER_NEW=${T_VER} ;;
	    esac
	    CONFDIR_NEW=`echo "$CONFDIR_OLD" | sed "s|\($INSTDIR/webserver/[^/]*\)/[^/]*/\(.*\)|\1/${VER_NEW}/\2|;s|\.${UPGRADE}\$||"`
	    if [ -d "$CONFDIR_OLD" -a -d "$CONFDIR_NEW" ]; then
	    (
		cd "$CONFDIR_OLD"
		find . ! -type d -print | while read CONFFILE; do
		    if cmp -s "$CONFFILE" "$CONFDIR_NEW/$CONFFILE"; then
			# File exists identically in old and new config dirs.
			# Delete the old copy.
			rm -f "$CONFFILE" >/dev/null 2>&1
		    elif [ ! -f "$CONFDIR_NEW/$CONFFILE" ]; then
			# File exists only in old config dir.
			# Copy to the new dir and delete the old copy.
			echo "$CONFFILE" | cpio -pdum "$CONFDIR_NEW" 2>/dev/null
			rm -f "$CONFFILE" >/dev/null 2>&1
		    else
			# File exists in both config dirs, but there are differences.
			: No action necessary
		    fi
		done
	    )
	    fi
	done
	# Cleanup saved config by purging empty dirs, then report upgraded files
	find "$INSTDIR/webserver" -depth -type d -print | egrep "/[^/]*\.${UPGRADE}" | xargs rmdir 2>/dev/null
	find "$INSTDIR/webserver" -print | egrep "/[^/]*\.${UPGRADE}" >>${INSTDIR}/var/log/webservercustomized.list
	find "$INSTDIR/webserver" -type d -name "*.$UPGRADE" -print >${TTA_TMPDIR}/,wsc 2>/dev/null
	[ -s "${TTA_TMPDIR}/,wsc" ] && (
	    echo "\
${p_oldwebserverconfig1}
${p_oldwebserverconfig3}
"
	    sed 's/^/   /' "${TTA_TMPDIR}/,wsc"
	    echo "
${p_oldwebserverconfig4}

   ${INSTDIR}/webserver/apache/${A_VER}
   ${INSTDIR}/webserver/tomcat/${T_VER}"
	) >${OLD_WEBSERVER_CONFIG}
	rm -f "${TTA_TMPDIR}/,wsc" 2>/dev/null
    fi
    if [ -n "${PKGINST}" -a -n "${jive_PkgInst}" -a "${PKGINST}" != "${jive_PkgInst}" ]; then
	FilesInPackage()
	{
	    [ -z "${TTA_RPM}" ] && {
		pkgchk -l $1 | egrep "^Pathname:[ 	]*${INSTDIR}/$2" | sed 's/^Pathname:[ 	]*//' | sort -u
	    }
	}
	# Find and remove any superseded Java archives from the old (upgraded) package.
	LastSuffix=`echo "${ARCHIVE_SUFFIX}" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ ZABCDEFGHIJKLMNOPQRSTUVWXY`
	FilesInPackage "${jive_PkgInst}" | LANG=C LC_ALL=C egrep '/tta[^/]*[A-'${LastSuffix}'][^/]*\.(cab|jar|zip)$' >${TTA_TMPDIR}/oldarchives
	if [ -s ${TTA_TMPDIR}/oldarchives ]; then
	    [ -z "${TTA_RPM}" ] && removef ${jive_PkgInst} `cat ${TTA_TMPDIR}/oldarchives` >/dev/null 2>&1
	    rm -f `cat ${TTA_TMPDIR}/oldarchives` 2>/dev/null
	    [ -z "${TTA_RPM}" ] && removef -f ${jive_PkgInst} >/dev/null 2>&1
	fi
	rm -f ${TTA_TMPDIR}/oldarchives 2>/dev/null
	# Find and remove any superseded Java archives that don't belong to a package
	# - ie files that may have been copied to a different part of the tree.
	find "${INSTDIR}" -name "tta*[A-${LastSuffix}]*.cab" -o \
	                  -name "tta*[A-${LastSuffix}]*.jar" -o \
	                  -name "tta*[A-${LastSuffix}]*.zip" -print >${TTA_TMPDIR}/oldarchives
	[ -s ${TTA_TMPDIR}/oldarchives ] && rm -f `cat ${TTA_TMPDIR}/oldarchives` 2>/dev/null
	rm -f ${TTA_TMPDIR}/oldarchives 2>/dev/null
	# Ensure all files in the webserver tree that belong to the old (upgraded) package,
	# also belong to the new package.  That will prevent them being removed by the pkgrm
	# that is run at the end of the installation.
	pattern="webserver/(_DoesntExist_"
	[ "$A_VER" = "$PREVIOUS_apache" ] && pattern="${pattern}|apache"
	[ "$T_VER" = "$PREVIOUS_tomcat" ] && pattern="${pattern}|tomcat"
	pattern="${pattern})/"
	FilesInPackage "${jive_PkgInst}" "${pattern}" >${TTA_TMPDIR}/pkglist.0
	FilesInPackage "${PKGINST}"      "${pattern}" >${TTA_TMPDIR}/pkglist.1
	comm -23 ${TTA_TMPDIR}/pkglist.[01] >${TTA_TMPDIR}/pkglist.2
	# If the apache and/or tomcat directories have changed between SGD versions, we may have
	# saved some old config in the old directory.  We need to make the top level old apache
	# and/or tomcat directory belong to the current package instance to avoid them being
	# removed by an over-zealous pkgrm of the old SGD package.
	[ "$A_VER" != "$PREVIOUS_apache" ] && echo "${INSTDIR}/webserver/apache/${PREVIOUS_apache}" >>${TTA_TMPDIR}/pkglist.2
	[ "$T_VER" != "$PREVIOUS_tomcat" ] && echo "${INSTDIR}/webserver/tomcat/${PREVIOUS_tomcat}" >>${TTA_TMPDIR}/pkglist.2
	[ -z "${TTA_RPM}" -a -s "${TTA_TMPDIR}/pkglist.2" ] && {
	    installf "$PKGINST" - <${TTA_TMPDIR}/pkglist.2
	    installf -f "$PKGINST"
	}
	rm -f ${TTA_TMPDIR}/pkglist.[012]
    fi
    $TTABINDIR/tarantella webserver stop >/dev/null 2>&1
    sleep 10
    # Generate and store web server auth credentials
    t=${TMPDIR:-/tmp}/ttatomcat$$
    rm -f $t >/dev/null 2>&1
    tomcatDir=`ls -d ${INSTDIR}/webserver/tomcat/* | tail -1`
    tomcatUsers="${tomcatDir}/conf/tomcat-users.xml"
    trustedUsername="sgd_trusted_user"
    trustedPassword=`${TTABINDIR}/bin/ttarandom --keysize 20 --printable`
    (
	cd "${tomcatDir}/webapps/sgd/WEB-INF/classes"
	encodedAuth=`${JHOME}/bin/java com/tarantella/tta/webservices/client/views/SgdPasswd --encode "${trustedUsername}:${trustedPassword}"`
	cd "com/tarantella/tta/webservices/client/views"
	grep -v "^sgdaccess=" Resources.properties >$t 2>/dev/null
	cp $t Resources.properties
	echo "sgdaccess=${encodedAuth}" >>Resources.properties
    )
    # Build CLASSPATH for RealmBase command
    CP=".:catalina.jar"
    for EXTRA1 in `ls ${INSTDIR}/bin/java/commons-logging*.jar 2>/dev/null`; do
	[ -r "${EXTRA1}" ] && CP="${CP}:${EXTRA1}"
    done
    digestedPassword=`cd ${tomcatDir}/server/lib;${JHOME}/bin/java -cp "${CP}" org.apache.catalina.realm.RealmBase -a SHA "${trustedPassword}" | sed 's/.*://'`
    sed "s/%%proxyuser/${trustedUsername}/;s/%%proxypass/${digestedPassword}/" "${tomcatUsers}" >$t 2>/dev/null
    cp $t "${tomcatUsers}"
    rm -f $t >/dev/null 2>&1
    [ -n "$UPGRADE" ] && rm -rf "${tomcatDir}/work/Standalone/localhost/sgd" >/dev/null 2>&1
    $TTABINDIR/tarantella webserver start --quiet >> $LOGFILE
    if [ $? -ne 0 ]; then
	echo "${m_scriptfail}${?}" | tee -a $LOGFILE
	echo "${l_seesetuplog1}${INSTDIR}/var/log/setup.log${l_seesetuplog2}" >>$LOGFILE
	cleanandexit 1
    else
	echo "${m_scriptok}" | tee -a $LOGFILE
    fi
    attrname="login-thirdparty-superusers"
    superusers=`${TTABINDIR}/tarantella config list --${attrname} 2>/dev/null | sed "s/${attrname}: *//"`
    if [ -z "${superusers}" -o "${superusers}" = "\"\"" -o "${superusers}" = "not found" ]; then
	${TTABINDIR}/tarantella config edit --${attrname} ${trustedUsername} >/dev/null 2>&1
    else
	case "${superusers}" in
	${trustedUsername} | ${trustedUsername},* | *,${trustedUsername},* | *,${trustedUsername})
	    # name is already configured
	    ;;
	*)  # add name to the list
	    ${TTABINDIR}/tarantella config edit --${attrname} `echo "${superusers}" | tr ',' ' '` "${trustedUsername}" >/dev/null 2>&1
	esac
    fi

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

    # Sort out webserver file/directory permissions.
    # Default permissions are:
    # 	directories:	rwxr-x--- / root / ttaserv
    #	files:		rw-r----- / root / ttaserv
    # unless specifically overridden below
    PERMS="${TTA_TMPDIR}/perms$$"; rm -f ${PERMS} 2>/dev/null

    find ${INSTDIR}/webserver ! \( -type l -o -user root \) -print | tee -a ${PERMS} | xargs chown root
    find ${INSTDIR}/webserver ! \( -type l -o -group $privgrp \) -print | tee -a ${PERMS} | xargs chgrp $privgrp
    find ${INSTDIR}/webserver ! \( -type l -o -type d -o -perm 640 \) -print | tee -a ${PERMS} | xargs chmod 640
    find ${INSTDIR}/webserver -type d ! -perm 750 -print | tee -a ${PERMS} | xargs chmod 750

    # 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

    # 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
	find $LOGDIRS ! \( -type d -o -perm 660 \) -print | tee -a ${PERMS} | xargs chmod 660
	find $LOGDIRS ! -user $webservusr -print | tee -a ${PERMS} | xargs chown $webservusr
    fi

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

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

    sort -u ${PERMS} >${PERMS}.1; mv ${PERMS}.1 ${PERMS}
  [ -z "${TTA_RPM}" ] && {
    _reinstallf="${TTA_TMPDIR}/_reinstallf$$"; _reinstallf1="${_reinstallf}.1"
    rm -f ${_reinstallf} ${_reinstallf1} 2>/dev/null
    pkgchk -l ${PKGINST} | sed '/^Pathname:/!d;s/^Pathname:[ 	]*//' | sort -u >${_reinstallf}
    comm -12 ${PERMS} ${_reinstallf} |
    xargs ls -ld |
    awk '{
	mode=substr($1,1,1)
	if (NF==9 && (mode=="d" || mode=="l" || mode=="-")) {
	    owner=$3; group=$4; filename=$9
	    if (mode=="l") mode="s"
	    else if (mode=="-") mode="f"
	    perm=0; for (i=2; i<=10; ++i) {
		perm *= 2
		if (substr($1,i,1)!="-") ++perm 
	    }
	    printf "%s %s %03o %s %s\n", filename, mode, perm, owner, group
	}
    }' |
    tee ${_reinstallf1} |
    installf ${PKGINST} -
    [ -s ${_reinstallf1} ] && installf -f ${PKGINST}
    rm -f ${_reinstallf} ${_reinstallf1} 2>/dev/null
  }

    rm -f ${PERMS} 2>/dev/null
)
fi
 
##########################################################################
# 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
)
 
##########################################################################
# Make sure scottawindowsapplication.properties (if it exists) belongs to
# this package instance to avoid problems on upgrade.
#
winprops="$INSTDIR/var/serverconfig/local/scottawindowsapplication.properties"
if [ -f "${winprops}" ]; then
    [ -z "${TTA_RPM}" ] && {
	installf $PKGINST "${winprops}"
	installf -f $PKGINST
    }
fi

# Run sub-package postinstall scripts if present
for POSTI in "${TTABINDIR}/scripts/install_scripts/pip/postinstall"\
             "${TTABINDIR}/scripts/install_scripts/wcp/postinstall"\
             "${TTABINDIR}/scripts/install_scripts/tsp/postinstall"; do
    [ -z "${TTA_RPM}" ] && [ -f "${POSTI}" ] && [ -n "`pkgchk -l -p \"${POSTI}\" \"${PKGINST}\" 2>/dev/null`" ] && sh $xflag "${POSTI}"
done

#stop the spinner
stopspin

##########################################################################
# User information.
#
# Output to a readme if there is one.
if [ -z "$READMEFILE" ]; then READMEFILE=$TTA_TMPDIR/README.tta; fi
if [ -f "$READMEFILE" ]; then exec >$READMEFILE; fi

# Copy the setup README (if any) to the main README
cat "${OLD_WEBSERVER_CONFIG}" 2>/dev/null; rm -f "${OLD_WEBSERVER_CONFIG}" 2>/dev/null

host_url="http://$a_PeerDNS"
case $a_httpport in
    80 ) ;;
    *  ) host_url="${host_url}:$a_httpport" ;;
esac

upgfrom=0
echo $_ss_headlines
echo "$h_docs"
echo $_ss_headlines

cat "${README_TTA_SETUP}" 2>/dev/null; rm -f "${README_TTA_SETUP}" 2>/dev/null
echo "${p_docintro}${p_url1}${host_url}/${p_url2}"

if [ -n "$UPGRADE" ] ; then
    #Log in as admin message
    upgfrom=`echo "$UPGRADE" | cut -d'.' -f1`
    echo "${p_login_upg}"
else
    #Log in as root message
    echo "${p_login_new}"
fi

echo "${p_webtop}${p_license}"


##ifdef ja-jp
# == # JAPAN (addjusting for the proper fonts)
# == case "$SCOARCH" in
# == rsai*)  # AIX-J
# ==         [ -d /usr/lib/X11/fonts/JP ] && {
# ==                 [ -f /usr/lib/X11/fonts/JP/fonts.dir ] || (
# ==                         cd /usr/lib/X11/fonts/JP
# ==                         /usr/bin/X11/mkfontdir
# ==                 )
# ==                 $INSTDIR/bin/tarantella config edit --xpe-fontpath /usr/lib/X11/fonts,/usr/lib/X11/fonts/JP,%%INSTALLDIR%%/etc/fonts/misc,%%INSTALLDIR%%/etc/fonts/75dpi,%%INSTALLDIR%%/etc/fonts/100dpi,%%INSTALLDIR%%/etc/fonts/Speedo,%%INSTALLDIR%%/etc/fonts/Type1,%%INSTALLDIR%%/etc/fonts/hp
# ==         }
# ==         ;;
# == spso*|i3so*)  # Solaris
# ==         [ -d /usr/openwin/lib/locale/ja/X11/fonts/75dpi ] && {
# ==                 $INSTDIR/bin/tarantella config edit --xpe-fontpath /usr/openwin/lib/locale/ja/X11/fonts/75dpi,%%INSTALLDIR%%/etc/fonts/misc,%%INSTALLDIR%%/etc/fonts/75dpi,%%INSTALLDIR%%/etc/fonts/100dpi,%%INSTALLDIR%%/etc/fonts/Speedo,%%INSTALLDIR%%/etc/fonts/Type1,%%INSTALLDIR%%/etc/fonts/hp
# ==         }
# ==         ;;
# == axo1*)  # Tru64
# ==         [ -d /usr/i18n/lib/X11/fonts/decwin/100dpi -a -d /usr/i18n/lib/X11/fonts/decwin/75dpi ] && {
# ==                 $INSTDIR/bin/tarantella config edit --xpe-fontpath %%INSTALLDIR%%/etc/fonts/misc,%%INSTALLDIR%%/etc/fonts/75dpi,%%INSTALLDIR%%/etc/fonts/100dpi,%%INSTALLDIR%%/etc/fonts/Speedo,%%INSTALLDIR%%/etc/fonts/Type1,%%INSTALLDIR%%/etc/fonts/hp,/usr/i18n/lib/X11/fonts/decwin/100dpi,/usr/i18n/lib/X11/fonts/decwin/75dpi,/usr/lib/X11/fonts/misc
# ==         }
# ==         [ -f /usr/lib/font.properties.ja ] && {
# ==                 mv /usr/lib/font.properties.ja /usr/lib/0,font.properties.ja
# ==                 echo "ATTENTION: \c"
# ==                 echo "font.properties.ja in /usr/lib/ was renamed to 0,font.properties.ja"
# ==         }
# ==         ;;
# == pahp*)  # HP-UX
# ==         [ -d /usr/lib/X11/fonts/hp_japanese/100dpi ] && {
# ==                 $INSTDIR/bin/tarantella config edit --xpe-fontpath %%INSTALLDIR%%/etc/fonts/misc,%%INSTALLDIR%%/etc/fonts/75dpi,%%INSTALLDIR%%/etc/fonts/100dpi,%%INSTALLDIR%%/etc/fonts/Speedo,%%INSTALLDIR%%/etc/fonts/Type1,%%INSTALLDIR%%/etc/fonts/hp,/usr/lib/X11/fonts/hp_japanese/100dpi
# ==         }
# ==         ;;
# == *)      # Other
# ==         ;;
# == esac
##endif

    
rm -f $INSTDIR/var/log/upgraded.files
show_upgrade_readme=0
files_saved=0
files_saved=`grep -v "Not upgrading" $INSTDIR/var/log/customized.list 2>/dev/null | wc -l`
[ -f $INSTDIR/var/log/customizedchanged.list ] && files_not_upgraded=`wc -l $INSTDIR/var/log/customizedchanged.list | awk '{print $1}'` || files_not_upgraded=0

if [ "$upgfrom" -gt 1 ];then
    if [ $files_saved -gt 0 -o $files_not_upgraded -gt 0 ]; then
        echo "${p_customizedfiles1}${jive_Build}${p_customizedfiles1b}${jive_Build}${p_customizedfiles1c} $files_saved" > $INSTDIR/var/log/upgraded.files
        echo "$p_customizedfiles2" >> $INSTDIR/var/log/upgraded.files
        echo "$p_customizedchanged1 $files_not_upgraded" >> $INSTDIR/var/log/upgraded.files
        if [ $files_not_upgraded -gt 0 ]; then
            echo "${p_customizedchanged2}${jive_Build}" >> $INSTDIR/var/log/upgraded.files
            echo "$p_customizedchanged2b" >> $INSTDIR/var/log/upgraded.files
        fi
        # it's assumed that if they've changed the java, then they'll have changed one or more
        # themes to make use of it ... file is created by preinstall.sh
        if [ -f $TTA_TMPDIR/docrootjava.log ]; then
            mv $TTA_TMPDIR/docrootjava.log $INSTDIR/var/log
            echo "$p_docrootjava $INSTDIR/var/log/docrootjava.log" >> $INSTDIR/var/log/upgraded.files
        fi
        show_upgrade_readme=1
    fi
    if [ -s $INSTDIR/var/log/expectcustomized.list ]; then
	echo "${p_expectupgrade1}${jive_Build}${p_expectupgrade1b}${jive_Build}" >>$INSTDIR/var/log/upgraded.files
	sed 's;.*/\(.*\)$; - \1;' $INSTDIR/var/log/expectcustomized.list >>$INSTDIR/var/log/upgraded.files
	echo "${p_expectupgrade2}${jive_Build}${p_expectupgrade2b}" >>$INSTDIR/var/log/upgraded.files
	show_upgrade_readme=1
    fi
fi

[ $show_upgrade_readme -eq 1 ] && echo "$p_readme_upgrade"

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

    _packageclean="${TTA_TMPDIR}/_packageclean$$"
    rm -f ${_packageclean} 2>/dev/null
    find ${INSTDIR} ! \( -group $privgrp -o -perm -4000 -o -perm -2000 \) -print |
	tee -a ${_packageclean} | xargs chgrp $privgrp 2>/dev/null
    find ${INSTDIR}/webserver ! \( -user root -o -user $webservusr -o -perm -4000 -o -perm -2000 \) -print |
	tee -a ${_packageclean} | xargs chown $webservusr 2>/dev/null
    find ${INSTDIR}/bin ${INSTDIR}/etc ${INSTDIR}/var ! \( -user $privusr -o -perm -4000 -o -perm -2000 \) -print |
	tee -a ${_packageclean} | xargs chown $privusr 2>/dev/null
    sort -u ${_packageclean} >${_packageclean}.1; mv ${_packageclean}.1 ${_packageclean}
  [ -z "${TTA_RPM}" ] && {
    _reinstallf="${TTA_TMPDIR}/_reinstallf$$"; _reinstallf1="${_reinstallf}.1"
    rm -f ${_reinstallf} ${_reinstallf1} 2>/dev/null
    pkgchk -l $PKGINST | sed '/^Pathname:/!d;s/^Pathname:[ 	]*//' | sort -u >${_reinstallf}
    comm -12 ${_packageclean} ${_reinstallf} |
    xargs ls -ld |
    awk '{
	mode=substr($1,1,1)
	if (NF==9 && (mode=="d" || mode=="l" || mode=="-")) {
	    owner=$3; group=$4; filename=$9
	    if (mode=="l") mode="s"
	    else if (mode=="-") mode="f"
	    perm=0; for (i=2; i<=10; ++i) {
		perm *= 2
		if (substr($1,i,1)!="-") ++perm 
	    }
	    printf "%s %s %03o %s %s\n", filename, mode, perm, owner, group
	}
    }' |
    tee ${_reinstallf1} |
    installf $PKGINST -
    [ -s ${_reinstallf1} ] && installf -f $PKGINST
    rm -f ${_reinstallf} ${_reinstallf1} 2>/dev/null
  }

    rm -f ${_packageclean} 2>/dev/null


# If we have done an upgrade, sort out licenses
[ -z "${DATADIR}" ] && DATADIR="${INSTDIR}/var"
LICTMPDIR="${DATADIR}/tmp"; [ -z "${TTA_RPM}" ] && LICTMPDIR="${TTA_TMPDIR}"
[ -s "${LICTMPDIR}/licdata.keys" -a -n "${UPGRADE}" -a -s "${LICTMPDIR}/licdata.maint" -a -s "${LICTMPDIR}/licdata.users" ] && {
    rm -f "${LICTMPDIR}/licdata.newkeys" 2>/dev/null
    while read lickey; do
	[ -z "${lickey}" ] && continue
	maint_or_rtu='' newlickey=''
	# component code 37=maintenance, 38=right_to_upgrade
	if [ -n "`${INSTDIR}/bin/bin/ttalicinfo \"${lickey}\" 2>/dev/null | grep '^TTALIC_COMPONENTS=.*3[78]'`" ]; then
	    maint_or_rtu='t'
	else
	    newlickey=`${INSTDIR}/bin/bin/ttalicinfo "${lickey}" --tta2sun 2>/dev/null | sed '/^TTALIC_V3KEY=/!d;s/.*=//'`
	fi
	[ -n "${maint_or_rtu}" -o -n "${newlickey}" ] && ${INSTDIR}/bin/tarantella license remove "${lickey}"
	[ -n "${newlickey}" ] && echo "${INSTDIR}/bin/tarantella license add \"${newlickey}\"" >>"${LICTMPDIR}/licdata.newkeys"
    done <"${LICTMPDIR}/licdata.keys"
    [ -s "${LICTMPDIR}/licdata.newkeys" ] && /bin/sh "${LICTMPDIR}/licdata.newkeys"
}

# Start the server if we are running from a raw pkgadd
# (ie neither an RPM nor an SHX file).
[ -z "${TTA_RPM}" ] && [ ! -f "${TTA_TMPDIR}/SHX" ] && {
    if [ -f "${TidyScript}" ]; then
	# we are about to run a script to purge old (upgraded) packages,
	# so piggy-back the server start commands on to the end of it
	echo "${INSTDIR}/bin/tarantella webserver start >>${INSTDIR}/var/log/start.log 2>&1" >>"${TidyScript}"
	echo "${INSTDIR}/bin/tarantella start >>${INSTDIR}/var/log/start.log 2>&1" >>"${TidyScript}"
    else
	# Start the server - detach the start command, to stop it from 
	# being killed when this postinstall script terminates.
	# No need to start the webserver, since it should already be running
	# following the webserver configuration phase earlier.
	nohup ${INSTDIR}/bin/tarantella start >>${INSTDIR}/var/log/start.log 2>&1 &
	echo "${l_waitforservertostart}"
    fi
}

# If we are not running from a .shx file, run the tidy-up script now.
KEEP_TMPDIR=""
[ -z "${TTA_RPM}" -a -f "${TidyScript}" ] && {
    nohup /bin/sh "${TidyScript}" >/dev/null 2>&1 &
    KEEP_TMPDIR="t"
    echo "${l_waitforservertostart_upg}"
}
# NB  TidyScript deletes TTA_TMPDIR.  Don't do anything after this point
#     that requires TTA_TMPDIR to be present.

cleanandexit ${OK} ${KEEP_TMPDIR}


