#!/bin/sh
###############################################################################
#
#	Name:		util_tr.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/util_tr.sh#5 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Provides functions to translate character strings
#			to upper and lower case.  This is done using functions
#			because 'tr' is not portable, and cannot always
#			be guaranteed to be available.
#
#			This file contains versions using 'tr' in its
#			simplest form.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################

# <<< - beginning of block containing strings for localisation
# >>> - end of block containing strings for localisation

###############################################################################
#
#  toupper() copies the standard input to the output, translating any lower
#  case letters to upper case.
#
###############################################################################
toupper(){
	 <&0 tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ >&1
}

###############################################################################
#
#  tolower() copies the standard input to the output, translating any upper
#  case letters to lower case.
#
###############################################################################
tolower(){
	 <&0 tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz >&1
}
#!/bin/sh
###############################################################################
#
#	Name:		map.sh
#
#
#	Created:	30 August 1994
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/map.sh#6 $
#
#	Coding Stds:	2.4
#
#	Purpose:	To map a file name from its original name to whatever
#			will be present on the CD ROM.  A file name may start
#			out as something like "install", but when put on a 
#			CD ROM and mounted, it may be changed to upper case,
#			may have a dot at the end, and may have a semi colon 1
#			at the end, so ending up as INSTALL, install., 
#			install.;1, or INSTALL.;1
#
#			To use these functions, you should include this source
#			in your shell script by concatenating it with your
#			source at build time, i.e. 
#				cat map.sh myscript.sh > myscript
#
#			To use the functions, you should first call get_tr_key
#			to set up the mapping keys, and then call tr_file for
#			each file you want to access.
#			E.g., 
#				get_tr_key $0
#				tr_file $TR_FILE_KEY /dir1/dir2/filename
#
#			The file name that is passed to get_tr_key should not
#			have any extensions in it. Also, in order that the
#			file name case mapping is correct, all the files on
#			a CD should be of the same case, either all upper or
#			all lower, not mixed.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################

# <<< - beginning of block containing strings for localisation
# >>> - end of block containing strings for localisation

###############################################################################
#
#	get_tr_key <path/file>
#
#	Examines the given filename, and generates a key suitable for use in
#	tr_file().  The key is returned in $TR_FILE_KEY and $TR_DIR_KEY.
#	TR_FILE_KEY is to be used when mapping a file name, TR_DIR_KEY when
#	mapping a directory name only. TR_DIR_KEY always has the dot and semi
#	colon parts set to NN.
#
#	The input filename is in 8.3 format, but the basic filename must not
#	have any extension, otherwise we cannot tell whether a dot is needed
#	at the end in the no-extension case.  There may be a path, but this
#	is ignored in the generation of the key.
#
###############################################################################

get_tr_key(){
	trkey_filename=`basename $1`
	TR_FILE_KEY=""
	TR_DIR_KEY=""

	# See if it's in upper or lower case.
	trkey_lower_filename=`echo $trkey_filename | tolower`
	if [ "$trkey_lower_filename" = "$trkey_filename" ]
	then
		# It is lower case
		TR_FILE_KEY=L
	else
		trkey_upper_filename=`echo $trkey_filename | toupper`
		if [ "$trkey_upper_filename" = "$trkey_filename" ]
		then
			# It is upper case
			TR_FILE_KEY=U
		else
			# It must be mixed case.
			TR_FILE_KEY=M
		fi
	fi

	# Only the case mapping is relevant for a directory, so set up the
	# directory mapping key now using the file case mapping, and NN for
	# dots and semi colons.
	TR_DIR_KEY=${TR_FILE_KEY}NN

	# See if it has a dot.
	echo $trkey_filename | grep '\.' > /dev/null 2>&1
	if [ "$?" = "0" ]
	then
		# Input filename has a dot
		TR_FILE_KEY=${TR_FILE_KEY}D
	else
		# No dot
		TR_FILE_KEY=${TR_FILE_KEY}N
	fi

	# See if it has a semi-colon-one
	echo $trkey_filename | grep ';1' > /dev/null 2>&1
	if [ "$?" = "0" ]
	then
		# Input filename has a semi-colon-one
		TR_FILE_KEY=${TR_FILE_KEY}S
	else
		# No semi-colon-one
		TR_FILE_KEY=${TR_FILE_KEY}N
	fi
}

###############################################################################
#
#	tr_file key <path/file>
#
#	Translates a filename to correspond to the format indicated.
#
#	The first parameter is the format to be used, and is a sequence of
#	three letters as follows:
#	U, L or M - Upper case, Lower case or Mixed case
#	D or N - Dot or No Dot (if there is no ".3" type suffix)
#	S or N - Semi-colon-One (;1) or Not
#	
#	The second parameter is the filename, and may have a leading path,
#	which will be converted to upper or lower case as necessary.
#	The filename is assumed to be in 8.3 format.
#
#	The translated filename is returned in $TR_FILE
#
###############################################################################

tr_file(){
	# Extract 1st, 2nd and 3rd characters.
	# sed is more generally available than cut.
	U_or_L=`echo $1 | sed -e 's/^\(.\).*/\1/'`
	D_or_N=`echo $1 | sed -e 's/^.\(.\).*/\1/'`
	S_or_N=`echo $1 | sed -e 's/^..\(.\).*/\1/'`

	TR_FILE=$2

	case $U_or_L in
	U)
		# Translate to upper case.
		TR_FILE=`echo $TR_FILE | toupper`
		;;
	M)
		# Mixed Case - do no translation
		;;
	*)
		# Translate to lower case (default).
		TR_FILE=`echo $TR_FILE | tolower`
		;;
	esac

	case $D_or_N in
	D)
		# Add a dot at the end, but only if there isn't already one.
		( basename $TR_FILE | grep '\.' > /dev/null ) || TR_FILE=${TR_FILE}'.'
		;;
	*)
		# Do not add a dot
		;;
	esac

	case $S_or_N in
	S)
		# Add a semi-colon-one (;1) at the end.
		TR_FILE=${TR_FILE}\;1
		;;
	*)
		# Do not add a semi-colon-one
		;;
	esac
}

###############################################################################
#
#	setCDidfile CDROOT
#
#	Tries to find a product ID file (pkgid) file in the given directory.
#
#	As a result of this, TR_FILE_KEY and TR_DIR_KEY will be set to values
#	suitable for the directory being examined.  This serves two purposes.
#	Firstly, it allows TR_XXXX_KEY to be set, with no previous information,
#	and secondly, it provides a translated filename (CDidfile) which contains
#	package and version information strings.
#
###############################################################################

setCDidfile()
{
	trialDIR=$1
	tr_file_key_list="UDS UDN UNS UNN LDS LDN LNS LNN MDS MDN MNS MNN"
	

	for key in $tr_file_key_list
	do
		tr_file $key "PkgId"
		if [ -r "$trialDIR/$TR_FILE" ]
		then
			# Make sure both file and directory keys are set.
			get_tr_key $trialDIR/$TR_FILE
			CDidfile=$trialDIR/$TR_FILE
			return
		fi
	done
	CDidfile=""
}
#!/bin/sh
#
# =============================================================================
#
#	Name:		setup.sh
#
#	Purpose:	To invoke a host-specific hinst script for installing
#			or removing Citrix ICA Client for Unix 
#		
#			Note: This part of the file must be preceded by the
#			functions tr_file and get_tr_key.
#
#
#	Created:	2nd February 1998
#
#	Version:	$Id: //depot/NetClient/3.0Unix/unix/installer/scripts/setup.sh#2 $
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
# =============================================================================

# <<< - beginning of block containing strings for localisation

setup1="This package does not contain a Citrix ICA Client for Unix for this workstation."

# the name of the installer script goes between setup2a and setup2b.
setup2a="Cannot locate essential files. Please run "
setup2b="using a full path."

# the platform type (HP, Dec, etc.) goes between setup4a and setup4b.
setup3a="This installation is not the correct type for a"
setup3b="workstation."

# >>> - end of block containing strings for localisation

# =============================================================================
#
#	get_OS()
#
#	Determines the Operating System we are running on, and sets up some
#	OS-specific variables, to ensure that some non-portable commands are
#	used, correctly.  If we cannot identify the operatin system the
#	shell is exited.
#
#	Outputs:	PLATFORM:	A platform-specific name for the host.
#			LNKTST:		The letter to use to `test' for a
#					sybbolic link.
#
# =============================================================================

get_OS(){

	opsys=`uname -s`
	case $opsys in
	OSF1)
		PLATFORM=dec
		DISP_PLATFORM="DIGITAL UNIX"
		;;
	SunOS)
		case `uname -r` in
		4*|3*|2*|1*)
			PLATFORM=sunos
			DISP_PLATFORM="SunOS 4"
			;;
		*)
			case `uname -p` in
			sparc)
				PLATFORM=solaris
				DISP_PLATFORM="Solaris 2 (SunOS 5, sparc)"
				;;
			i386)
				PLATFORM=solx86
				DISP_PLATFORM="Solaris 2 (SunOS 5, x86)"
				;;
			esac
			;;
		esac
		;;
	IRIX*)
		PLATFORM=sgi
		DISP_PLATFORM="Silicon Graphics (IRIX)"
		;;
	AIX)
		PLATFORM=ibm
		DISP_PLATFORM="IBM (AIX)"
		;;
	HP-UX)
		PLATFORM=hp
		DISP_PLATFORM="Hewlett-Packard (HP-UX)"
		;;
	Linux)
               # We assume that an Intel-based linux system will have an x86
               # processor. We also assume that this is reported by uname -m
               # "ix86" where x is some number.
               if uname -m | grep 86 2>&1 >/dev/null ;then
                   PLATFORM=linux
                   DISP_PLATFORM="Linux"
               elif uname -m | grep -i arm 2>&1 >/dev/null  ;then
                   PLATFORM=linuxarm
                   DISP_PLATFORM="Linux (Arm)"
               else
                   echo
                   echo $setup1
                   echo
                   exit 1
               fi
               ;;
        UnixWare)
                # SCO UnixWare 7
                PLATFORM=sco
                DISP_PLATFORM="SCO Systems"
                ;;
        SCO_SV)
                # OpenServer 5
                PLATFORM=sco
                DISP_PLATFORM="SCO Systems"
                ;;
        UNIX_SV)
                # UnixWare 2.1
                PLATFORM=sco
                DISP_PLATFORM="SCO Systems"
                ;;
	*)
		echo
		echo $setup1
		echo
		exit 1
		;;
	esac
}

# =============================================================================
#
#	Online Help Script
#
# =============================================================================


# Save the invocation arguments for future use.
MYNAME=$0

# Identify the platform type.
get_OS

# Find the directory where this script is located.  This may be in an installation
# or on a distribution CD.
case $MYNAME in
/*)
        MyLocation=`dirname $MYNAME`
        ;;
*)
        MyLocation="`pwd`/`dirname $MYNAME`"
        ;;
esac

MyFullName=${MyLocation}/`basename $MYNAME`

# Check that we got that bit right...

if [ ! -r "$MyFullName" ]
then
	echo
	echo $setup2a `basename $MYNAME` $setup2b
	echo
	exit 1
fi

# Work out the type of filenames we see on the CD
setCDidfile ${MyLocation}
if [ "$CDidfile" = "" ]
then
	get_tr_key $MYNAME
fi

# Find out if this script is running from a distribution or from an installation
tr_file $TR_FILE_KEY "PkgId"
if [ -r "${MyLocation}/$TR_FILE" ]
then
	# See if there is a package for this platform on the CD.

	tr_file $TR_DIR_KEY $PLATFORM
	PLATFORM_PACKAGE_DIR=${MyLocation}/$TR_FILE

	if [ ! -d "$PLATFORM_PACKAGE_DIR" ]
	then
		echo
		echo $setup1
		echo
		exit 1
	fi

	# Setup our generic ECHO_CMD  - same syntax across all platforms
	tr_file $TR_FILE_KEY echo_cmd
	ECHO_CMD=${PLATFORM_PACKAGE_DIR}/$TR_FILE export ECHO_CMD

	# Run the installer proper
	tr_file $TR_FILE_KEY hinst
	PlatformInstaller=${PLATFORM_PACKAGE_DIR}/$TR_FILE
	exec ${PlatformInstaller} CDROM ${MyLocation}
else
	# Check we're on the correct platform
	cat ${MyLocation}/pkginf/V* | grep "^PORT=$PLATFORM" >/dev/null 2>&1
	if [ "$?" != "0" ]
	then
		echo
		echo $setup3a $DISP_PLATFORM $setup3b
		echo
		exit 1
	fi

	# Setup our generic ECHO_CMD  - same syntax across all platforms
	ECHO_CMD=${MyLocation}/util/echo_cmd export ECHO_CMD

	# And run the installer proper.
	exec ${MyLocation}/util/hinst INSTALLED ${MyLocation}
fi
##################################################################################
