#!/bin/sh
###############################################################################
#
#	Name:		Version.sh
#
#
#	Created:	May 1996
#
#	Version:	$Id: //icaclient/develop/main/UKH/NetClient/3.0UnixGFS/unix/installer/scripts/Version.sh#2 $
#
#	Purpose:	Sets shell variables for the version of Client
#			to be installed.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


INSTALLER_YES=yes
INSTALLER_NO=no
INSTALLER_QUIT=quit
INSTALLER_Y=y
INSTALLER_N=n
INSTALLER_Q=q


# Use lots of minor numbers, because a grep for 2.0 would pick up 2.0.1
ID_VERSION=3.0.0.1
# This one is for display of the version number only.
DISP_VERSION=3.0
ID_PRODUCT_NAME=CitrixICAClient
DISP_PRODUCT_NAME="Citrix ICA Client"
#!/bin/sh
###############################################################################
#
#	Name:		config.sh
#
#
#	Created:	March 1998
#
#	Version:	$Id: //depot/NetClient/3.0Unix/linux/installer/config.sh#4 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Sets shell variables for things that may be specific
#			to the host operating system.  This allows other shell
#			script parts to be generic.  To adapt the install
#			script for an additional host, you should consider
#			ALL of the lines below.  Note that for some items,
#			and incorrect value might not show up on a simple test,
#			as the scripts might not follow a path containing
#			that item.
#			 
#
#	Copyright 1998-1999 Citrix Systems, Inc.  All rights reserved.
#
###############################################################################

# Ensure we have some sort of echo command set up. setupwfc should have set
# it to use our own version that has the same syntax across all platforms.
if [ -z "$ECHO_CMD" ]
then
    ECHO_CMD=echo
fi

#  Install in here by default.
DefaultInstallDir=/usr/lib/ICAClient

#  Default CDROM mount point
DefaultCDSourceDir=/cdrom

#  The directory name on the CDROM of the platform package we are installing.
PORT=linux

#  The command to undo the archive on this platform.
EXTRACT_ARCHIVE="cpio -imud -H odc --no-preserve-owner"

# The thing that goes between the owner and group to set both by chown.
CHOWNGRP_TOKEN=":"

# The command to use to test for a symbolic link
LNKTST="test -L"

# The commands to use to change user/group of symbolic link
# In Linux, this information is included in the cpio archive
SYMCHOWN_CMD=
SYMCHGRP_CMD=

# The command to use to force a reread of inittab
READ_INITTAB_CMD="/sbin/telinit q"

# Arguments for lmhostid to get correct hostid
LMHOSTID_ARGS=ether

# The hosts file name
CAT_CMD=cat
MORE_CMD=more
CAT_HOST_ARG=/etc/hosts

# The command to read host information from NIS
YPCAT_CMD=/usr/bin/ypcat
YPCAT_HOST_ARG=hosts

# The awk command
AWK_CMD=awk
BYTES_PER_BLOCK=512
BLOCKS_PER_ALLOCATION=2
#!/bin/sh
###############################################################################
#
#	Name:		signon.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/3.0Unix/unix/installer/scripts/signon.sh#2 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Displays a sign-on message.  This module should come
#			quite early on in the script, so that the message is
#			displayed before any others, and is displayed promptly
#			rather than having to wait while the shell reads in
#			all those other functions.  Must appear after the
#			version number module.
#
#	Copyright 1996-2000 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


signon1="$DISP_PRODUCT_NAME $DISP_VERSION setup."

signon2=\
"Copyright 1996-2000 Citrix Systems, Inc. All rights reserved.\n\
\n\
Citrix, Independent Computing Architecture (ICA), MultiWin,\n\
DirectICA, WinFrame, and MetaFrame are registered trademarks or trademarks\n\
of Citrix Systems, Inc. in the U.S.A. and other countries.\n\
\n\
Microsoft, MS, MS-DOS, Windows, Windows NT, and BackOffice are\n\
either registered trademarks or trademarks of Microsoft Corporation in\n\
the United States and/or other countries.\n\
\n\
All other Trade Names referred to are the Servicemark, Trademark,\n\
or Registered Trademark of the respective manufacturers."


#
#  Sign-on early in the script, so it's reasonably quick.
#
$ECHO_CMD $signon1
$ECHO_CMD ""
$ECHO_CMD $signon2
$ECHO_CMD ""
#!/bin/sh
###############################################################################
#
#	Name:		out_bounds.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/out_bounds.sh#4 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Check that number is outside of numerical bounds.
#			If test produces error same exit status as out
#			of bounds. 
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


###############################################################################
#
#  out_of_bound ()
#
#  return exit 0 if $1 in outside of $2 and $3, or if an error occurs
#                during the testing.
#         exit 1 if $1 within $2 and $3.
#
###############################################################################

out_of_bound ()
{
	[ "$1" -ge "$2" -a "$1" -le "$3" ] > /dev/null 2>&1

	[ $? != 0 ]
	return
}
#!/bin/sh
###############################################################################
#
#	Name:		echo_c.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/echo_n.sh#5 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Provides an echo function with the trailing line-feed
#			suppressed for those platforms that need -n to do the
#			suppression.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


###############################################################################
#
#  Echo without a new line - required as a function because some platforms
#  like a \c and some like a -n to indicate that a new-line should not
#  be output.
#
###############################################################################
echo_no_nl(){
	$ECHO_CMD -n "$*"
}
#!/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.
#
###############################################################################


###############################################################################
#
#  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:		chkrun.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/chkrun.sh#9 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Checks that the user has appropriate privilege to
#			run the script.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


chkrun1a="You must be logged in as root to run the "
chkrun1b=" setup program."


check_run(){
	uid=`id | cut -d'=' -f2 | cut -d'(' -f1`
	if [ $uid != 0 ]
	then
		$ECHO_CMD $chkrun1a $DISP_PRODUCT_NAME $chkrun1b
		exit 0
	fi
}
#!/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.
#
###############################################################################


###############################################################################
#
#	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:		getyesno.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/getyesno.sh#13 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Reads input to get a simple yes/no response from the
#			user.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


getyesno1="You must answer $INSTALLER_YES or $INSTALLER_NO "

getyesno2="default"


###############################################################################
#
# getyesno keeps asking user to answer yes or no. $1 parameter passed to 
# getyesno is the default answer
#
###############################################################################
getyesno(){
ANSWER=""
while test "$ANSWER" = ""
do
	read response
	test "x$response" = "x" && response=$1
	response=`$ECHO_CMD $response | tolower`
	case $response in
	$INSTALLER_Y|$INSTALLER_YES)
		ANSWER=$INSTALLER_YES
		;;
	$INSTALLER_N|$INSTALLER_NO)
		ANSWER=$INSTALLER_NO
		;;
	*)
		ANSWER=""
		;;
	esac
	if test "$ANSWER" = ""
	then
		echo_no_nl $getyesno1
		test "$1" = "" || echo_no_nl "[$getyesno2 $1]:"
	fi
done
}
###############################################################################
#!/bin/sh
###############################################################################
#
#	Name:		chkspace.sh
#
#
#	Created:	2 March 1998
#
#	Version:	$Id:$
#
#	Coding Stds:	2.4
#
#	Purpose:	Finds the space available on the filesystem selected
#			for the installation.
#
#	Copyright 1998 Citrix Systems, Inc.  All rights reserved.
#
###############################################################################

###############################################################################
#
#  calc_space_available() calculates the space available on the filesystem
#  selected for installation.  The value available is returned in
#  SPACE_AVAILABLE in units of kilobytes.
#
###############################################################################
calc_space_available(){
	if [ -d "$INST_DIR" ]
	then
		# The installation directory exists already, so use it.
		inst_fs_dir=$INST_DIR
	else
		# The installation directory does not exist, so the value
		# required is the space on the filesystem of its parent.
		inst_fs_dir=`dirname $INST_DIR`
	fi
	SPACE_AVAILABLE=`df $inst_fs_dir | awk '
		NR==2{avail=$4}
		NR==3{avail=$3}
		END {print avail}'`
}
#!/bin/sh
###############################################################################
#
#	Name:		calcspace.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/calcspace.sh#16 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Functions to calculate the space required for an installation.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


calcspace1="\nChecking available disk space ..."

# both lines followed by size in K.
calcspace2a="\n\tDisk space available"
calcspace2b="\n\tDisk space required"

calcspace3="\n\
\n\
Insufficient disk space available.  Please make space available, or try\n\
installing on another file system.\n\
\n\
Press any key to continue: "

calcspace4="\n\
\n\
Continuing ..."


###############################################################################
#
#  calc_space_required() uses COR_SELECTED/MAN_SELECTED/CUST_SELECTED/
#  WIN_SELECTED and information in the installation .psf files to work out
#  the total space requirements for the package.
#
###############################################################################
calc_space_required(){

	tr_file $TR_FILE_KEY $PORT/$PORT.psf
	if test -f $TOPDIR/$TR_FILE 
	then
		PORT_PSF=$TOPDIR/$TR_FILE
	fi

	SPACE_REQUIRED=`$AWK_CMD '
			BEGIN {
				total = 0
				package["cor"] = "'$COR_SELECTED'"
				bytes_per_block = "'$BYTES_PER_BLOCK'"
				blocks_per_allocation = "'$BLOCKS_PER_ALLOCATION'"
				bytes_per_allocation = bytes_per_block * blocks_per_allocation
			}
			{
				if ( package[$3] == "true" )
				{
					if ( ($1 == "f") || ($1 == "d") )
					{
						blocks = ( int($NF / bytes_per_allocation) + 1 ) * blocks_per_allocation
						if ( blocks > size[$2] )
						{
							total += (blocks - size[$2])
							size[$2] = blocks
						}
					}
					else if ($1 == "s")
						total += blocks_per_allocation
				}
			}
			END {
				if (total == 0)
				{
					print 0
				}
				else
				{
        				print int ((total * bytes_per_block / 1024) + 250)
				}
			}
			' $PORT_PSF`

	$ECHO_CMD $SPACE_REQUIRED
}

################################################################################
#
# check_pkg_fits()
#
# check that there is enough room on the install file system for the 
# specifed package.
#
################################################################################

check_pkg_fits()
{
	$ECHO_CMD $calcspace1

	calc_space_available

	package_size=`calc_space_required`

	$ECHO_CMD "$calcspace2a $SPACE_AVAILABLE K $calcspace2b $package_size K"

	if [ `expr $SPACE_AVAILABLE \< $package_size` != "0" ]
	then
		echo_no_nl $calcspace3
		read dummy

		/bin/false
		return 
	fi

	$ECHO_CMD $calcspace4

	/bin/true
	return
}
#!/bin/sh
###############################################################################
#
#	Name:		inst_ica.sh
#
#
#	Created:	28 May 1996
#
#	Version:	$Id: //icaclient/develop/main/UKH/NetClient/3.0UnixGFS/unix/installer/scripts/inst_ica.sh#5 $
#
#	Coding Stds:	2.4
#
#	Purpose:	To install the ICA client.
#
#	Copyright 1996-1999 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


instica1="Installation abandoned."

# installer destination directory goes after instica2 
instica2="\nYou have chosen to install $DISP_PRODUCT_NAME $DISP_VERSION in"

instica3="\nThis is not the default location so you must set environment variable\n\
ICAROOT to this location after installation has completed."

instica4="\nProceed with installation? [default $INSTALLER_N]: "

instica5="$DISP_PRODUCT_NAME $DISP_VERSION installation abandoned."

instica6="\nContinue with installation? [default $INSTALLER_N]: "

instica7="Removal abandoned."

# installer source directory name goes between instica8a and instica8b
instica8a="\nThe directory"
instica8b="does not contain a valid installation of\n\
$DISP_PRODUCT_NAME $DISP_VERSION\n\
\n\
Removal Abandoned."

# installer destination directory name goes between instica9a and instica9b
instica9a="\nYou have chosen to remove the $DISP_PRODUCT_NAME $DISP_VERSION\n\
installation in"
instica9b="\nThis will remove all software and configuration files in this directory.\n\
\n\
Do you wish to continue with removal? [default $INSTALLER_N]: "

instica10="Removing"

# installer destination directory name goes between instica11a and instica11b
instica11a="The directory"
instica11b="could not be removed. You must try removing this directory manually."

# installer destination directory name goes between instica12a and instica12b
instica12a="Directory"
instica12b="removed."


###############################################################################
#	install_ICA_client()
#
#	Handles the installation of the ICA client from the CD (or other
#	image).  Prompts and checks the installation directory, and, if
#	necessary, gets the CD image directory.
#
###############################################################################

install_ICA_client()
{
	# make sure SourceDir and DestDir are set correctly.

	setCDSourceDir
	if [ "$SETDIR_OK" != "true" ]
	then
		$ECHO_CMD $instica1
		return 0
	fi
	setICAInstDir
	if [ "$SETDIR_OK" != "true" ]
	then
		$ECHO_CMD $instica1
		return 0
	fi

	# Confirm that we want to proceed....

	$ECHO_CMD "$instica2 $ICAInstDir."

	# Got a directory. If it's not the default location then warn the user
	# that they must set ICAROOT
	if [ "$ICAInstDir" != "$DefaultInstallDir" ]
	then
		$ECHO_CMD $instica3
	fi

	echo_no_nl $instica4

	getyesno $INSTALLER_NO
	if [ "$ANSWER" != "$INSTALLER_YES" ]
	then
		$ECHO_CMD $instica5
		return
	fi

	# OK, got CDSourceDir and ICAInstDir, so do the installation

	# first display the End-User License Agreement which the user must
	# accept before installation can proceed

	$ECHO_CMD

	tr_file $TR_FILE_KEY eula.txt
	$MORE_CMD $CDSourceDir/$TR_FILE

	echo_no_nl $instica6
	getyesno $INSTALLER_NO
	if [ "$ANSWER" != "$INSTALLER_YES" ]
	then
		$ECHO_CMD $instica5
		return
	fi

	# Create a directory for the client to store its license, then generate
        # a license file.

	create_dir /etc/icalicense

        if [ ! -f /etc/icalicense/clientlicense ]
        then
                $ECHO_CMD -l >/etc/icalicense/clientlicense
        fi
        chmod 444 /etc/icalicense/clientlicense
	chmod 555 /etc/icalicense

	# Always install core package

	COR_SELECTED=true
	install_packages $CDSourceDir $ICAInstDir 
	COR_SELECTED=false

        # Integrate with netscape
        netscape_integrate
}

###############################################################################
#
#	remove_ICA_client()
#
#	Handles the removal of the ICA client from
#	Prompts and checks the installation directory, and removes it.
#
###############################################################################

remove_ICA_client()
{
	# make sure we know where the installation is.

	setICAInstDirForMod
	if [ "$SETDIR_OK" != "true" ]
	then
		$ECHO_CMD $instica7
		return 0
	fi

	# Check that this directory does indeed contain an installation
        # that we recognise.
	version_ok=`inst_version_ok "$ICAInstDir"`

	if [ "$version_ok" != "true" ]
	then
		# Directory does not contain a valid installation.
		$ECHO_CMD "$instica8a $ICAInstDir $instica8b"
		return 0
	fi

	# Directory looks OK - confirm before proceeding

	echo_no_nl "$instica9a $ICAInstDir $instica9b"

	getyesno $INSTALLER_NO
	if [ "$ANSWER" != "$INSTALLER_YES" ]
	then
		$ECHO_CMD $instica7
		return 0
	fi

	# OK - go for it and remove the installation.

        # disintegrate from netscape
        netscape_disintegrate

	$ECHO_CMD "$instica10 $ICAInstDir"

	# Change directory.  Some platforms will not remove current dir.
	cd /
	rm -rf "$ICAInstDir"
	if [ -d "$ICAInstDir" ]
	then
		echo
		echo "$instica11a $ICAInstDir $instica11b"
		echo
	else
		echo
		echo "$instica12a $ICAInstDir $instica12b"
		echo
	fi

	exit
}
###############################################################################
#!/bin/sh
###############################################################################
#
#	Name:		fileutil.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/fileutil.sh#9 $
#
#	Coding Stds:	2.4
#
#	Purpose:	General utilities to make it easier to backup or
#			move files.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


# the 'old' filename goes between fileutil1a and fileutil1b.
# the 'new' filename goes after fileutil1b.
fileutil1a="Cannot copy"
fileutil1b="to"

fileutil2="Error creating backup file"

fileutil3="backed up to"


###############################################################################
#
#  create_new_filename() makes up a new filename suitable for temporary work
#  or for backup.  The function takes a single parameter which should
#  be a legal filename (absolute or relative to the current directory).
#  The new filename is the given name with a numerical suffix which does
#  not already exist.
#
###############################################################################
create_new_filename(){
	filename_root=$1
	extension=1
	NEW_FILENAME=""
	while true
	do
		next_filename=${filename_root}.${extension}
		# Test for the filename already used.  The first (read) test
		# will catch most cases, but we also need to explicitly check
		# for the various file types, because there is no single
		# simple test to see if a particular filename is in use.
		if	   test -r "$next_filename" \
			|| test -f "$next_filename" \
			|| test -d "$next_filename" \
		 	|| test -c "$next_filename" \
			|| test -b "$next_filename" \
			|| test -p "$next_filename" \
			|| $LNKTST "$next_filename"
		then
			extension=`expr $extension + 1`
		else
			NEW_FILENAME=$next_filename
			break
		fi
	done
}
	

###############################################################################
#
#  backup_file() takes one parameter.  This must be the name of an existing
#  file.  A copy is made of the file, and the name of the new file returned
#  in BACKUP_FILENAME.  If there is some error in making the copy, FAIL_MSG
#  is set, and the backup file removed.
#
###############################################################################
backup_file(){
	BACKUP_OK=false
	OLD_FILENAME=$1
	create_new_filename $OLD_FILENAME

	cp $OLD_FILENAME $NEW_FILENAME
	if [ ! -f "$NEW_FILENAME" ]
	then
		FAIL_MSG="$fileutil1a $OLD_FILENAME $fileutil1b $NEW_FILENAME"
		return
	fi
	cmp -s $OLD_FILENAME $NEW_FILENAME
	if [ "$?" != "0" ]
	then
		FAIL_MSG="$fileutil2 $NEW_FILENAME"
		rm -f $NEW_FILENAME
		return
	fi
	$ECHO_CMD "$OLD_FILENAME $fileutil3 $NEW_FILENAME"
	BACKUP_FILENAME=$NEW_FILENAME
	BACKUP_OK=true
}
#!/bin/sh
###############################################################################
#
#	Name:		dir_util.sh
#
#
#	Created:	28 May 1996
#
#	Version:	$Id: //icaclient/develop/main/UKH/NetClient/3.0UnixGFS/unix/installer/scripts/dir_util.sh#1 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Functions for obtaining, checking and creating
#			the directories required for installation.
#
#	Copyright 1996-1999 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


# the installer source directory and ']' goes between dirutil1a and dirutil1b.
dirutil1a="\n\
Enter the location of your $DISP_PRODUCT_NAME $DISP_VERSION CDROM\n\
or installable image [default"
dirutil1b="\nor type \"$INSTALLER_QUIT\" to abandon the installation: "

dirutil2="\nCannot access"

# the installer source directory goes between dirutil3a and dirutil3b.
dirutil3a="\nThe directory" 
dirutil3b="\ndoes not contain a $DISP_PRODUCT_NAME $DISP_VERSION package."

# the installer destination directory and ']' goes between dirutil4a and dirutil4b.
dirutil4a="\nPlease enter the directory in which $DISP_PRODUCT_NAME is to be installed.\n\
[default"
dirutil4b="\nor type \"$INSTALLER_QUIT\" to abandon the installation: "

dirutil5="\nThis directory already exists.\n\
You must choose a directory name that does not exist."

# the installer destination directory goes between dirutil6a and dirutil6b.
dirutil6a="\nShould I use the name"
dirutil6b="instead? [default $INSTALLER_Y]: "

dirutil7="\nAn installation of $DISP_PRODUCT_NAME\n\
already exists in this directory. Re-installing will\n\
overwrite that installation and all its configuration.\n\
\n\
Do you wish to proceed? [default $INSTALLER_N]: "

# the installer destination directory goes between dirutil8a and dirutil8b.
dirutil8a="\nCannot create directory\n\t"
dirutil8b="A file with this name already exists."

# the installer destination directory goes between dirutil9a and dirutil9b.
dirutil9a="\nThe parent directory"
dirutil9b="does not exist.\nDo you want it to be created? [default $INSTALLER_Y]: "

# the installer destination directory goes between dirutil10a and dirutil10b.
dirutil10a="\nThe directory"
dirutil10b="\ndoes not contain a valid $DISP_PRODUCT_NAME $DISP_VERSION\n\
installation."

# the (modified or removed) installer destination directory goes between 
# dirutil11a and dirutil11b.
dirutil11a="\nThe directory"
dirutil11b="\ndoes not exist."

# the (modified or removed) installer destination directory goes between 
# dirutil12a and dirutil12b.
dirutil12a="\nPlease enter the directory containing the\n\
$DISP_PRODUCT_NAME $DISP_VERSION installation.\n\
[default"
dirutil12b="\nor type \"$INSTALLER_QUIT\" to return to the menu: "

dirutil13="User $INSTALLER_QUIT operation"


###############################################################################
#
#	rm_last_dot()
#
#	Removes a trailing /. from a filename given to it.
#	This is essential, because rm refuses to act on paths ending in /.
#	It also looks neater when displaying paths.
#
###############################################################################

rm_last_dot(){
	<&0 sed 's/\/.$//' >&1
}


###############################################################################
#
#	setCDSourceDir()
#
#	Sets the variable CDSourceDir.  This may be done automatically if the
#	this script is being run from the CDROM.  Otherwise we must prompt the
#	user for the location of the CDROM (or installable image).
#
###############################################################################

setCDSourceDir()
{
	SETDIR_OK=false
	# Check we haven't already done it - if we have, there's nothing to do.
	if [ "$CDSourceDir" != "" ]
	then
		SETDIR_OK=true
		return
	fi

	if [ "$RunningFrom" = "CDROM" ]
	then
		# Running from CDROM, so we can determine the CDROM directory
		# automatically.
		CDSourceDir=$TopDir
		SETDIR_OK=true
		return
	fi
	# Don't have a directory, so need to prompt for it.
	CDSourceDir=$DefaultCDSourceDir
	got_directory=false
	while [ "$got_directory" = "false" ]
	do
		echo_no_nl "$dirutil1a $ICAInstDir] $dirutil1b"
		read newCDSourceDir
		if [ "x$newCDSourceDir" != "x" ]
		then
			CDSourceDir=$newCDSourceDir
		fi
		if [ "x$CDSourceDir" = "x$INSTALLER_QUIT" ]
		then
			FAIL_MSG=$dirutil13
			return
		fi

		if [  ! -d "$CDSourceDir" ]
		then
			$ECHO_CMD "$dirutil2 $CDSourceDir."
			continue
		fi

		# Got a directory
		# Do a quick check that it looks like our image.
		setCDidfile $CDSourceDir
		if [ "$CDidfile" = "" ]
		then
			$ECHO_CMD "$dirutil3a $CDSourceDir $dirutil3b"
			continue
		fi
		egrep '^ID_PRODUCT_NAME' $CDidfile 2>&1 | egrep '='"$ID_PRODUCT_NAME" > /dev/null 2>&1
		if [ "$?" != "0" ]
		then
			$ECHO_CMD "$dirutil3a $CDSourceDir $dirutil3b"
			continue
		fi
		egrep '^ID_VERSION' $CDidfile 2>&1 | egrep '='"$ID_VERSION" > /dev/null 2>&1
		if [ "$?" != "0" ]
		then
			$ECHO_CMD "$dirutil3a $CDSourceDir $dirutil3b"
			continue
		fi
		# Looks like this directory is OK
		got_directory=true
	done
	SETDIR_OK=true
}

###############################################################################
#
#	setICAInstDir()
#
#	Sets the variable ICAInstDir, to a directory in which to install the
#	client package.   We should always prompt for this, even
#	if we are running from the installed package directory, as the user
#	may want to install somewhere else.
#
###############################################################################

setICAInstDir()
{
	SETDIR_OK=false
	# Set up a suitable default location.
	if [ "$ICAInstDir" = "" ]
	then
		if [ "$RunningFrom" = "INSTALLED" ]
		then
			ICAInstDir=$TopDir
		else
			ICAInstDir=$DefaultInstallDir
		fi
	fi

	got_directory=false
	while [ "$got_directory" = "false" ]
	do
		echo_no_nl "$dirutil4a $ICAInstDir] $dirutil4b"
		read newICAInstDir
		if [ "x$newICAInstDir" = "x$INSTALLER_QUIT" ]
		then
			FAIL_MSG=$dirutil13
			return
		fi
		if [ "x$newICAInstDir" != "x" ]
		then
			ICAInstDir="$newICAInstDir"
		fi

		# Got a directory.

		if [ -d "$ICAInstDir" ]
		then
			if [ `inst_version_ok "$ICAInstDir"` != "true" ]
			then
				# Directory exists but it's not ours
				$ECHO_CMD $dirutil5
				tryDir="$ICAInstDir/"`basename $DefaultInstallDir`
				if [ ! -r "$tryDir" ]
				then
					echo_no_nl "$dirutil6a $tryDir $dirutil6b"
					getyesno $INSTALLER_YES
					if test $ANSWER = $INSTALLER_YES
					then
						ICAInstDir="$tryDir"
						got_directory=true
					else
						continue
					fi
				fi
			else
				echo_no_nl $dirutil7
				getyesno $INSTALLER_NO
				if [ "$ANSWER" != "$INSTALLER_YES" ]
				then
					return
				fi
				# Install over the existing installation
				got_directory=true
			fi
		else
			# Directory doesn't exist already
			# Quick check there's nothing else with that name
			if [ -r "$ICAInstDir" ]
			then
				$ECHO_CMD "$dirutil8a $ICAInstDir $dirutil8b"
				continue
			fi
			# OK - the directory isn't there
			parent_dir=`dirname "$ICAInstDir"`
			if [ -d "$parent_dir" ]
			then
				got_directory=true
			else
				echo_no_nl "$dirutil9a $parent_dir $dirutil9b"
				getyesno $INSTALLER_YES
				if [ "$ANSWER" = "$INSTALLER_YES" ]
				then
					create_dir $parent_dir
					if [ "$?" = "0" ]
					then
						got_directory=true
					fi
				fi
			fi
		fi
	done
	SETDIR_OK=true
}

###############################################################################
#
#	setICAInstDirForMod()
#
#	Sets the variable ICAInstDir, to a directory containing a client
#	package for modification or removal of the package.
#
###############################################################################

setICAInstDirForMod()
{
	SETDIR_OK=false
	# Set up a suitable default location.
	if [ "$ICAInstDir" = "" ]
	then
		if [ "$RunningFrom" = "INSTALLED" ]
		then
			newICAInstDir=$TopDir
		else
			newICAInstDir=$DefaultInstallDir
		fi
	else
		newICAInstDir="$ICAInstDir"
	fi

	got_directory=false
	while [ "$got_directory" = "false" ]
	do
		if [ -d "$newICAInstDir" ]
		then
			if [ `inst_version_ok "$newICAInstDir"` = "true" ]
			then
				ICAInstDir="$newICAInstDir"
				got_directory=true
				continue
			fi
			echo_no_nl "$dirutil10a $newICAInstDir $dirutil10b"
		else
			$ECHO_CMD "$dirutil11a $newICAInstDir $dirutil11b"
		fi
		
		echo_no_nl "$dirutil12a $newICAInstDir] $dirutil12b"
		read inICAInstDir
		if [ "x$inICAInstDir" = "x$INSTALLER_QUIT" ]
		then
			FAIL_MSG=$dirutil13
			return
		fi
		if [ "x$inICAInstDir" != "x" ]
		then
			newICAInstDir="$inICAInstDir"
		fi
	done
	# Got a directory
	SETDIR_OK=true
	return 0
}

#!/bin/sh
###############################################################################
#
#	Name:		util_ver.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/util_ver.sh#8 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Utilities for creting and checking version information
#			for both CD image and installation.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


###############################################################################
#
#  put_version_info() creates version information in the installed package,
#  for later checking of the version and possibly for upgrading the package.
#
#  Takes four parameters:
#	package information filename (.psf file)
#	package data file
#	sub-package type (core/man/cus)
#	sub-package section (base/local/port)
#
#  The two filename parameters are assumed to already be expanded to full
#  pathnames, with any required name mappings completed.
#
###############################################################################
put_version_info(){
	pvi_package_info_file=$1
	pvi_package_data_file=$2
	pvi_package_type=$3
	pvi_package_section=$4

	pvi_output_dir=$INST_DIR/pkginf
	create_dir $pvi_output_dir

	pvi_output_file=${pvi_output_dir}/Ver.${pvi_package_type}.${pvi_package_section}

	$ECHO_CMD "ID_VERSION=$CurrentIDVER"	          >  $pvi_output_file
	$ECHO_CMD "DISP_VERSION=$CurrentDISPVER"	  >> $pvi_output_file
	$ECHO_CMD "ID_PRODUCT_NAME=$CurrentIDNAME"     >> $pvi_output_file
	$ECHO_CMD "DISP_PRODUCT_NAME=$CurrentDISPNAME" >> $pvi_output_file
	$ECHO_CMD "uname=`uname -a`"			  >> $pvi_output_file
	$ECHO_CMD "PORT=$PORT"			  >> $pvi_output_file
	if [ "$HOST_DATE_COMMAND" != "" ]
	then
		$ECHO_CMD "date=`$HOST_DATE_COMMAND`"	>> $pvi_output_file
	else
		$ECHO_CMD "date=`date '+%Y:%m:%d:%H:%M:%S %Z' | sed 's/://g'`"	>> $pvi_output_file
	fi
	$ECHO_CMD "INFO_FILE=$pvi_package_info_file"	>> $pvi_output_file
	$ECHO_CMD "DATA_FILE=$pvi_package_data_file"	>> $pvi_output_file
	
	pkg_files_rec=${pvi_output_dir}/F.${pvi_package_type}.${pvi_package_section}
	echo_no_nl > $pkg_files_rec
	cat $pvi_package_info_file | (
		while read line
		do
			set $line
			psf_package_type=$3
			if [ "$psf_package_type" = "$pvi_package_type" ]
			then
				$ECHO_CMD "$line" >> $pkg_files_rec
			fi
		done
	)
	chmod 644 $pvi_output_file $pkg_files_rec
}

###############################################################################
#
#  inst_version_ok() sees if an installation is suitable for overwriting
#  with this installer.  Returns 'true' if it is OK, 'false' otherwise.
#  Takes one parameter, which is the directory containing the installation.
#
###############################################################################
# The root of the version information file names.
inst_version_ok(){
	root_inst_dir=$1
	ver_file=${root_inst_dir}/pkginf/Ver.core.$PORT
	
	if [ ! -r $ver_file ]
	then
		# Can't find the file - installed version doesn't match
		$ECHO_CMD false >&1
		return
	fi
	
	egrep '^ID_PRODUCT_NAME' $ver_file 2>&1 | fgrep '='"$ID_PRODUCT_NAME" > /dev/null 2>&1
	if [ "$?" = "0" ]
	then
		# Product name matches
		egrep '^ID_VERSION' $ver_file 2>&1 | fgrep '='"$ID_VERSION" > /dev/null 2>&1
		if [ "$?" = "0" ]
		then
			# files contain this product name and version number
			# - we've got a match
			$ECHO_CMD true >&1
			return
		fi
	fi
	# file contains another name or version number
	$ECHO_CMD false >&1
	return
}

#!/bin/sh
###############################################################################
#
#	Name:		crdir.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/crdir.sh#5 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Creates a directory and any necessary parents.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


###############################################################################
#
#  create_dir() creates a directory and any required parent directories.
#
#  This shell function is necessary on HP because of a bug with mkdir -p
#  that means that you cannot do mkdir -p on an automounted file system
#  What we have to do is manually create each directory in turn.
#  It returns 0 in $RETVAL if successful, otherwise 1 in $RETVAL
#
###############################################################################
create_dir(){
	TARGET_DIR=$1
	CURR_DIR=""
	# Turn /'s into spaces to get list of parent directories
	DIR_LIST=`$ECHO_CMD $TARGET_DIR | sed 's/\// /g'`

	# For each directory in the path, starting from the top, if it
	# doesn't exist, create it.
	for dir in $DIR_LIST
	do
		CURR_DIR=$CURR_DIR/$dir
		test -d $CURR_DIR || mkdir $CURR_DIR 2>/dev/null
	done
	# The target directory should now be made. If not return an error
	# in RETVAL
	RETVAL=0
	test -d $TARGET_DIR || RETVAL=1
}
#!/bin/sh
###############################################################################
#
#	Name:		instpkgs.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //icaclient/develop/main/UKH/NetClient/3.0UnixGFS/unix/installer/scripts/instpkgs.sh#1 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Installs the required parts of the ICA Client.
#
#	Copyright 1996-1999 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


instpkgs1="Installation proceeding..."

# instpkgs is followed by the name of a directory, e.g. /usr/lib/ICAClient
instpkgs2="Creating directory"

# instpkgs3a is followed by the name of a directory, e.g. /usr/lib/ICAClient
instpkgs3a="\nCannot create directory"
instpkgs3b="\nInstallation aborted."

instpkgs4="Core package..."

instpkgs5="Setting file permissions..."


#
# first parameter is the .psf filename
# second parameter is the data filename
# third parameter is the type of the sub-package (core/man/cus)
# fourth parameter is the section of the package (base/local/port)
#
install_one_pkg(){
	package_info_file=$1
	package_data_file=$2
	package_type=$3
	package_section=$4

	# Map both the filenames to real filenames

	tr_file $TR_FILE_KEY $package_info_file
	package_info_file=$TOPDIR/$TR_FILE
	tr_file $TR_FILE_KEY $package_data_file
	package_data_file=$TOPDIR/$TR_FILE

	# unpackage the data
	if [ -f "$package_data_file" ]
	then
		$EXTRACT_ARCHIVE < $package_data_file
	fi

	# Put some version information relating to this part of the package
	# into the installation.
	put_version_info $package_info_file $package_data_file $package_type $package_section
}
#####################################################################
#   selectively set mod and grp/user for entries in .psf file       #
#####################################################################

set_mod_and_grp()
{
	# This function sets the group/user ownership and status for the files
	# listed in the .psf file pointed to by TR_FILE. It only attempts to
	# act on a file if the package (cor | cus | man | win) has be selected
	# for installation.

	cat $TOPDIR/$TR_FILE | (
		while read line
		do
		        # Parse input line
			set $line
			filetype=$1
			filename=$2
			case $filetype in
			s|h)
			    realfilename=$3
			    shift;
			    ;;
			d|f)
			    ;;
			esac
			
			filepackage=$3
			filemode=$4
			fileown=$5
			filegrp=$6
			
			# Set the Package type
			case $filepackage in
			cor)
				PACKAGE_SELECTED=$COR_SELECTED
				;;
			*)
			        PACKAGE_SELECTED=false
			esac
			
			# Modify the system group name if it isn't sys on
			# this type of machine
			if [ "$HOST_SYS_GROUP_NAME" != "" -a "$filegrp" = "sys" ]
			then
				filegrp=$HOST_SYS_GROUP_NAME
			fi
			
			# Process the line if it is in an appropriate package
			if [ "$PACKAGE_SELECTED" = "true" ]
			then
				case $filetype in
				s)
				    # Setting the symbolic link permissions 
				    # has no meaning here as it only sets
				    # the permissions of the actual file
				    if [ "$SYMCHOWN_CMD" ] ; then
					$SYMCHOWN_CMD $fileown $INST_DIR/$filename
				    fi
				    if [ "$SYMCHGRP_CMD" ] ; then
					$SYMCHGRP_CMD $filegrp $INST_DIR/$filename
				    fi	
				    ;;
				h)
				    # It makes no sense to change hardlinks, as
				    # this would change the original file
				    # attributes also
				    ;;
				d|f)
					chmod $filemode $INST_DIR/$filename
					chown $fileown $INST_DIR/$filename
					chgrp $filegrp $INST_DIR/$filename
					;;
				esac
			fi
		done 
	)
}
###############################################################################
#
#  install_packages() Installs the packages selected by
#  COR_SELECTED/MAN_SELECTED/CUST_SELECTED/WIN_SELECTED into INST_DIR
#
###############################################################################
install_packages(){
	$ECHO_CMD $instpkgs1
	TOPDIR=$1
	INST_DIR=$2

	# Check that there is enough space ...
	if check_pkg_fits 
	then
		:
	else
		/bin/false
		return 
	fi

	if [ ! -d "$INST_DIR" ]
	then
		$ECHO_CMD "$instpkgs2 $INST_DIR"
		create_dir $INST_DIR
		if [ ! -d "$INST_DIR" ]
		then
			$ECHO_CMD "$instpkgs3a $INST_DIR $instpkgs3b"
			exit 1
		fi
	fi
	cd $INST_DIR

	if test "$COR_SELECTED" = "true"
	then
		$ECHO_CMD $instpkgs4
		CurrentIDNAME="$ID_PRODUCT_NAME"
		CurrentIDVER="$ID_VERSION"
		CurrentDISPNAME="$DISP_PRODUCT_NAME"
		CurrentDISPVER="$DISP_VERSION"
		install_one_pkg $PORT/$PORT.psf $PORT/$PORT.cor core $PORT
#		tr_file $TR_FILE_KEY readme.txt
#		cp $TOPDIR/$TR_FILE $INST_DIR/readme
#		chmod 444 $INST_DIR/readme

		# make this a server installation (separate config files for each user)
		touch $INST_DIR/config/.server
		chmod 444 $INST_DIR/config/.server
	fi

	if [ "$PRODUCING_SMIT_TREE" != "true" ]
	then
		$ECHO_CMD $instpkgs5
		# Now look at the .psf files and change the permissions and
		# ownerships of all the files as specified.
		
		# We need four temporary files to enable the caching chown type
		# functions to work.  These files will contain a mode, a list of
		# filenames for which the mode needs to be changed, an owner/group
		# combination, and a list of filenames to have the owner and
		# group changed.
	
		tr_file $TR_FILE_KEY $PORT/$PORT.psf
		set_mod_and_grp
	fi

	# rm -f $m_filename $mf_filename $o_filename $of_filename
}
#!/bin/sh
###############################################################################
#
#       Name:           setup-netscape.sh
#
#
#       Created:        Oct 1999
#
#       Version:        $Id: //icaclient/develop/main/ukh/NetClient/3.0UnixGFS/unix/installer/scripts/setup-netscape.sh#3 $
#
#       Purpose:        Installs wfica as a helper application for Netscape,
#                       and adds new mime type.
#
#       Copyright 1999 Citrix Systems, Inc. All rights reserved.
#
###############################################################################

integrate_netscape1="Integrating with Netscape browser..."

integrate_netscape2="\nCould not find an installation of Netscape on your system.\n\
Is Netscape installed? [default $INSTALLER_N]: "

integrate_netscape3="Netscape found."

integrate_netscape4="\nFound entries in Netscape configuration from an earlier installation.\n\
Do you want these entries to point to the new installation? [default $INSTALLER_Y]: "

integrate_netscape5="\nIntegration complete."

integrate_netscape6="\nIntegration cancelled."

disintegrate_netscape1="\nThe Netscape configuration has entries referring to \
the Citrix ICA Client.\n\
Remove references to the ICA Client? [default $INSTALLER_Y]: "

disintegrate_netscape2="Netscape's references to the ICA client removed.\n"

INST_DIR=$ICAInstDir
TMP_NAME=/tmp/ICAnetscape.$$
NETSCAPE_DIR="/usr/local/lib/netscape"

op_system=`uname -s`

case $op_system in
OSF1)
	ALT_INSTALL=1
	ALT_NETSCAPE_DIR="/usr/lib/netscape"
	;;
IRIX*)
	ALT_INSTALL=1
	ALT_NETSCAPE_DIR="/var/netscape/communicator"
	;;
*)
	ALT_INSTALL=0
	;;
esac

###############################################################################
#
#	netscape_integrate()
#
#	This function is called to add entries to Netscape configuration files
#	to support charlotte. The following is added:
#
#	${NETSCAPE_DIR}/mailcap:
#	application/x-ica; /usr/lib/ICAClient/wfica -file %s
#
#	${NETSCAPE_DIR}/mime.types:
#	type=application/x-ica exts=ica
#
###############################################################################

netscape_integrate()
{
  $ECHO_CMD $integrate_netscape1
  search_ok=0
  
  if (test -d "/usr/lib/netscape"\
   || test -d "/usr/local/netscape"\
   || test -d "/opt/netscape"\
   || test -d "/usr/local/lib/netscape")
  then
  	$ECHO_CMD $integrate_netscape3
  	found_netscape 
  else
	echo_no_nl $integrate_netscape2
 	getyesno $INSTALLER_NO
	if [ "$ANSWER" = "$INSTALLER_YES" ]
	then
		found_netscape
	else
  		$ECHO_CMD $integrate_netscape6
	fi
  fi;
}

################################################################################
#
#	found_netscape()
#
#	Sub-function, called by Netscape_integrate to do it's dirty work. Do
#	not call this function separately.
#
################################################################################
found_netscape()
{
  ALREADY_MIMETYPE=0
  ALREADY_MAILCAP=0
  # Ensure the directory exists
  if [ ! -d ${NETSCAPE_DIR} ]
  then
	create_dir ${NETSCAPE_DIR}
  fi
  # does mailcap exist ?
  if [ ! -f ${NETSCAPE_DIR}/mailcap ]
  then
	$ECHO_CMD "# ${NETSCAPE_DIR}/mailcap" >${NETSCAPE_DIR}/mailcap
  fi
  # does mime.types exist ?
  if [ ! -f ${NETSCAPE_DIR}/mime.types ]
  then
	# mime.types must have a distinctive string on the first line...
	$ECHO_CMD "#--Netscape Communications Corporation MIME Information" >${NETSCAPE_DIR}/mime.types
  fi
  # does mime.types already contain our line?
  if grep application/x-ica ${NETSCAPE_DIR}/mime.types >/dev/null
  then   
	ALREADY_MIMETYPE=1
  fi
  # does mailcap already contain our line?
  if grep application/x-ica ${NETSCAPE_DIR}/mailcap >/dev/null
  then
        ALREADY_MAILCAP=1
  fi
  if test $ALREADY_MIMETYPE -eq 1 || test $ALREADY_MAILCAP -eq 1
  then
	echo_no_nl $integrate_netscape4
	getyesno $INSTALLER_YES
        if [ "$ANSWER" = "$INSTALLER_YES" ]
	then
		if test $ALT_INSTALL -eq 1
		then
			alt_integrate
		fi
		if [ $ALREADY_MAILCAP -eq 1 ]
		then
			sed '/x-ica/d' ${NETSCAPE_DIR}/mailcap >${TMP_NAME}
			mv ${TMP_NAME} ${NETSCAPE_DIR}/mailcap
		fi

		if [ $ALREADY_MIMETYPE -eq 1 ]
		then
			sed '/x-ica/d' ${NETSCAPE_DIR}/mime.types >${TMP_NAME}
			mv ${TMP_NAME} ${NETSCAPE_DIR}/mime.types
		fi

		$ECHO_CMD "application/x-ica; ${INST_DIR}/wfica -file %s" >>${NETSCAPE_DIR}/mailcap
		$ECHO_CMD "type=application/x-ica exts=ica" >>${NETSCAPE_DIR}/mime.types	
  		$ECHO_CMD $integrate_netscape5
	else
  		$ECHO_CMD $integrate_netscape6
        fi
  else
	if test $ALT_INSTALL -eq 1
	then
		alt_integrate
	fi
	$ECHO_CMD "application/x-ica; ${INST_DIR}/wfica -file %s" >>${NETSCAPE_DIR}/mailcap
	$ECHO_CMD "type=application/x-ica exts=ica" >>${NETSCAPE_DIR}/mime.types	
  	$ECHO_CMD $integrate_netscape5
  fi
}

###########################################################################
#
#	netscape_disintegrate()
#
#	This functions checks if we have updated Netscape's configuration.
#	If so, we offer to undo these changes.
#
###########################################################################

netscape_disintegrate()
{
  MAILCAP_MODIFIED=0
  MIMETYPES_MODIFIED=0

  # Does file exist?
  if [ -f ${NETSCAPE_DIR}/mime.types ]
  then
	# Has it been altered?
	if grep application/x-ica ${NETSCAPE_DIR}/mime.types >/dev/null
  	then
        	MIMETYPES_MODIFIED=1
	fi
  fi

  # Does file exist?
  if [ -f ${NETSCAPE_DIR}/mailcap ]
  then
	# Has it been altered?
	if grep application/x-ica ${NETSCAPE_DIR}/mailcap >/dev/null
	then
		MAILCAP_MODIFIED=1
	fi
  fi

  if test $MIMETYPES_MODIFIED -eq 1 || test $MAILCAP_MODIFIED -eq 1
  then
        echo_no_nl $disintegrate_netscape1
        getyesno $INSTALLER_YES
        if [ "$ANSWER" = "$INSTALLER_YES" ]
	then
		if test $ALT_INSTALL -eq 1
		then
			alt_disintegrate
		fi
		if [ $MAILCAP_MODIFIED -eq 1 ]
		then
			sed '/x-ica/d' ${NETSCAPE_DIR}/mailcap >${TMP_NAME}
			mv ${TMP_NAME} ${NETSCAPE_DIR}/mailcap
		fi

		if [ $MIMETYPES_MODIFIED -eq 1 ]
                then
                        sed '/x-ica/d' ${NETSCAPE_DIR}/mime.types >${TMP_NAME}
                        mv ${TMP_NAME} ${NETSCAPE_DIR}/mime.types
                fi
  		$ECHO_CMD $disintegrate_netscape2
	fi
  fi
}

################################################################################
#
#       alt_integrate()
#
#       special cases: IRIX and DEC. We add prefs to an additional location
#
################################################################################
alt_integrate()
{
  ALREADY_MIMETYPE2=0
  ALREADY_MAILCAP2=0
  # Ensure the directory exists
  if [ ! -d ${ALT_NETSCAPE_DIR} ]
  then
        create_dir ${ALT_NETSCAPE_DIR}
  fi
  # does mailcap exist ?
  if [ ! -f ${ALT_NETSCAPE_DIR}/mailcap ]
  then
        $ECHO_CMD "# ${ALT_NETSCAPE_DIR}/mailcap" >${ALT_NETSCAPE_DIR}/mailcap
  fi
  # does mime.types exist ?
  if [ ! -f ${ALT_NETSCAPE_DIR}/mime.types ]
  then
        # mime.types must have a distinctive string on the first line...
        $ECHO_CMD "#--Netscape Communications Corporation MIME Information" >${ALT_NETSCAPE_DIR}/mime.types
  fi
  # does mime.types already contain our line?
  if grep application/x-ica ${ALT_NETSCAPE_DIR}/mime.types >/dev/null
  then
        ALREADY_MIMETYPE2=1
  fi
  # does mailcap already contain our line?
  if grep application/x-ica ${ALT_NETSCAPE_DIR}/mailcap >/dev/null
  then
        ALREADY_MAILCAP2=1
  fi
  if test $ALREADY_MIMETYPE2 -eq 1 || test $ALREADY_MAILCAP2 -eq 1
  then
        if [ $ALREADY_MAILCAP2 -eq 1 ]
        then
        	sed '/x-ica/d' ${ALT_NETSCAPE_DIR}/mailcap >${TMP_NAME}
                mv ${TMP_NAME} ${ALT_NETSCAPE_DIR}/mailcap
        fi

        if [ $ALREADY_MIMETYPE2 -eq 1 ]
        then
                sed '/x-ica/d' ${ALT_NETSCAPE_DIR}/mime.types >${TMP_NAME}
                mv ${TMP_NAME} ${ALT_NETSCAPE_DIR}/mime.types
        fi
  fi
  $ECHO_CMD "application/x-ica; ${INST_DIR}/wfica -file %s" >>${ALT_NETSCAPE_DIR}/mailcap
  $ECHO_CMD "type=application/x-ica exts=ica" >>${ALT_NETSCAPE_DIR}/mime.types
}

###########################################################################
#
#       alt_disintegrate()
#
#       Special cases: IRIX and DEC. We uninstall from a second location.
#
###########################################################################

alt_disintegrate()
{
  # Does file exist?
  if [ -f ${ALT_NETSCAPE_DIR}/mime.types ]
  then
        # Has it been altered?
        if grep application/x-ica ${ALT_NETSCAPE_DIR}/mime.types >/dev/null
        then
                sed '/x-ica/d' ${ALT_NETSCAPE_DIR}/mime.types >${TMP_NAME}
                mv ${TMP_NAME} ${ALT_NETSCAPE_DIR}/mime.types
        fi
  fi

  # Does file exist?
  if [ -f ${ALT_NETSCAPE_DIR}/mailcap ]
  then
        # Has it been altered?
        if grep application/x-ica ${ALT_NETSCAPE_DIR}/mailcap >/dev/null
        then
        	sed '/x-ica/d' ${ALT_NETSCAPE_DIR}/mailcap >${TMP_NAME}
                mv ${TMP_NAME} ${ALT_NETSCAPE_DIR}/mailcap
        fi
  fi
}
#!/bin/sh
###############################################################################
#
#	Name:		menus.sh
#
#
#	Created:	May 1996 1995
#
#	Version:	$Id: //depot/NetClient/3.0Unix/unix/installer/scripts/menus.sh#2 $
#
#	Coding Stds:	2.4
#
#	Purpose:	Displays menus for ICA Client installer.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################

menus1=\
"\n\
Select a setup option:\n\
\n\
  1.   Install $DISP_PRODUCT_NAME $DISP_VERSION\n\
  2.   Remove $DISP_PRODUCT_NAME $DISP_VERSION\n\
  3.   Quit $DISP_PRODUCT_NAME $DISP_VERSION setup\n"

menus2="Enter option number"

menus3="Invalid Entry"


###############################################################################
#
#  main_install_menu()
#
#  Displays a menu of the available options, and calls functions for each.
#
###############################################################################
main_install_menu(){

		keyDefault=1
		while true
		do
			#
			# Get the Function the user wants to perform
			#
			menuItems=3

			$ECHO_CMD $menus1
			echo_no_nl "$menus2 1-$menuItems [$keyDefault]: "
			read keynum

			if test "x$keynum" = "x"
			then 
				keynum=$keyDefault 
			fi

# CPR183 : "setupwfc crashes if ! Is entered in the setup options menu."
# ! might not be the only character that can cause problems, we should
# really strip out anything that's not 0-9 and q. And this whole lot
# should be a single case statement anyway.

			if test "x$keynum" = "x!"
			then 
				keynum="invalid"
			fi

			#  Handle special case for Quit
			keynum=`$ECHO_CMD $keynum | tolower`
			if [ "$keynum" = "$INSTALLER_Q" -o "$keynum" = "$INSTALLER_QUIT" ]
			then
				return 0
			fi

			if out_of_bound "$keynum" 1 "$menuItems"
			then
				$ECHO_CMD
				$ECHO_CMD $menus3
				continue
			fi
			#  Got a valid key

			keyDefault="$keynum"

			case $keynum in
			1)
				install_ICA_client 
				;;
			2)
				remove_ICA_client
				;;
			3)
				return 0
				;;
			esac
			sub_ret=$?
			if [ "$sub_ret" != "0" ]
			then
				# Subroutine requested a particular default
				keyDefault="$sub_ret"
			fi
		done
}
###############################################################################
#!/bin/sh
###############################################################################
#
#	Name:		install.sh
#
#
#	Created:	May 1995
#
#	Version:	$Id: //depot/NetClient/main/unix/installer/scripts/install.sh#14 $
#
#	Coding Stds:	2.4
#
#	Purpose:	The main (top-level) part of the ICA Client installer.
#			For correct operation this should be at the very
#			bottom of the script.
#
#	Copyright 1996-1998 Citrix Systems, Inc. All rights reserved.
#
###############################################################################


install1="\nTo install $DISP_PRODUCT_NAME run the setupwfc program\n\
in the root directory of the CD-ROM.\n"

install2="\nFor further information see your $DISP_PRODUCT_NAME $DISP_VERSION manual.\n"

install3="Quitting $DISP_PRODUCT_NAME $DISP_VERSION setup."


###############################################################################
#
#  This is the main part of the install script.  It operates mainly using
#  the functions above.  Code above this must be only:
#
#	1.	"echo" commands for a sign-on message.
#	2.	Commands to set shell variables to values which are specific
#		to a particular build or platform.
#	3.	Commands to set shell variables which are related to particular
#		functions and must be set before the function is called the
#		first time.
#	4.	Shell functions.
#
###############################################################################

#  First (proper) executable lines in the script - save command line for later.

MY_NAME=$0
if [ $# -ne 2 ]
then
        $ECHO_CMD $install1
	$ECHO_CMD $install2
        exit 1
fi

#  Parameter 1:  Flag to indicate whether this script is being run from
#  a CDROM (or similar installable image), or from an installed package.
#    Can be either "CDROM" or "INSTALLED"
RunningFrom=$1

# Parameter 2:
# The directory from which the installer is being run.  Either the root
# of the CDROM, or an already installed ICAROOT directory.  Remove any
# trailing /. for neatness, and so that removing works OK on that directory.
TopDir=`$ECHO_CMD $2 | rm_last_dot`

check_run

#  Find the filename mapping type required.
#  This initialises TR_DIR_KEY and TR_FILE_KEY

get_tr_key $MY_NAME

#  Set up the names of directories

tr_file $TR_DIR_KEY $PORT
PORTDIR=$TR_FILE

#  Display a menu of the available functions.  Everything happens within
#  this function, until Quit is selected.

main_install_menu

#  And that's us done!!

$ECHO_CMD $install3

exit 0
###############################################################################

