#!/bin/sh
#
#  Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# $Id: request.sh,v 1.111.6.1 2006/01/04 17:10:36 billwe Exp $
#
##########################################
##########################################
if [ -f /tmp/pkgadd.debug ]; then
    echo "Debug Output On"
    echo "---------------"
    echo " "
    set
    set -x	
    trace=x export trace
fi

[ ! -f /tmp/tta_noreqcd ] && cd /tmp

OK=0
FAIL=1
CANT_DOWNGRADE=2
CANT_UPGRADE=3

# version number in the licenses:
LICVERSION=3

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




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


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

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

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

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

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

if [ -z "$REQDIR" ]
then
    echo "<--- $who_i_am"
    exit $FAIL
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]*\)/.*;\1;p'`
if [ ! -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

[ ! -f /tmp/tta_noreqcd ] && cd ${TTA_TMPDIR}
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


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


# spinning cursor function
spin ()
{
  [ ! -d "$TTA_TMPDIR" ] && return
  B="\b"
  char1='|'
  char2='/'
  char3='-'
  char4='\\'
  sleepcmd="sleep"
  sleeptime="1"
  if [ -z "$sleeptime" ]; then sleeptime=1; fi
  if [ -z "$sleepcmd" ]; then sleeptime=""; fi

  if [ -f $TTA_TMPDIR/spinning ]; then
      #stop an existining spinner
      rm -f $TTA_TMPDIR/spinning >/dev/null 2>&1
      $sleepcmd $sleeptime
  fi
  touch $TTA_TMPDIR/spinning >/dev/null 2>&1
  set +x
  while [ -f $TTA_TMPDIR/spinning ]
  do
     if [ -f $TTA_TMPDIR/spinning ]; then
	echo $N $char1"$B$C"
     else
	break
     fi
     $sleepcmd $sleeptime
     if [ -f $TTA_TMPDIR/spinning ]; then
	echo $N $char2"$B$C"
     else
	break
     fi
     $sleepcmd $sleeptime
     if [ -f $TTA_TMPDIR/spinning ]; then
	echo $N $char3"$B$C"
     else
	break
     fi
     $sleepcmd $sleeptime
     if [ -f $TTA_TMPDIR/spinning ]; then
	echo $N $char4"$B$C"
      else
	break
      fi
     $sleepcmd $sleeptime
  done
  rm -f $TTA_TMPDIR/spinning >/dev/null 2>&1
  echo $N " $B$C"
}


NUSERS="0"
THISKEY=""
NEWUSERS="0"

# licinfo binary
LICINFO="$TTA_TMPDIR/licinfo"
cp ${REQDIR}/licinfo $LICINFO >/dev/null 2>&1
chmod 700 $LICINFO >/dev/null 2>&1

# ttaregisterinfo binary
TTAREGISTERINFO="$TTA_TMPDIR/ttaregisterinfo"
cp ${REQDIR}/ttaregisterinfo $TTAREGISTERINFO >/dev/null 2>&1
chmod 700 $TTAREGISTERINFO >/dev/null 2>&1

# ttahostname binary
TTAHOSTNAME="$TTA_TMPDIR/ttahostname"
cp ${REQDIR}/ttahostname $TTAHOSTNAME >/dev/null 2>&1
chmod 700 $TTAHOSTNAME >/dev/null 2>&1

TTAHOSTPROBE="$TTA_TMPDIR/ttahostprobe"
cp ${REQDIR}/ttahostprobe $TTAHOSTPROBE >/dev/null 2>&1
chmod 700 $TTAHOSTPROBE >/dev/null 2>&1

# setup response file
SAVE_FILE=$TTA_TMPDIR/tta.resp
chmod 777 $SAVE_FILE >/dev/null 2>&1

# how much space do we need
if [ -f $TTA_TMPDIR/tta.size ]; then
    kb_needed=`cat $TTA_TMPDIR/tta.size`
    res=$?; if [ $res -ne 0 ]; then kb_needed=0; fi
else
    # pkg is being installed by pkgadd not from
    # the shx file - let pkgadd deal with this
    kb_needed=0
fi

cleanup()
{
    trap '' 1 2 3 15
    echo "<--- $who_i_am" >>$LOGFILE
    rm -f $LICINFO >/dev/null 2>&1
    rm -f $TTAHOSTPROBE $TTAHOSTNAME >/dev/null 2>&1
    rm -f $SAVE_FILE $TTA_TMPDIR/spinning > /dev/null 2>&1
    rm -f $TTAREGISTERINFO >/dev/null 2>&1
    return 0
}

cleanandexit()
{
    cleanup
    exit $1
}

trap 'cleanup; exit 1' 1 2 3 15

getLicenseInfo()
{
if [ -f /tmp/pkgadd.debug ]; then
    echo "Debug Output On"
    echo "---------------"
    echo " "
    set
    set -x	
    trace=x export trace
fi

    #
    #-------------------------------------------------------------------------
    # Check user has read and agreed to the license file.
    #-------------------------------------------------------------------------
    #

    skip_license=

    awkscript='{v="true"; if (NF!=1 || $1!~/^['${a_case_yes}${a_case_no}${a_case_readlicense}'].*$/) v="false"; print v}'

    a_chooselicop=$a_readlicense
    echo " "; echo " "
echo $_ss_headlines
echo "$h_licenseagreement"
echo $_ss_headlines

echo "$p_chooselicop"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_chooselicop [$a_chooselicop] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_chooselicop"   # default
  fi
   _valid=`echo "$_answer" | sed 's/[, ][, ]*/ /g' | awk "$awkscript"` 
done
a_chooselicop="$_answer"


    case $a_chooselicop in
	[${a_case_no}]* ) return 3 ;;
	[${a_case_yes}]* ) skip_license=true ;;
    esac

    if [ -z "$skip_license" ]
    then
	licfile=${REQDIR}/${PKGLANG}_license
	if [ -f "$licfile" ]; then
	    # Select a pager to view the license agreement.  Use pg if available
	    # (usually everywhere except Linux) - otherwise use less or more.
	    # /usr/bin/pg is on some Linuxen, but its not a pager! fitz/514246
	    #
	    # Do all this in a subshell so that we don't have to bother with
	    # resetting environment variables at the end.
	    #
	(
	    PAGER=""
	    case $MACHINEARCH in
	    i3li*|ppli*) pagers="less:more" ;;
	    * ) pagers="pg:less:more" ;;
	    esac
	    savedifs="$IFS"
	    IFS=:
	    for cmd in $pagers; do
		[ -n "$PAGER" ] && break
		for d in $PATH; do
		    [ -x $d/$cmd ] && { PAGER=$d/$cmd; break; }
		done
	    done
	    IFS="$savedifs"

	    # We should make sure we're in raw mode if we're using less
	    oldstty="" oldless="$LESS"
	    case "$PAGER" in 
	    */less)
		oldstty=`stty -g`
                stty -icanon
		LESS="-f -Es -P \"$less_prompt\"" export LESS
		;;
	    */pg)
		PAGER="$PAGER -p \"$pg_prompt\""
		;;
	    esac

pg=${PAGER:-more}
##ifdef ja-jp
# == eval LANG=ja_JP LC_ALL=ja_JP $pg $licfile
##endif
##ifdef ko-kr
# == eval LANG=ko_KR LC_ALL=ko_KR $pg $licfile
##endif
##ifdef zh-cn
# == eval LANG=zh_CN LC_ALL=zh_CN $pg $licfile
##endif
##ifdef en-us
eval $pg $licfile
##endif


	    # reset stty if we changed it
	    [ -n "$oldstty" ] && stty $oldstty
	)
	else
	    echo "Error - cannot find license file."
	    return 1
	fi

	a_license=$a_no 
	echo " "; echo " "
echo $_ss_headlines
echo "$h_licenseagreement"
echo $_ss_headlines

echo ""
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_license [$a_license] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_license"   # default
  fi
  case "$_answer" in
    [${a_case_yes}]* )
	    _answer=$s_yes
	    _valid=true
	    ;;
    [${a_case_no}]* )
	    _answer=$s_no
	    _valid=true
	    ;;
  esac
done
a_license="$_answer"


	case $a_license in
	    [${a_case_no}]* ) return 3 ;;
	esac
    fi

    return $OK
}

# INSERT-DIALOG-FILE-HERE (do not remove or change this line!)
# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
# $Id: setup,v 1.25 2005/10/05 14:08:12 billwe Exp $
# Messages for install scripts

lf_usage="<options>
 where <options> are:
   --instdir     Installation directory
   --datadir     Data directory
   --version     Current product version
   --oldinstdir  Old installation directory
   --olddatadir  Old data directory
   --oldversion  Old version
   --savefile    File containing shell variables
"

m_noprtinstallscript="Printing configuration failed (prtinstall script not found)"

####
# Install type

q_installtype="Installation type"

a_upgrade="upgrade"
a_downgrade="downgrade"
a_reinstall="reinstall"
a_install="install"

l_dupgrade="
NOTE: a datastore has been detected in the installation directory,
 although the previous installation of $PRODUCT_SHORT_NAME has been removed.
 Setup will preserve it in directories with a "
l_dupgrade1=" suffix.
 If you made any modifications that you want to preserve, you can copy
 these modifications manually after this installation has completed."

l_unsupported_upgrade="
NOTE: you are attempting an unsupported upgrade. You may continue
 at your own risk. Alternatively, quit this installation and uninstall
 your existing version before installing this version."
####
# Install directory 

h_instdir="$PRODUCT_SHORT_NAME installation directory"
p_instdir="\
$PRODUCT_SHORT_NAME uses a single directory for all its code and other
static and dynamic components. Which directory would you like to use?"
p_instdir_insist="

If you really want to use the directory you have chosen, enter its name
followed by a "!" character."
q_instdir="Installation directory"
q_or_q=" (or Q to quit)"
a_base_definstdir="/opt"
a_definstdir="/opt/tarantella"
a_definstdir2="/usr/tarantella"

m_isafile="Sorry, but that's a file, not a directory. Please try again."

e_nospace1="IMPORTANT:  There is not enough space in "
e_nospace2="Please name a directory with at least "
e_nospace3="K free."
e_carryonregardless="... attempting installation anyway, by user request."

e_instdircontents1="
You are attempting to install $PRODUCT_SHORT_NAME in "
e_instdircontents2=",
which contains the following unexpected files:

"

####
# Peer dns name

h_peerdns="Peer (internal) DNS name"
p_peerdns="\
Each computer on the network may have a number of DNS names.  In
$PRODUCT_SHORT_NAME, the peer DNS name is the name by which this host
is known to others within your firewall, if you have one. If you're
using an array of multiple $PRODUCT_SHORT_NAME servers, this is the
name used by other servers in the array to identify this server."
q_peerdns="Peer DNS name"

####
# For setup summary heading
l_summary="Setting up $PRODUCT_FULL_NAME"
l_recommend="$PRODUCT_SHORT_NAME Setup recommends you use the following settings:"

###
# HTTP port for TWS

e_httpport_inuse="
IMPORTANT: The default HTTP port is in use. Either stop the process
that is using this port, or select a different port when prompted."
q_httpport="HTTP port"
p_httpinuse="[already in use]"
p_httpnotinuse="[not currently in use]"
h_httpport="HTTP port"
p_httpport="$PRODUCT_SHORT_NAME includes a web server. You need to choose the TCP port
on which the web server listens for HTTP (unencrypted) connections.
The default port for HTTP is 80/tcp.

You must choose an unused TCP port for installation to complete."
s_port="
Port "
s_inuse=" is currently in use."

####
# Add entry to rc file
h_restart="Start $PRODUCT_SHORT_NAME on reboot"
p_restart="\
Would you like the $PRODUCT_SHORT_NAME server to start automatically
when the UNIX host reboots?"
q_restart="Start $PRODUCT_SHORT_NAME on reboot?"
p_runlevel="\
At which run level should the $PRODUCT_SHORT_NAME server start?
Choose from:
  S - Single-user mode
  1 - Administration mode
  2 - Multi-user mode
  3 - Remote file-sharing mode
  4 - Alternative remote file-sharing mode
"
p_currun="Current run level is: "
p_instrun="Currently installed at run level: "
q_runlevel="Run level"
q_mkrcdir="The correct run-level directory doesn't exist. Do you want to create
it?"
v_runlevel="The valid run levels are S, 1, 2, 3 and 4."

####
# Is it OK type stuff

p_damage="\
Are these settings OK?
  Y - Yes, install using these settings
  N - No, tell me more about the options and let me change the settings
  Q - Quit now"

q_damage="OK to use these settings?"

h_nochange="$PRODUCT_FULL_NAME Setup made no changes to your system."

####
# Yes and No

a_case_y="yY"
a_case_yes="yY"
s_yes="yes"

a_case_n="nN"
a_case_no="nN"
s_no="no"

a_case_q="qQ"
a_case_quit="qQ"
s_quit="quit"

a_case_a="aA"

a_y="y"
a_n="n"
a_q="q"
a_a="a"

a_yes="yes"
a_no="no"
a_quit="quit"
a_auto="auto"

####
# Add entry to crontab to archive logs
h_checkpoint="Archive logs every week"
p_checkpoint="\
Would you like the $PRODUCT_SHORT_NAME server to archive its log files
every week?"
q_checkpoint="Archive logs every week?"
p_checktime="
At what time should the archive occur?
Type a number between 0 (midnight) and 23 (11pm).
"
q_checktime="Archive time"
q_hours=":00 hours"
v_badnumber="Please type a number from 0 to 23, inclusive."
p_checkday="
On what day should the archive occur?
Type a number between 0 (Sunday) and 6 (Saturday).
"
q_checkday="Archive day"
v_badday="Please type a number from 0 to 6, inclusive."

l_sun="Sunday"
l_mon="Monday"
l_tue="Tuesday"
l_wed="Wednesday"
l_thu="Thursday"
l_fri="Friday"
l_sat="Saturday"


####
# Licensing
h_licmode="License mode"
h_addlicense2="$PRODUCT_SHORT_NAME has two license modes. Each mode gives you different
rights for using the $PRODUCT_SHORT_NAME software."
q_addlicense="License key"
p_addlicense="If you'd like to add a new license key, type it now.
Press [Return] to continue without adding any license keys."
l_evalmsg="This $PRODUCT_SHORT_NAME server is licensed for a 30-day evaluation only."
l_fullmsg="This $PRODUCT_SHORT_NAME server is licensed for "
l_fullmsg2=" concurrent users."

l_chtoeval="Changing to Evaluation license mode."
l_chtofull="Changing to Fully Licensed mode."
l_alreadyfull="This server is already fully licensed."
l_nochange="No changes have been made."
l_addinglic="Adding "
l_addinglic2="-user license..."
l_unlimited="unlimited"

l_mode_full="Full"
l_mode_full2=" concurrent users)"
l_mode_eval="Evaluation"
l_mode_eval2=" (30-day limit)"

l_currentmode="Current license mode: "
l_nolicenses="No $PRODUCT_SHORT_NAME license keys are currently installed."
l_somelicenses="$PRODUCT_SHORT_NAME license keys:"

l_licnum="License key '"
l_notalic="' is not a $PRODUCT_SHORT_NAME server license key."
l_licinstalled="' has already been installed."

l_romalic1="The following license key(s) are installed in your "
l_romalic2="
(version "
l_romalic3=") installation:"
l_romalic4="If you want the new "
l_romalic5=" installation to be similarly
licensed you must obtain new license keys. See:
   http://www.tarantella.com/buy"


###############
# License upgrade

# When upgrading from pre-3.00
lupg_oldvernotsupported="\
Setup does not support license key upgrades from this version.
To upgrade your license keys you must contact Tarantella.
"

# If you are upgrading from 3.30+ to 3.30+ (e.g. 3.30 to 3.40). The
# user may have already run license info, but they may have forgotten
# to do so. Not shown when upgrading pre-3.30 installation - see
# lupg_pre330needsmessage
lupg_pwantinfo="
To upgrade, you must first supply your current license key information to
the Tarantella Customer Central web site as a signed message.

You can generate this message at any time using \"tarantella license info\".
Do you want Setup to generate this message for you?

  Y - Yes, generate the message now
  N - No, I have already supplied this information to Customer Central
  Q - Quit now
"
# Question to go with the above prompt.
lupg_qwantinfo="Generate the license information message?"

# Printed before the license info equivalent message
lupg_preinfo=""

# Printed after the license info equivalent message.
lupg_postinfo="
Please supply this information to Customer Central.

Go to https://custcentral.tarantella.com, register if necessary,
and paste the above (including BEGIN and END lines) into
the appropriate form.
"

# Explanation about the whole license upgrade thing, shown when upgrading 
# from pre - 3.30
lupg_pre330needsmessage="
The product version you're installing needs new license keys.

To upgrade your existing license keys to the new version, you supply
your current license information, as the following signed message, to
the Tarantella Customer Central web site. If you are eligible for
upgrade, the web site will supply a new signed message containing
the new license keys."

# Prompt for asking for the return message
lupg_pretmessage="\
Paste the signed message containing your new license keys, exactly as
supplied by Customer Central. Include the BEGIN and END lines, but
do not include any information before the BEGIN line or after the END line.

Press Ctrl-D (EOF) when finished, or type quit on a line on its own
to cancel the upgrade.
"


# sh case-match for "quit". Mustn't match a line that is part of a
# return message, so q* is probably too dangerous.
a_lupg_case_quit="[qQ][uU][iI][tT]"

# Return message from web site validated OK (i.e. signature check is fine)
lupg_retmessageok="License message validated OK."

# Return message from web site not OK
lupg_retmessagebad="
Setup couldn't validate the license message. Please check that you're
pasting no information before the BEGIN line or after the END line.
"

# If we support it, we have accepted a message of just license keys
# not wrapped in a message
lupg_acceptingkeys="Recognized and accepted list of license keys"

####
# Misc

###
#ask whether to create Tarantella printer
h_prtsetup="Create $PRODUCT_SHORT_NAME printer"
p_prtsetup="\
Would you like Setup to recreate the $PRODUCT_SHORT_NAME printer,
as if this was a new installation?

Note: This won't have any effect unless the $PRODUCT_SHORT_NAME printer
configuration has been changed since installation.  If any changes
have been made, this option will restore the installation configuration."

q_prtsetup="Create $PRODUCT_SHORT_NAME printer?"

l_serverbeans_start="Setting up server beans..."
l_serverbeans_end="...finished setting up server beans."

l_serverbeans_start_templates="Setting up server beans (templates)..."
l_serverbeans_end_templates="...finished setting up server beans (templates)."

l_running_ug_script="running upgrade script:"
l_ug_script_failed="...failed"
l_ug_script_ok="...success"
l_ug_script_inapplicable="...not applicable to this upgrade"

q_pkguninst="
Setup will uninstall the following packages:"
q_pkguninst2="
You should install newer versions when Setup has finished."

l_missing="Missing file: "
#!/bin/sh
# $Id: setup_dialog.sh,v 1.40.6.1 2006/03/23 16:55:08 billwe Exp $
#  Copyright 2006 Sun Microsystems, Inc. All rights reserved.
#
# Prompt user for setup information.
##########################################

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




preInstalledKeys=`cat $TTA_TMPDIR/LICENSE.tta 2>/dev/null`
apachePort=80
if [ -s "$TTA_TMPDIR/apachePort" ]; then
    [ `wc -l <"$TTA_TMPDIR/apachePort"` -eq 1 ] && apachePort=`cat "$TTA_TMPDIR/apachePort"`
fi

GetLicInfo()
{
    # Work out the current license mode and message to display.  Note that
    # all relevant shell variables (including messages) have to be passed in
    # as arguments to this function.  This is horrible, but it's better than
    # having the content of this function replicated in three places as used
    # to be the case.

    l_mode_eval="$1"; 	[ -n "$1" ] && shift
    l_mode_eval2="$1"; 	[ -n "$1" ] && shift
    l_mode_full="$1"; 	[ -n "$1" ] && shift
    l_mode_full2="$1"; 	[ -n "$1" ] && shift
    l_unlimited="$1"; 	[ -n "$1" ] && shift
    LICINFO="$1"; 	[ -n "$1" ] && shift
    PRODUCT_LICENSE_PRODUCT_CODE="$1"; [ -n "$1" ] && shift
    a_LicenseKeys="$1"

    licmode=$l_mode_eval
    NUSERS=0
    unlimitedUserCount=f
    for key in $preInstalledKeys $a_LicenseKeys; do
	output=`$LICINFO $key`
	if [ -n "$output" ]; then
	    unset TTALIC_USERS
	    eval $output
            NEWUSERS=0
            thiskeyunlimited=f
	    for component in $TTALIC_COMPONENT_NAMES ; do
		if [ "$component" = "base" ]; then
		    if [ -n "${TTALIC_USERS}" ]; then
			[ "${TTALIC_USERS}0" -eq 0 ] && thiskeyunlimited=t
                        NEWUSERS=$TTALIC_USERS
		    fi
		fi
                if [ "$component" = "maintenance" ]; then
                    # we assume base comes before maintenace.
                    # maintenance licenses do not license base..
                    NEWUSERS=0
                    thiskeyunlimited=f
                fi
	    done
            if [ "${thiskeyunlimited}" = "t" ] ; then 
                NEWUSERS=0 NUSERS=0
                unlimitedUserCount=t
            fi
            if [ "${NEWUSERS}" != "0" -a -z "$TTALIC_EXPIRE_TIME" ]; then
		licmode=$l_mode_full
	    fi
            NUSERS=`expr $NUSERS + $NEWUSERS` 
	    unset TTALIC_USERS
	fi
    done
    [ "$unlimitedUserCount" = "t" ] && NUSERS="${l_unlimited}"
    case $licmode in
    $l_mode_eval) echo "${NUSERS}%${licmode}%${l_mode_eval2}" ;;
    *) 		  echo "${NUSERS}%${licmode}% (${NUSERS}${l_mode_full2}"
    esac
    return 0
}

setup_dialog()
{
    case "$trace" in
    x) set -x
    esac

    OK=0
    FAIL=1
    CANT_DOWNGRADE=2
    CANT_UPGRADE=3
    QUIT=4

# 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


    NUSERS="0"
    THISKEY=""
    NEWUSERS="0"
    LICINFO=":"
    RESPONSE="/dev/null"
    NEEDKB="0"
    INSTTYPE=""
    INSTMSG=""
    GOTSTRINGS=""
    INST_RCFILE="S90$PRODUCT_SHORT_FILENAME"
    INST_RCSTRING="##$PRODUCT_SHORT_FILENAME##"

    ASK_INSTDIR=""
    ASK_PEERDNS=""
    ASK_LICMODE=""
    ASK_CRONTAB=""
    ASK_RC=""
    ASK_WEBTOP=""
    ASK_PRINTER=""
    ASK_HTTPPORT=""

    a_LicenseKeys=""

    ######################################################################
    # command-line args
    #
    while [ -n "$1" ]; do
	case "$1" in
	--licinfo) 	LICINFO="$2"; shift; shift;;
	--response) 	RESPONSE="$2"; shift; shift;;
	--needkb) 	NEEDKB="$2"; shift; shift;;
	--gotstrings) 	GOTSTRINGS="t"; shift;;
	--ask_instdir) 	ASK_INSTDIR="t"; shift;;
	--ask_peerdns)  ASK_PEERDNS="$2"; shift; shift;;
	--ask_licmode) 	ASK_LICMODE="t"; shift;;
	--ask_crontab) 	ASK_CRONTAB="t"; shift;;
	--ask_rc) 	ASK_RC="t"; shift;;
	--ask_webtop) 	ASK_WEBTOP="t"; shift;;
	--ask_printer) 	ASK_PRINTER="t"; shift;;
	--ask_httpport)	ASK_HTTPPORT="t"; shift;;
	*)  echo "$0: unknown arg '$1'" >&2
	    return $FAIL
	esac
    done

    if [ -z "$GOTSTRINGS" ]; then
lf_nomessages="No message files installed for LANG="
l_langdefault="Attempting to use default English (en-us) messages"
l_langunknown="Unrecognized \$LANG: "
l_langunset="\$LANG is not set."
lf_langright="Please check the \$LANG variable is correct."
l_langsetto="\$LANG is currently set to: "
l_gottheselangs="Message files are installed for the following languages:"
l_usinglang="Using messages in"
[ -z "$LANG" ] && LANG="C"

TTALANG=$LANG
case "$TTALANG" in
C)  TTALANG="en-us"
    ;;
[a-z][a-z]_[A-Z][A-Z])
    # convert LANG format from ab_CD to ab-cd
    TTALANG=`echo "$TTALANG" | LANG=C LC_ALL=C tr '[A-Z]_' '[a-z]-'`
esac

if [ ! -d $TTALANG -o -z "$TTALANG" ]; then
  [ ! -z "$TTALANG" ] && posslangs=`find . -type d -name "$TTALANG*" -print 2>/dev/null | sed 's;.*\/.*\/.*;;'`

  [ -z "$posslangs" ] && posslangs=`find . -type d -name '[a-z][a-z]-[a-z][a-z]*' -print 2>/dev/null | sed 's;.*\/.*\/.*;;'`

  nposslangs=`echo $posslangs | wc -w`
  if [ "$nposslangs" -gt 1 ]; then
    case "$TTALANG" in
      ??* )
            echo "${lf_nomessages}${LANG}" #!!!
	    echo "$lf_langright"
            ;;
      "" )
           echo "$l_langunset"
           ;;
      * )
          TTALANG=en-us
          echo "$l_langunknown $LANG"
          echo "$l_langdefault"
          ;;
    esac
    echo "$l_gottheselangs"
    tmpTTALANG=$TTALANG
    for a_lang in $posslangs; do
      output=`echo $a_lang | sed -e 's/.*\///'`
      echo "  $output"
      if [ -f $output/common -o -f ../$output/common ]; then
	[ "$tmpTTALANG" != "en-us" ] && tmpTTALANG=$output
      fi
    done
    [ "$TTALANG" = "$tmpTTALANG" ] && TTALANG=en-us || TTALANG=$tmpTTALANG	
    echo "$l_usinglang $TTALANG"
  elif [ "$nposslangs" -eq 1 ]; then
    TTALANG=`echo $posslangs | sed -e 's/.*\///'`
  else
    echo "$lf_reinst"
    exit 5
  fi
fi

TTAMSG=`pwd`/$TTALANG
export TTAMSG TTALANG
if [ $trace ]; then echo "   trace: Language dir = $TTAMSG"; fi

if [ -f $TTAMSG/common ]; then
  . $TTAMSG/common
else
  _lang=`basename $TTAMSG`
  _parent=`dirname $TTAMSG`
  _parent=`dirname $_parent`
  if [ -f $_parent/$_lang/common ]; then
    . $_parent/$_lang/common
  else
    echo "Unable to open message file: $TTAMSG/common"
    exit 1
  fi
fi
if [ -f $TTAMSG/setup ]; then
  . $TTAMSG/setup
else
  echo "Unable to open message file: $TTAMSG/setup"
  exit 1
fi

    fi

    get_httpport() { 
    ##################################################################
    # HTTP port for TWS
    #
    if [ -n "$ASK_HTTPPORT" ]; then
        case `$TTA_TMPDIR/ttahostprobe localhost:$a_httpport` in
           "n" ) prompt_httpport=${p_httpport} ;;
            * ) prompt_httpport="${p_httpport}${s_port}${a_httpport}/tcp${s_inuse}" ;;
        esac
echo; echo
echo $_ss_headlines
echo "$h_httpport"
echo $_ss_headlines

echo "$prompt_httpport"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_httpport [$a_httpport] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_httpport"   # default
  fi
  _valid=`case $_answer in [1-9]*) if expr $_answer + 1 >/dev/null 2>/dev/null; then echo true; else echo false; fi;; *) echo false;; esac`
done
a_httpport="$_answer"

        while [ "`$TTA_TMPDIR/ttahostprobe localhost:$a_httpport`" = "y" ]; do
            httpprompt="${s_port}${a_httpport}/tcp${s_inuse}"
echo "$httpprompt"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_httpport [$a_httpport] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_httpport"   # default
  fi
  _valid=`case $_answer in [1-9]*) if expr $_answer + 1 >/dev/null 2>/dev/null; then echo true; else echo false; fi;; *) echo false;; esac`
done
a_httpport="$_answer"

        done
    fi
    }

    a_Archive=$a_yes a_cron="" a_CronDay="" a_CronTime=""
a_cron="" a_CronDay="" a_CronTime=""
_cronline=`crontab -l 2>/dev/null | grep "/tarantella archive" | grep -v '^#'`
if [ -n "$_cronline" ]; then
  a_cron=t
  a_CronDay=`echo "$_cronline" | awk '{print $5}'`
  a_CronTime=`echo "$_cronline" | awk '{print $2}'`
fi

    [ -z "$a_CronTime" ] && a_CronTime=03
    [ -z "$a_CronDay" ] && a_CronDay=0
    a_CronTimeOrig=$a_CronTime
    a_CronDayOrig=$a_CronDay

    if [ "$PRODUCT_TTA_PKGNAME" = "ttajive" ]; then
	a_definstdir=`echo "$a_definstdir" | sed 's/tarantella/ttajive/'`
	a_definstdir2=`echo "$a_definstdir2" | sed 's/tarantella/ttajive/'`
    fi

    a_InstDir=$a_definstdir2
    # try to find sensible default directory
    if [ -d "$a_definstdir" ]; then
case "$MACHINEARCH" in
i3li*|ppli*)  _kflag=kP;;
*)	_kflag=k
esac

_path=$a_definstdir
while [ ! -d "$_path" ]; do
if [ -z "$_path" ]; then
  _path=.
else
  _path=`expr "$_path/" : '\(/\)/*[^/]*//*$'  \| \
    "$_path/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

done
if [ -f /bin/pwd ]
then
    origdir=`/bin/pwd`
    cd "$_path"
    dir=`/bin/pwd`
else
    origdir=`pwd`
    cd "$_path"
    dir=`pwd`
fi

kbytes=""

dirname="$dir/"
apple=`df -${_kflag}l $dirname > /dev/null 2>&1`
if [ $? -eq 0 ]
then
    # NOT any of the following
    # pahp0901 axo10300 axo10400 spsu0412 spsu0413 spsu0414 rsai0302
    # rsai0401 rsai0402

    banana=`df -${_kflag}l $dirname 2>/dev/null | egrep '[Aa]vail' > /dev/null 2>&1`
    if [ $? -eq 0 ]
    then
	# NOT any of the following
	# i3sc0325 mpsx0543 pahp1001 pahp1100
	# System V style output
	kbytes=`(df -${_kflag} $dirname 2>/dev/null | egrep -v '[Aa]vail' | tr '\012' ' '; echo) | sed -e '
{
s/^[^ 	]*[ 	]*[a-zA-Z]*[ 	]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
    else
	cumquat=`df -bl $dirname 2>/dev/null | grep "Kbytes free" > /dev/null 2>&1`
	if [ $? -eq 0 ]
	then
	    # pahp10* pahp11*


	    # pahp1002 core dumps if you try df -k on an NFS drive
	    # pahp1020 gives you the wrong info with df -b
	    #     but the right info with df -k !!!
	    # so use df -f and divide the answer
	    kbytes=`df -f $dirname 2>/dev/null | sed -e '
{
s/.*[	 ]*.*:[	 ]*\([0-9]*\)[	 ]*blocks.*$/\1/
q
}'`
	    kbytes=`expr $kbytes / 2`
	else
	    ## probably i3sc0325
	    kbytes=`df -${_kflag} $dirname 2>/dev/null | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	fi
    fi
else
    dewberry=`df -${_kflag} $dirname 2>/dev/null | grep Free > /dev/null 2>&1`
    if [ $? -eq 0 ]
    then
	# rsai04* style output
	kbytes=`df -${_kflag} $dirname 2>/dev/null | grep -v Free  | sed -e '
{
s/^[^ 	]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
    else
	elderberry=`df $dirname > /dev/null 2>&1`
	if [  $? -eq 0  ]
	then
	    # spsu style output
	    kbytes=`df $dirname 2>/dev/null | egrep -v '[Aa]vail' | sed -e '
{
s/^[^ 	]*[ 	]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
	    if [ "x$kbytes" = "x" ]
	    then
		kbytes=`df $dirname 2>/dev/null | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	    case "$kbytes" in
		    *free*) # rsai03* old style
			dk_space=`df $dirname 2>/dev/null | grep -v free  | sed -e '
{
s/^[^   ]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
		    if [ -n "$dk_space" ]
			then
			    kbytes=$dk_space
			fi
		    ;;
		    *)
			dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
			sz=`du -s $_path/._._._`
			sz=`expr "$sz" : '\([0-9]*\).*'`
			rm -f $_path/._._._
			case $sz in
			2*)
				kbytes=`expr $kbytes / $sz`
			    ;;
			    *)
			    ;;
			esac
		esac
	    fi
	else
	    dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
	    sz=`du -s $_path/._._._`
	    sz=`expr "$sz" : '\([0-9]*\).*'`
	    rm -f $_path/._._._
	    while [ "$dirname" != "" ]
	    do
		kbytes=`df 2>/dev/null | egrep "^$dirname[ 	]*\(.*$" | sed -e '
{
s/^[^\)]*.:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	    if [ "$kbytes" != "" -o "$dirname" = "/"  ]
		then
		    break
		fi
if [ -z "$dirname" ]; then
  dirname=.
else
  dirname=`expr "$dirname/" : '\(/\)/*[^/]*//*$'  \| \
    "$dirname/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

	    done
	    case $sz in
		2*)
		    kbytes=`expr $kbytes / $sz`
		;;
		*)
		;;
	    esac
	fi
    fi
fi

cd $origdir

	if [ "${kbytes}0" -gt "${NEEDKB}0" ]; then
	    a_InstDir=$a_definstdir
	fi
    elif [ -d "$a_base_definstdir" ]; then
case "$MACHINEARCH" in
i3li*|ppli*)  _kflag=kP;;
*)	_kflag=k
esac

_path=$a_base_definstdir
while [ ! -d "$_path" ]; do
if [ -z "$_path" ]; then
  _path=.
else
  _path=`expr "$_path/" : '\(/\)/*[^/]*//*$'  \| \
    "$_path/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

done
if [ -f /bin/pwd ]
then
    origdir=`/bin/pwd`
    cd "$_path"
    dir=`/bin/pwd`
else
    origdir=`pwd`
    cd "$_path"
    dir=`pwd`
fi

kbytes=""

dirname="$dir/"
apple=`df -${_kflag}l $dirname > /dev/null 2>&1`
if [ $? -eq 0 ]
then
    # NOT any of the following
    # pahp0901 axo10300 axo10400 spsu0412 spsu0413 spsu0414 rsai0302
    # rsai0401 rsai0402

    banana=`df -${_kflag}l $dirname 2>/dev/null | egrep '[Aa]vail' > /dev/null 2>&1`
    if [ $? -eq 0 ]
    then
	# NOT any of the following
	# i3sc0325 mpsx0543 pahp1001 pahp1100
	# System V style output
	kbytes=`(df -${_kflag} $dirname 2>/dev/null | egrep -v '[Aa]vail' | tr '\012' ' '; echo) | sed -e '
{
s/^[^ 	]*[ 	]*[a-zA-Z]*[ 	]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
    else
	cumquat=`df -bl $dirname 2>/dev/null | grep "Kbytes free" > /dev/null 2>&1`
	if [ $? -eq 0 ]
	then
	    # pahp10* pahp11*


	    # pahp1002 core dumps if you try df -k on an NFS drive
	    # pahp1020 gives you the wrong info with df -b
	    #     but the right info with df -k !!!
	    # so use df -f and divide the answer
	    kbytes=`df -f $dirname 2>/dev/null | sed -e '
{
s/.*[	 ]*.*:[	 ]*\([0-9]*\)[	 ]*blocks.*$/\1/
q
}'`
	    kbytes=`expr $kbytes / 2`
	else
	    ## probably i3sc0325
	    kbytes=`df -${_kflag} $dirname 2>/dev/null | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	fi
    fi
else
    dewberry=`df -${_kflag} $dirname 2>/dev/null | grep Free > /dev/null 2>&1`
    if [ $? -eq 0 ]
    then
	# rsai04* style output
	kbytes=`df -${_kflag} $dirname 2>/dev/null | grep -v Free  | sed -e '
{
s/^[^ 	]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
    else
	elderberry=`df $dirname > /dev/null 2>&1`
	if [  $? -eq 0  ]
	then
	    # spsu style output
	    kbytes=`df $dirname 2>/dev/null | egrep -v '[Aa]vail' | sed -e '
{
s/^[^ 	]*[ 	]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
	    if [ "x$kbytes" = "x" ]
	    then
		kbytes=`df $dirname 2>/dev/null | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	    case "$kbytes" in
		    *free*) # rsai03* old style
			dk_space=`df $dirname 2>/dev/null | grep -v free  | sed -e '
{
s/^[^   ]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
		    if [ -n "$dk_space" ]
			then
			    kbytes=$dk_space
			fi
		    ;;
		    *)
			dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
			sz=`du -s $_path/._._._`
			sz=`expr "$sz" : '\([0-9]*\).*'`
			rm -f $_path/._._._
			case $sz in
			2*)
				kbytes=`expr $kbytes / $sz`
			    ;;
			    *)
			    ;;
			esac
		esac
	    fi
	else
	    dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
	    sz=`du -s $_path/._._._`
	    sz=`expr "$sz" : '\([0-9]*\).*'`
	    rm -f $_path/._._._
	    while [ "$dirname" != "" ]
	    do
		kbytes=`df 2>/dev/null | egrep "^$dirname[ 	]*\(.*$" | sed -e '
{
s/^[^\)]*.:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	    if [ "$kbytes" != "" -o "$dirname" = "/"  ]
		then
		    break
		fi
if [ -z "$dirname" ]; then
  dirname=.
else
  dirname=`expr "$dirname/" : '\(/\)/*[^/]*//*$'  \| \
    "$dirname/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

	    done
	    case $sz in
		2*)
		    kbytes=`expr $kbytes / $sz`
		;;
		*)
		;;
	    esac
	fi
    fi
fi

cd $origdir

	if [ "${kbytes}0" -gt "${NEEDKB}0" ]; then
	    a_InstDir=$a_definstdir
	fi
    fi

    a_Restart=$a_yes

    a_AsadPort=3144

    a_PeerDNS=""
    [ -n "$ASK_PEERDNS" ] && a_PeerDNS=`$ASK_PEERDNS`

    a_httpport=${apachePort:-80}

    upgrade=""
    dupgrade=false # dubious "upgrade", following an uninstall

    # get configuration info for an existing installed tta package
    jive_PkgInst="" jive_InstDir="" jive_DataDir="" jive_Build="" 
    if [ -s "$a_InstDir/etc/pkg/rpm_tta_upgradefrom" ]; then
	# RPM -> RPM upgrade case
	jive_PkgInst="tta"
	jive_InstDir="$a_InstDir"
	jive_DataDir="$a_InstDir/var"
	jive_Build=`cat $a_InstDir/etc/pkg/rpm_tta_upgradefrom`
    else
# find the latest instance of the package
instver=0
pkginst=''
# get the package name
shortpkgname=`echo tta | 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)
    pkginst=`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
		pkginst=$inst
	    fi
	fi
    done
fi

	if [ "${res}0" -eq 0 ]; then
	    jive_InstDir=`pkgparam $pkginst INSTDIR 2>/dev/null`
	    # sanity check
	    if [ -z "`pkginfo -l $pkginst 2>/dev/null | grep INSTDATE:`" -o ! -f "${jive_InstDir}/bin/bin/ttaauxserv" ]; then
		jive_InstDir=""
	    else
		jive_DataDir=${jive_InstDir}/var
		jive_Build=`pkgparam $pkginst BUILD 2>/dev/null`
		jive_PkgInst=$pkginst
	    fi
	fi
    fi

    # Not really upgrading either, but maybe upgrading following an uninstall.
    if [ -z "$jive_InstDir" -a -r "$a_InstDir/var/pkginfo" ]; then
	jive_InstDir=`sed -n 's;INSTDIR=\(.*\);\1;p' $a_InstDir/var/pkginfo`
	jive_DataDir=${jive_InstDir}/var
	jive_Build=`sed -n 's;BUILD=\(.*\);\1;p' $a_InstDir/var/pkginfo`
	jive_PkgInst=""
	dupgrade=true
	if [ -z "$jive_InstDir" -o -z "$jive_Build" ]; then
	    jive_InstDir="" jive_DataDir="" jive_Build="" upgrade="" oldver="" dupgrade=false
	fi
    fi

    # if there is an existing install, try to reuse the peer DNS name, may 
    # not be the same as what is returned by ttahostname, fitz/600820
    localbootstrap="$jive_InstDir/var/serverconfig/local/bootstrap.properties"
    if [ -r "$localbootstrap" ]; then
        origpeername=`sed -n 's;^tarantella.config.server.dns.peer=\(.*\);\1;p' "$localbootstrap"`
        [ ! -z $origpeername ] && a_PeerDNS=$origpeername
    fi

    # care, changes & sets a number of vars
if [ -n "$jive_InstDir" -a "${dupgrade}" = "false" ]; then
  # Re-install or upgrade of a Jive package: use existing values
  a_InstDir=$jive_InstDir
  upgrade=$jive_Build

  # Check for compatibilities
_tmp=`echo $jive_Build | sed -e 's/\([0-9][0-9]*\)\.\([0-9]\)\([0-9]*\)\.\([0-9][0-9]*\)/\1 \2 \3 \4/'`
read _omajor _ofeature _obug _obuild <<EOF
$_tmp
EOF

_tmp=`echo $PRODUCT_VERSION_FULL | sed -e 's/\([0-9][0-9]*\)\.\([0-9]\)\([0-9]*\)\.\([0-9][0-9]*\)/\1 \2 \3 \4/'`
read _nmajor _nfeature _nbug _nbuild <<EOF
$_tmp
EOF

if [ $jive_Build = $PRODUCT_VERSION_FULL ]; then
	INSTTYPE=$a_reinstall
elif [ $_omajor -lt $_nmajor ]; then
	INSTTYPE=$a_upgrade
elif [ $_omajor = $_nmajor -a $_ofeature -lt $_nfeature ]; then
	INSTTYPE=$a_upgrade
elif [ $_omajor = $_nmajor -a $_ofeature = $_nfeature -a $_obug -lt $_nbug ]; then
	INSTTYPE=$a_upgrade
elif [ $_omajor = $_nmajor -a $_ofeature = $_nfeature -a $_obug = $_nbug -a $_obuild -lt $_nbuild ]; then
	INSTTYPE=$a_upgrade
else
	INSTTYPE=$a_downgrade
fi


  # We don't allow downgrades
  [ "$INSTTYPE" = "$a_downgrade" ] && {
    echo "a_installtype='$INSTTYPE'; export a_installtype; 
    oldver='$jive_Build'; export oldver;" >$RESPONSE
    return $CANT_DOWNGRADE
  }
  # Check it's a supported upgrade
suppupgrade=f
# get supported upgrade list as a pipe-delimited pattern
_supported_upgrades=`echo "$SUPPORTED_UPGRADES" | tr ' ' '|'`
[ -n "$jive_Build" ] && suppupgrade=`/bin/sh -c "\
    case $jive_Build in
    $_supported_upgrades) echo t;;
    *) echo f
    esac"`

  [ "$suppupgrade" = "f" ] && {
    echo "a_installtype='$INSTTYPE'; export a_installtype; 
    oldver='$jive_Build'; export oldver;" >$RESPONSE
    return $CANT_UPGRADE
  }
else
  INSTTYPE="$a_install"
  suppupgrade=f
fi


    # only set during install - only time we'll uninstall anything.
    p_oldpkg=""
    if [ "$ASK_INSTDIR" = "t" ]; then
	# Check for pkg compatibility
	incompat=""
	compat_file=$REQDIR/${PKG}compat
if [ -f $compat_file ]; then
  # can we work with them?
  incompat="`
    egrep -v \"^$|^[# ]\" $compat_file | while read c_switch c_pkg c_reqver; do
      if [ ! -z \"$c_pkg\" ]; then 
# find the latest instance of the package
theinstver=0
c_target=''
# get the package name
shortpkgname=\`echo $c_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)
    c_target=\`echo $pkginfo | awk '{print $1}'\`
    for inst in $pkginfo
    do
	thisinst=\`pkgparam $inst INSTVER 2>/dev/null\`
	if [ -n \"$thisinst\" ]; then
	    if [ "$thisinst" -gt "$theinstver" ]; then
		theinstver=$thisinst
		c_target=$inst
	    fi
	fi
    done
fi

      fi
      [ ! -z \"$c_target\" ] && c_instver=\`pkgparam $c_target BUILD 2>/dev/null\` || continue 
      [ $? -ne 0 ] && continue # not installed
_omajor=\`echo $c_instver | sed -e 's;\([0-9][0-9]*\)\..*;\1;'\`
_ofeature=\`echo $c_instver | sed -e 's;[0-9][0-9]*\.\([0-9]\)[0-9]\..*;\1;'\`
_obug=\`echo $c_instver | sed -e 's;[0-9][0-9]*\.[0-9]\([0-9]*\)\..*;\1;'\`
_obuild=\`echo $c_instver | sed -e 's;[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\);\1;'\`


_nmajor=\`echo $c_reqver | sed -e 's;\([0-9][0-9]*\)\..*;\1;'\`
_nfeature=\`echo $c_reqver | sed -e 's;[0-9][0-9]*\.\([0-9]\)[0-9]\..*;\1;'\`
_nbug=\`echo $c_reqver | sed -e 's;[0-9][0-9]*\.[0-9]\([0-9]*\)\..*;\1;'\`
_nbuild=\`echo $c_reqver | sed -e 's;[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\);\1;'\`


if [ $c_instver = $c_reqver ]; then
	c_allow=t
elif [ $_omajor -lt $_nmajor ]; then
	c_allow=f
elif [ $_omajor = $_nmajor -a $_ofeature -lt $_nfeature ]; then
	c_allow=f
elif [ $_omajor = $_nmajor -a $_ofeature = $_nfeature -a $_obug -lt $_nbug ]; then
	c_allow=f
elif [ $_omajor = $_nmajor -a $_ofeature = $_nfeature -a $_obug = $_nbug -a $_obuild -lt $_nbuild ]; then
	c_allow=f
else
	c_allow=t
fi

      [ "$c_allow" = "f" ] && echo "$c_target"
      c_pkg=""
    done`"
fi

	incompat=" `echo $incompat | tr \"\n\" \" \"` "
 
	# need to do this here instead of postinstall to catch a reinstall, where compat would be OK,
	# but depends wouldn't.

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

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


	oldpkg=" $oldttapatch $incompat $oldpkgtmp "
	
	# Look for any other old dependent packages
	pkgDirs=""
	[ -n "${jive_InstDir}" ] && pkgDirs="${pkgDirs} ${jive_InstDir}/etc/pkg"
	for pkgDir in ${pkgDirs}; do
	    for dependFile in ${pkgDir}/*/depend; do
		case "${dependFile}" in
		*/pkg/tta/depend|*/pkg/tta.*/depend)
		    # base pack entry, therefore not a dependent
		    ;;
		*)  dependentPkg=`expr "${dependFile}" : '.*/pkg/\([^/]*\)/depend'`
		    basePkg=`cat ${dependFile} 2>/dev/null`
		    case "${basePkg}" in
		    # $PKGINST)
			# The base pack is the package currently being installed:
			# we don't want to uninstall its dependents.
			# echo "basePkg=$basePkg  PKGINST=$PKGINST"
			# ;;
		    *)
			# use and keep spaces so ttasecure doesn't match ttasecure.2
			if [ `echo \"$oldpkg\" | grep " ${dependentPkg} " 1>/dev/null 2>&1; echo $?` -ne 0 ]; then
			    oldpkg=" ${dependentPkg} ${oldpkg} "
			fi
		    esac
		esac
	    done
	done
	
	# list of packages that we are going to uninstall
	# that we are going to tell the user about.
	for oldp in $oldpkg; do
	    case $oldp in
		tta|tta.* ) ;;
		tt*pip|tt*pip.* ) ;;
		ttawcp|ttawcp.* ) ;;
		ttapatch|ttapatch.* ) ;;
		ttexprsip|ttexprsip.* ) ;;
		ttajava|ttajava.* ) ;;
		* ) p_oldpkg="$oldp $p_oldpkg" ;;
	    esac
	done
    fi

    # if this is a reinstall or an upgrade 
    # and there is no crontab entry 
    # assume the user didnt want one
    # in the previous install
    if [ "$INSTTYPE" = "$a_reinstall" -o "$INSTTYPE" = "$a_upgrade" ]; then
	[ -z "$a_cron" ] && a_Archive=$a_no
    fi

    if [ "$INSTTYPE" = "$a_reinstall" -o "$suppupgrade" = "f" ]; then
	INSTMSG="$INSTTYPE $PRODUCT_VERSION_FULL"
    else
	INSTMSG="$INSTTYPE $jive_Build -> $PRODUCT_VERSION_FULL"
    fi

    qURetVal=$OK

    a_ArchiveOrig=$a_Archive
    a_Webtop=$a_no
    a_PrtSetup=$a_no

    # work out the rctype
_dummy_="" a_RcCurRun="" a_RcInstRun="" a_RcKillRun="" a_RcType="unknown" a_RcFile=""
if [ -d /etc/rc.d/rc2.d -o -d /etc/rc.d/rc3.d ]; then
  a_RcType="rcddir" a_RcFile="/etc/rc.d" _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_RcCurRun=`who -r 2>/dev/null | awk '{print $3;}'`
  [ ! -z "$a_RcCurRun" ] && {
    case $a_RcCurRun in [0-9]);; *) a_RcCurRun=`who -r 2>/dev/null | awk '{print $2;}'`;; esac;
  } || a_RcCurRun=`/sbin/runlevel 2>/dev/null | awk '{print $2}'`;
  [ -z "$a_RcCurRun" ] && a_RcCurRun=2 # guess
  a_RcKillRun=1
  for _i in 5 4 3 2 1 S; do
    [ -r ${_rcbase}${_i}.d/$INST_RCFILE ] && { a_RcInstRun=${_i}; break; }
  done
  _dummy_=$a_RcFile/rc$a_RcKillRun.d/_dummy_
  a_RcFile=$a_RcFile/rc$a_RcCurRun.d/$INST_RCFILE
esac

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

    SettingsOK="n"
    firsthdr=0
    insist=""
    show_insist_prompt=""
    while [ "$SettingsOK" = "n" ]; do

	##################################################################
	# Work out current license mode on basis of installed license numbers.
	# 
	licinfo_str=`GetLicInfo "$l_mode_eval" "$l_mode_eval2" "$l_mode_full" "$l_mode_full2" "$l_unlimited" "$LICINFO" "$PRODUCT_LICENSE_PRODUCT_CODE" "$a_LicenseKeys"`
	licmode=`expr "$licinfo_str" : '[^%]*%\([^%]*\)%.*'`
	licmode_ext=`expr "$licinfo_str" : '.*%\([^%]*\)$'`

	echo " "; echo " "
	summarystr="$l_summary"
echo $_ss_headlines
echo "$summarystr"
echo $_ss_headlines

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

	##################################################################
	# Display current settings
	#
	[ -n "$INSTTYPE" ] && echo "$q_installtype = $INSTMSG"
	[ -n "$ASK_INSTDIR" ] && echo "$q_instdir = $a_InstDir"
	[ -n "$ASK_PEERDNS" ] && echo "$q_peerdns = $a_PeerDNS"
	[ -n "$ASK_LICMODE" ] && echo "$h_licmode = ${licmode}${licmode_ext}"
        if [ -n "$ASK_HTTPPORT" -a "$INSTTYPE" != "$a_upgrade" ]; then
            httpinuse=`$TTA_TMPDIR/ttahostprobe localhost:$a_httpport`
            echo $N "$q_httpport = $a_httpport $C"
            [ "$httpinuse" = "y" ] && echo $N "$p_httpinuse$C" || echo $N "$p_httpnotinuse$C"
            echo " "
        fi
	if [ -n "$ASK_CRONTAB" ]; then
	    echo $N "$q_checkpoint = $a_Archive$C"
	    if [ "$a_Archive" = "$a_yes" ]; then
  case $a_CronDay in
    0 ) a_daystr="$l_sun";;
    1 ) a_daystr="$l_mon";;
    2 ) a_daystr="$l_tue";;
    3 ) a_daystr="$l_wed";;
    4 ) a_daystr="$l_thu";;
    5 ) a_daystr="$l_fri";;
    6 ) a_daystr="$l_sat";;
  esac

		echo $N " ($a_daystr $C"
		echo $N "$a_CronTime$q_hours)$C"
	    fi
	    echo
	fi
	if [ -n "$ASK_RC" ]; then
	    if [ "$a_RcType" != "unknown" ]; then
		case $a_RunLevel in
		2|3|4|5 ) 
		    ;;
		* ) case "$a_RcType" in
		    svr4*|sbin|rcddir*)
			echo $N "$q_restart = $a_Restart$C"
			if [ "$a_Restart" = "yes" -a "$a_RunLevel" != "" ]; then
			    echo " ($q_runlevel = $a_RunLevel)"
			else
			    echo " "
			fi
		    esac
		esac
	    fi
	fi
	[ -n "$ASK_WEBTOP" ] && echo "$q_webtop = $a_Webtop"
	[ -n "$ASK_PRINTER" ] && echo "$q_prtsetup = $a_PrtSetup"
	if [ ! -z "$p_oldpkg" ]; then
	    echo "$q_pkguninst"
	    for uninst in $p_oldpkg; do
		[ ! -z "$uninst" ] && echo " - `pkgparam $uninst NAME`"
	    done
	    echo "$q_pkguninst2"
	fi

	[ "$dupgrade" != "false" -a -n "${jive_Build}" ] && echo "${l_dupgrade}${jive_Build}${l_dupgrade1}"

	# Warn about unsupported upgrades from pre-release builds of same version
	if [ -n "$jive_Build" -a -n "$PRODUCT_VERSION_FULL" ]; then
	    oldVer=`expr "$jive_Build" : '\(.*\..*\)\..*'`
	    oldBld=`expr "$jive_Build" : '.*\..*\.\(.*\)'`
	    newVer=`expr "$PRODUCT_VERSION_FULL" : '\(.*\..*\)\..*'`
	    if [ -n "$oldVer" -a -n "$newVer" -a -n "$oldBld" ]; then
		[ "$oldVer" = "$newVer" -a "$oldBld" -lt 901 ] && echo "$l_unsupported_upgrade"
	    fi
	fi

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

        #  check there is enough space to (re)install
        # How much space is available in $a_InstDir?
case "$MACHINEARCH" in
i3li*|ppli*)  _kflag=kP;;
*)	_kflag=k
esac

_path=$a_InstDir
while [ ! -d "$_path" ]; do
if [ -z "$_path" ]; then
  _path=.
else
  _path=`expr "$_path/" : '\(/\)/*[^/]*//*$'  \| \
    "$_path/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

done
if [ -f /bin/pwd ]
then
    origdir=`/bin/pwd`
    cd "$_path"
    dir=`/bin/pwd`
else
    origdir=`pwd`
    cd "$_path"
    dir=`pwd`
fi

kbytes=""

dirname="$dir/"
apple=`df -${_kflag}l $dirname > /dev/null 2>&1`
if [ $? -eq 0 ]
then
    # NOT any of the following
    # pahp0901 axo10300 axo10400 spsu0412 spsu0413 spsu0414 rsai0302
    # rsai0401 rsai0402

    banana=`df -${_kflag}l $dirname 2>/dev/null | egrep '[Aa]vail' > /dev/null 2>&1`
    if [ $? -eq 0 ]
    then
	# NOT any of the following
	# i3sc0325 mpsx0543 pahp1001 pahp1100
	# System V style output
	kbytes=`(df -${_kflag} $dirname 2>/dev/null | egrep -v '[Aa]vail' | tr '\012' ' '; echo) | sed -e '
{
s/^[^ 	]*[ 	]*[a-zA-Z]*[ 	]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
    else
	cumquat=`df -bl $dirname 2>/dev/null | grep "Kbytes free" > /dev/null 2>&1`
	if [ $? -eq 0 ]
	then
	    # pahp10* pahp11*


	    # pahp1002 core dumps if you try df -k on an NFS drive
	    # pahp1020 gives you the wrong info with df -b
	    #     but the right info with df -k !!!
	    # so use df -f and divide the answer
	    kbytes=`df -f $dirname 2>/dev/null | sed -e '
{
s/.*[	 ]*.*:[	 ]*\([0-9]*\)[	 ]*blocks.*$/\1/
q
}'`
	    kbytes=`expr $kbytes / 2`
	else
	    ## probably i3sc0325
	    kbytes=`df -${_kflag} $dirname 2>/dev/null | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	fi
    fi
else
    dewberry=`df -${_kflag} $dirname 2>/dev/null | grep Free > /dev/null 2>&1`
    if [ $? -eq 0 ]
    then
	# rsai04* style output
	kbytes=`df -${_kflag} $dirname 2>/dev/null | grep -v Free  | sed -e '
{
s/^[^ 	]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
    else
	elderberry=`df $dirname > /dev/null 2>&1`
	if [  $? -eq 0  ]
	then
	    # spsu style output
	    kbytes=`df $dirname 2>/dev/null | egrep -v '[Aa]vail' | sed -e '
{
s/^[^ 	]*[ 	]*[0-9]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
	    if [ "x$kbytes" = "x" ]
	    then
		kbytes=`df $dirname 2>/dev/null | sed -e '
{
s/.*[ 	]*.*:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	    case "$kbytes" in
		    *free*) # rsai03* old style
			dk_space=`df $dirname 2>/dev/null | grep -v free  | sed -e '
{
s/^[^   ]*[ 	]*[0-9]*[ 	]*\([0-9]*\).*$/\1/
q
}'`
		    if [ -n "$dk_space" ]
			then
			    kbytes=$dk_space
			fi
		    ;;
		    *)
			dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
			sz=`du -s $_path/._._._`
			sz=`expr "$sz" : '\([0-9]*\).*'`
			rm -f $_path/._._._
			case $sz in
			2*)
				kbytes=`expr $kbytes / $sz`
			    ;;
			    *)
			    ;;
			esac
		esac
	    fi
	else
	    dd of=$_path/._._._ bs=1000 if=/bin/ls count=1 > /dev/null 2>&1
	    sz=`du -s $_path/._._._`
	    sz=`expr "$sz" : '\([0-9]*\).*'`
	    rm -f $_path/._._._
	    while [ "$dirname" != "" ]
	    do
		kbytes=`df 2>/dev/null | egrep "^$dirname[ 	]*\(.*$" | sed -e '
{
s/^[^\)]*.:[ 	]*\([0-9]*\)[ 	]*blocks.*$/\1/
q
}'`
	    if [ "$kbytes" != "" -o "$dirname" = "/"  ]
		then
		    break
		fi
if [ -z "$dirname" ]; then
  dirname=.
else
  dirname=`expr "$dirname/" : '\(/\)/*[^/]*//*$'  \| \
    "$dirname/" : '\(.*[^/]\)//*[^/][^/]*//*$' \| \
    .`
fi

	    done
	    case $sz in
		2*)
		    kbytes=`expr $kbytes / $sz`
		;;
		*)
		;;
	    esac
	fi
    fi
fi

cd $origdir


        # Is it enough?
        if [ -n "$ASK_INSTDIR" -a "${kbytes}0" -le "${NEEDKB}0" ]; then   
	    show_insist_prompt=t
            SettingsOK="N"
            # tell the user there is not enough space
            echo " "; echo " "
            echo "$e_nospace1$a_InstDir"
            # but if they insist, let them ...
	    if [ -z "$insist" ]; then
		echo "$e_nospace2$NEEDKB$e_nospace3"
	    else
		echo "$e_carryonregardless"
		SettingsOK="Y"
	    fi
        else
            ## check if ok
            [ "${SettingsOK}" != "N" ] && SettingsOK="Y"
	fi

        # Are they trying to install in a sensible place?
	instdircontents=""
	[ -d "${a_InstDir}" ] && instdircontents=`ls "${a_InstDir}" | egrep -v '^(tmp.*|temp.*|tta.*|bin|etc|var|webserver)$'`
	if [ -n "${instdircontents}" ]; then
	    show_insist_prompt=t
	    SettingsOK="N"
	    # tell the user the prospective instdir is not empty
	    echo "${e_instdircontents1}${a_InstDir}${e_instdircontents2}`cd ${a_InstDir};ls -l \"${instdircontents}\"`"
	    # but if they insist, let them ...
	    if [ -n "$insist" ]; then
		echo "
$e_carryonregardless"
		SettingsOK="Y"
	    fi
        else
            ## check if ok
            [ "${SettingsOK}" != "N" ] && SettingsOK="Y"
	fi

        # check for HTTP port availability
        if [ -n "$ASK_HTTPPORT" -a "$INSTTYPE" != "$a_upgrade" -a "$httpinuse" = "y" ]; then
            echo "$e_httpport_inuse"
            get_httpport
            SettingsOK="n"
            continue
        fi

	extra_qprompt="${q_or_q}"
	case "$SettingsOK" in
	y|Y)
            echo " "
	    extra_qprompt=""
echo "$p_damage"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_damage [$SettingsOK] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$SettingsOK"   # default
  fi
  case "$_answer" in y|Y|n|N|q|Q)_valid=true;;esac
done
SettingsOK="$_answer"

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

        esac

	case "$SettingsOK" in
	q|Q)
	    echo " "
echo $_ss_headlines
echo "$h_nochange"
echo $_ss_headlines

	    # tell the wrapper script to exit quietly
	    echo "#USERQUIT" >>$TTA_TMPDIR/ttainst.cmds_to_webwrap 2>/dev/null
	    qURetVal=$QUIT
	    return $qURetVal
	    ;;
	n|N)
	    # User wants to change something
	    # Loop again
	    SettingsOK="n"
	    ;;
	y|Y)
	    if [ "${dupgrade}" != "false" ]; then
		dupgrade="${jive_Build}"
		[ -z "${dupgrade}" ] && dupgrade="0.00.000"
		jive_InstDir=""
		jive_DataDir=""
		jive_Build=""
		jive_PkgInst=""
		oldpkg=""
	    fi
	    [ "$INSTTYPE" = "${a_upgrade}" ] && a_httpport="%%oldhttpport"
	    echo \
"a_Archive='$a_Archive' export a_Archive
a_ArchiveOrig='$a_ArchiveOrig' export a_ArchiveOrig
a_AsadPort='$a_AsadPort' export a_AsadPort
a_CronDay='$a_CronDay' export a_CronDay
a_CronDayOrig='$a_CronDayOrig' export a_CronDayOrig
a_CronTime='$a_CronTime' export a_CronTime
a_CronTimeOrig='$a_CronTimeOrig' export a_CronTimeOrig
a_InstDir='$a_InstDir' export a_InstDir
a_LicenseKeys='$a_LicenseKeys' export a_LicenseKeys
a_PeerDNS='$a_PeerDNS' export a_PeerDNS
a_PrtSetup='$a_PrtSetup' export a_PrtSetup
a_RcCurRun='$a_RcCurRun' export a_RcCurRun
a_RcFile='$a_RcFile' export a_RcFile
a_RcInstRun='$a_RcInstRun' export a_RcInstRun
a_RcKillRun='$a_RcKillRun' export a_RcKillRun
a_RcType='$a_RcType' export a_RcType
a_Restart='$a_Restart' export a_Restart
a_RunLevel='$a_RunLevel' export a_RunLevel
a_Webtop='$a_Webtop' export a_Webtop
jive_InstDir='$jive_InstDir' export jive_InstDir
jive_DataDir='$jive_DataDir' export jive_DataDir
jive_Build='$jive_Build' export jive_Build
jive_PkgInst='$jive_PkgInst' export jive_PkgInst
oldpkg='$oldpkg' export oldpkg
a_httpport='$a_httpport' export a_httpport
dupgrade='$dupgrade' export dupgrade" >$RESPONSE
	    break ;;
	esac

	##################################################################
	# Installation directory
	#
	if [ -n "$ASK_INSTDIR" ]; then
	    echo " "; echo " "
echo $_ss_headlines
echo "$h_instdir"
echo $_ss_headlines

	    prompt="$p_instdir"; [ -n "$show_insist_prompt" ] && prompt="${prompt}${p_instdir_insist}"
echo "$prompt"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  _valid2=false
  _tmp_dirname=""
  echo $N "$q_instdir$extra_qprompt [$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" ;;
	    q|Q) echo " "
echo $_ss_headlines
echo "$h_nochange"
echo $_ss_headlines

		# tell the wrapper script to exit quietly
		echo "#USERQUIT" >>$TTA_TMPDIR/ttainst.cmds_to_webwrap 2>/dev/null
		qURetVal=$QUIT
		return $qURetVal
	    esac
	fi
	show_insist_prompt=""

	# Not really upgrading either, but maybe upgrading following an uninstall.
	if [ -z "$pkginst" ]; then  # no current install
	    if [ -r "$a_InstDir/var/pkginfo" ]; then
		jive_InstDir=`sed -n 's;INSTDIR=\(.*\);\1;p' $a_InstDir/var/pkginfo`
		jive_DataDir=${jive_InstDir}/var
		jive_Build=`sed -n 's;BUILD=\(.*\);\1;p' $a_InstDir/var/pkginfo`
		jive_PkgInst=""
		dupgrade=true
		if [ -z "$jive_InstDir" -o -z "$jive_Build" ]; then
		    jive_InstDir="" jive_DataDir="" jive_Build="" upgrade="" oldver="" dupgrade=false
		fi	
	    else
		jive_InstDir="" jive_DataDir="" jive_Build="" upgrade="" oldver="" dupgrade=false
	    fi

	    # care, changes & sets a number of vars    
if [ -n "$jive_InstDir" -a "${dupgrade}" = "false" ]; then
  # Re-install or upgrade of a Jive package: use existing values
  a_InstDir=$jive_InstDir
  upgrade=$jive_Build

  # Check for compatibilities
_tmp=`echo $jive_Build | sed -e 's/\([0-9][0-9]*\)\.\([0-9]\)\([0-9]*\)\.\([0-9][0-9]*\)/\1 \2 \3 \4/'`
read _omajor _ofeature _obug _obuild <<EOF
$_tmp
EOF

_tmp=`echo $PRODUCT_VERSION_FULL | sed -e 's/\([0-9][0-9]*\)\.\([0-9]\)\([0-9]*\)\.\([0-9][0-9]*\)/\1 \2 \3 \4/'`
read _nmajor _nfeature _nbug _nbuild <<EOF
$_tmp
EOF

if [ $jive_Build = $PRODUCT_VERSION_FULL ]; then
	INSTTYPE=$a_reinstall
elif [ $_omajor -lt $_nmajor ]; then
	INSTTYPE=$a_upgrade
elif [ $_omajor = $_nmajor -a $_ofeature -lt $_nfeature ]; then
	INSTTYPE=$a_upgrade
elif [ $_omajor = $_nmajor -a $_ofeature = $_nfeature -a $_obug -lt $_nbug ]; then
	INSTTYPE=$a_upgrade
elif [ $_omajor = $_nmajor -a $_ofeature = $_nfeature -a $_obug = $_nbug -a $_obuild -lt $_nbuild ]; then
	INSTTYPE=$a_upgrade
else
	INSTTYPE=$a_downgrade
fi


  # We don't allow downgrades
  [ "$INSTTYPE" = "$a_downgrade" ] && {
    echo "a_installtype='$INSTTYPE'; export a_installtype; 
    oldver='$jive_Build'; export oldver;" >$RESPONSE
    return $CANT_DOWNGRADE
  }
  # Check it's a supported upgrade
suppupgrade=f
# get supported upgrade list as a pipe-delimited pattern
_supported_upgrades=`echo "$SUPPORTED_UPGRADES" | tr ' ' '|'`
[ -n "$jive_Build" ] && suppupgrade=`/bin/sh -c "\
    case $jive_Build in
    $_supported_upgrades) echo t;;
    *) echo f
    esac"`

  [ "$suppupgrade" = "f" ] && {
    echo "a_installtype='$INSTTYPE'; export a_installtype; 
    oldver='$jive_Build'; export oldver;" >$RESPONSE
    return $CANT_UPGRADE
  }
else
  INSTTYPE="$a_install"
  suppupgrade=f
fi

	    if [ "$INSTTYPE" = "$a_reinstall" -o "$suppupgrade" = "f" ]; then
		INSTMSG="$INSTTYPE $PRODUCT_VERSION_FULL"
	    else
		INSTMSG="$INSTTYPE $jive_Build -> $PRODUCT_VERSION_FULL"
	    fi

	fi

	##################################################################
	# Peer DNS name
	#
	if [ -n "$ASK_PEERDNS" ]; then
            echo " "; echo " "
echo $_ss_headlines
echo "$h_peerdns"
echo $_ss_headlines


echo "$p_peerdns"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_peerdns [$a_PeerDNS] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_PeerDNS"   # default
  fi
  _valid=true
done
a_PeerDNS="$_answer"

	fi


        [ "$INSTTYPE" != "$a_upgrade" ] && get_httpport 

	##################################################################
	# Archive logs weekly?
	#
	if [ -n "$ASK_CRONTAB" ]; then
echo; echo
echo $_ss_headlines
echo "$h_checkpoint"
echo $_ss_headlines

echo "$p_checkpoint"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_checkpoint [$a_Archive] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_Archive"   # default
  fi
  case "$_answer" in
    [${a_case_yes}]* )
	    _answer=$s_yes
	    _valid=true
	    ;;
    [${a_case_no}]* )
	    _answer=$s_no
	    _valid=true
	    ;;
  esac
done
a_Archive="$_answer"

     
	    if [ "$a_Archive" = "$a_yes" ]; then
echo "$p_checkday"
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_checkday [$a_CronDay] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_CronDay"   # default
  fi
  case "$_answer" in
  [0-6] )
      _valid=true
      a_CronDay=$_answer
      ;;
  *)
    echo "$v_badday"
    ;;
  esac
done

echo "$p_checktime"
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_checktime [$a_CronTime] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_CronTime"   # default
  fi
  case "$_answer" in
  [0-9]|[0-9][0-9])
    if [ `expr $_answer \< 24` != "0" ]; then
      _valid=true
      a_CronTime=$_answer
    else
      echo "$v_badnumber"
    fi
    ;;
  *)
    echo "$v_badnumber"
    ;;
  esac
done

	    fi
	fi

	##################################################################
	# Restart Tarantella on system reboot?
	#
	if [ -n "$ASK_RC" ]; then
	    if [ "$a_RcType" != "unknown" ]; then
		a_Restart="yes"
		case "$a_RunLevel" in
		2|3|4|5 ) 
		    ;;
		* ) case "$a_RcType" in
		    svr4*|sbin|rcddir*)
echo; echo
echo $_ss_headlines
echo "$h_restart"
echo $_ss_headlines

echo "$p_restart"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_restart [$a_Restart] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_Restart"   # default
  fi
  case "$_answer" in
    [${a_case_yes}]* )
	    _answer=$s_yes
	    _valid=true
	    ;;
    [${a_case_no}]* )
	    _answer=$s_no
	    _valid=true
	    ;;
  esac
done
a_Restart="$_answer"

			
			if [ "$a_Restart" = "yes" ]
			then
case "$a_RcType" in
"svr4"|"sbin")
  if [ "$a_RcType" = "svr4" ]
  then
    _rcbase=/etc/rc
  else
    _rcbase=/sbin/rc
  fi

  # check the installed runlevel
  _instrun=""
  for _i in S 1 2 3 4 5
  do
    if [ -f "$_rcbase$_i.d/$INST_RCFILE" ]
    then
      _instrun=$_i
      break
    fi
  done

  # check the current run level
  _currun=`who -r 2>/dev/null | awk '{print $3;}'`
  [ ! -z "$_currun" ] && {
    case $_currun in [0-9]);; *) _currun=`who -r 2>/dev/null | awk '{print $2;}'`;; esac;
  } || _currun=`/sbin/runlevel 2>/dev/null | awk '{print $2}'`;
  [ -z "$_currun" ] && _currun=2 # guess

  # display all known information
  echo "$p_runlevel"
  if [ ! -z "$_currun" ]
  then
    echo "$p_currun$_currun"
    a_RunLevel=$_currun
  fi
  if [ ! -z "$_instrun" ]
  then
    echo "$p_instrun$_instrun"
    a_RunLevel=$_instrun
  fi

  _valid="false"
  while [ $_valid = false ]
  do
    echo $N "$q_runlevel [$a_RunLevel] $C"
    read _answer
    if [ -z "$_answer" ]
    then
      _answer="$a_RunLevel"   # default
    fi
    case "$_answer" in
    "s")
      _answer="S"
      ;;
    "1"|"2"|"3"|"4"|"S")
      ;;
    *)
      echo "$v_runlevel"
      continue
      ;;
    esac

    # check the rcdir exists
    if [ ! -d $_rcbase$_answer.d ]
    then
      _valid2=false
      while  [ "$_valid2" != "true" ]
      do
        echo $N "$q_mkrcdir [$a_yes] $C"
        read _answer2
        if [ -z "$_answer2" ]
        then
          _answer2=$a_yes
        fi
        case "$_answer2" in
        [${a_case_yes}]*)
          _valid2=true
          _valid=true
          ;;
        [${a_case_no}]*)
          _valid2=true
        esac
      done
    else
      _valid=true
    fi
  done

  a_RunLevel="$_answer"
  a_RcFile=$_rcbase$a_RunLevel.d/$INST_RCFILE
  ;;
"local")
  a_RcFile=/etc/rc.local
  ;;
"rcd")
  a_RcFile=/etc/rc.d/rc.local
  ;;
"nfs")
  a_RcFile=/etc/rc.nfs
  ;;
"basic")
  a_RcFile=/etc/rc
  ;;
*)
  a_RcFile=""
  ;;
esac

			fi
		    esac
		esac
	    fi
	fi

	##################################################################
	# Create default webtop objects?
	#
	if [ -n "$ASK_WEBTOP" ]; then
echo; echo
echo $_ss_headlines
echo "$h_webtop"
echo $_ss_headlines

echo "$p_webtop"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_webtop [$a_Webtop] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_Webtop"   # default
  fi
  case "$_answer" in
    [${a_case_yes}]* )
	    _answer=$s_yes
	    _valid=true
	    ;;
    [${a_case_no}]* )
	    _answer=$s_no
	    _valid=true
	    ;;
  esac
done
a_Webtop="$_answer"

	fi

	##################################################################
	# Create Tarantella printer?
	#
	if [ -n "$ASK_PRINTER" ]; then
echo; echo
echo $_ss_headlines
echo "$h_prtsetup"
echo $_ss_headlines

echo "$p_prtsetup"
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "$q_prtsetup [$a_PrtSetup] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_PrtSetup"   # default
  fi
  case "$_answer" in
    [${a_case_yes}]* )
	    _answer=$s_yes
	    _valid=true
	    ;;
    [${a_case_no}]* )
	    _answer=$s_no
	    _valid=true
	    ;;
  esac
done
a_PrtSetup="$_answer"

	fi
    done

    return $qURetVal
}


getLicenseUpgradeInfo()
{
    # get configuration info for an existing installed tta package
    jive_PkgInst="" jive_InstDir="" jive_DataDir="" jive_Build="" OldVersionAsNumber=0
# find the latest instance of the package
instver=0
pkginst=''
# get the package name
shortpkgname=`echo tta | 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)
    pkginst=`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
		pkginst=$inst
	    fi
	fi
    done
fi

    if [ "${res}0" -eq 0 ]; then
        jive_InstDir=`pkgparam $pkginst INSTDIR 2>/dev/null`
        # sanity check
        if [ -z "`pkginfo -l $pkginst 2>/dev/null | grep INSTDATE:`" -o ! -f "${jive_InstDir}/bin/bin/ttaauxserv" ]; then
            jive_InstDir=""
        else
            jive_DataDir=${jive_InstDir}/var
            jive_Build=`pkgparam $pkginst BUILD 2>/dev/null`
            OldVersionAsNumber=`echo "${jive_Build}" | tr -d .`
	    case "${OldVersionAsNumber}" in
	    [0-9][0-9][0-9][0-9][0-9][0-9]) ;;
	    *) OldVersionAsNumber=0
	    esac
            jive_PkgInst=$pkginst
        fi
    fi
    [ -z "${jive_InstDir}" ] && return 0

    # check license status
    DATADIR="${jive_DataDir}"
    LICTMPDIR="${TTA_TMPDIR}"
    rm -f ${LICTMPDIR}/licdata* 2>/dev/null
    for licinfo in /var/sadm/pkg/tta*/install/licinfo; do
	cp ${licinfo} ${LICTMPDIR} 2>/dev/null
	chmod +x ${LICTMPDIR}/licinfo 2>/dev/null
	break
    done
    lickeys=`awk '$1=="License-Key:"{print $2}' "${DATADIR}/info/lickeys.msg" 2>/dev/null`
    [ -n "${lickeys}" -a -x ${LICTMPDIR}/licinfo ] && {	# failsafe: need license key(s) and licinfo program
	echo 0 >${LICTMPDIR}/licdata.maint
	echo 0 >${LICTMPDIR}/licdata.users
	echo "${lickeys}" | tee ${LICTMPDIR}/licdata.keys | while read lickey; do
	    ${LICTMPDIR}/licinfo ${lickey} >${LICTMPDIR}/licdata 2>/dev/null
	    [ $? -ne 0 ] && continue				# failsafe: ignore keys that make licinfo fail
	    [ -n "`grep '^TTALIC_COMPONENTS=.*38' ${LICTMPDIR}/licdata`" ] && {
		# right-to-upgrade trumps all maintenance keys
		echo "+999999999" >>${LICTMPDIR}/licdata.maint
		continue
	    }
	    users=`sed '/^TTALIC_USERS=/!d;s/.*=//' ${LICTMPDIR}/licdata`
	    case "${users}" in
	    [0-9]*)
		if [ -n "`grep '^TTALIC_COMPONENTS=.*37' ${LICTMPDIR}/licdata`" ]; then
		    echo "+${users}" >>${LICTMPDIR}/licdata.maint
		elif [ -n "`grep '^TTALIC_COMPONENTS=.0' ${LICTMPDIR}/licdata`" ]; then
		    echo "+${users}" >>${LICTMPDIR}/licdata.users
		fi
	    esac
	done
	maint_total=`(tr -d '\012' <${LICTMPDIR}/licdata.maint;echo)|bc`
	users_total=`(tr -d '\012' <${LICTMPDIR}/licdata.users;echo)|bc`
	[ "${OldVersionAsNumber}" -lt 420000 -a ${maint_total} -lt ${users_total} ] && {
	    echo "
This ${PRODUCT_SHORT_NAME} server cannot be upgraded because it is not licensed
for upgrades. Check that you have added the correct license keys and try again.
Alternatively, you can uninstall your current installation and install the new
version as a clean install.
"
	    return 1
	}
    }
    return 0
}

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


getLicenseInfo
rVal=$?
[ $rVal -ne $OK ] && cleanandexit $rVal

getLicenseUpgradeInfo
rVal=$?
[ $rVal -ne $OK ] && cleanandexit $rVal


setup_dialog --gotstrings --licinfo $LICINFO --response $SAVE_FILE --needkb $kb_needed --ask_instdir --ask_crontab --ask_rc --ask_peerdns $TTAHOSTNAME --ask_httpport
rVal=$?
# Can't downgrade from any version, and can't upgrade *directly* from versions older than 3.30
if [ "$rVal" -eq "$CANT_DOWNGRADE" -o "$rVal" -eq "$CANT_UPGRADE" ]; then
    . $SAVE_FILE
    echo $m_cantupgrade1$a_installtype$m_cantupgrade2$oldver$m_cantupgrade3 | tee -a $LOGFILE
    [ "$rVal" -eq "$CANT_UPGRADE" ] && echo "$m_upgrade_via330" | tee -a $LOGFILE
    echo "<--- $who_i_am" >>$LOGFILE
    rm -f "$LICINFO" "$TTAHOSTPROBE" "$TTAHOSTNAME" $TTA_TMPDIR/LICENSE.tta* $TTAREGISTERINFO >/dev/null 2>&1
    exit 1
fi
[ $rVal -ne $OK ] && cleanandexit $rVal

NEWKEYS=""
for i in `cat $TTA_TMPDIR/LICENSE.tta 2>/dev/null` ; do
    NEWKEYS="$NEWKEYS $i"
done
OLDKEYS=""
for i in `cat $TTA_TMPDIR/LICENSE.tta.old 2>/dev/null` ;do
    OLDKEYS="$OLDKEYS $i"
done

echo "NEWKEYS='$NEWKEYS'
OLDKEYS='$OLDKEYS'" >>$SAVE_FILE
    
echo " "
echo "$l_recordingsettings"

#instver holds the "installation number" -increment it
if [ -z "$instver" ]; then instver=0; fi
instver=`expr $instver + 1`


cat >$1 << EOF
INSTDIR="$a_InstDir"
DATADIR="${a_InstDir}/var"
INSTVER="$instver"
UPGRADE="$upgrade"
LKEYS="$a_LicenseKeys"
TTA_TMPDIR="$TTA_TMPDIR"
EOF

if [ -f $TTA_TMPDIR/UPGRADE.tta ]; then
  # if we are being run from an shx script
  # spin the spinner
  (spin)&
fi

rm -f "$LICINFO" "$TTAHOSTPROBE" "$TTAHOSTNAME" $TTA_TMPDIR/LICENSE.tta* $TTAREGISTERINFO >/dev/null 2>&1
echo "<--- $who_i_am" >>$LOGFILE
exit $OK


