#!/bin/sh
#
#########################################################################
#
# Copyright (c) 1994 Adobe System Incorporated
# All Rights Reserved
#
#	***********************************************************************
#	If you copy this script off of the CD-ROM and then edit it, this
#	script will only work if you pass it the optional parameter "CDDIR=xxx",
#	where "xxx" is the mount point for the CD-ROM (e.g., /cdrom).
#	***********************************************************************
#
# In general, this script accepts command line parameters in the form:
#	xxx=yyy
# where "xxx" is a shell variable name and "yyy" is the value.
# For each parameter with an equal sign, this script does an eval on the parameter.
# Probably, CDDIR is the only parameter which makes sense to alter.
#
##########################################################################

export PATH

TAR=/usr/bin/tar
TAR_OPTS="-xfv"
MKDIR="/usr/bin/mkdir -p "
RMDIR="/usr/bin/rmdir "
CP="/usr/bin/cp"
LN="/usr/bin/ln -s"
RM="/usr/bin/rm -f"
MV="/usr/bin/mv"
CAT="/usr/bin/cat"

# For echo without newline under BSD, set EB and EE variables
EB="-n "
EE=""
LASTLINECMD="tail -1"

# Things that are either platform-specific or potentially platform-specific.
osname="UNKNOWN"
osversion="UNKNOWN"
osmajorminor="UNKNOWN"
osmajor="UNKNOWN"
osminor="UNKNOWN"
if [ -x /bin/uname ] ; then
	osname=`/bin/uname -s`
	osversion=`/bin/uname -r`
	check=`echo "$osversion" | egrep '^[0-9]\.[0-9]*'`
	if [ "$check" != "" ] ; then
		# osmajorminor will be like "4.2". osmajor: "4". osminor:"2".
		osmajorminor=`echo "$osversion" | sed -e 's/^\([0-9]\.[0-9]\).*/\1/'`
		osmajor=`echo "$osversion" | sed -e 's/^\([0-9]\).*/\1/'`
		osminor=`echo "$osversion" | sed -e 's/^[0-9]\.\([0-9]\).*/\1/'`
	else
		osversion="UNKNOWN"
	fi
fi
if [ $osname = "SunOS" ] ; then
	RETURNKEYNAME="Return"
	if [ $osmajor -ge 5 ] ; then
		DFTTAPEPATH=/dev/rmt/0
		# For echo without newline under Sys V, set EB and EE variables
		EB=""
		EE="\c"
		PATH=/usr/sbin:/usr/bin:/bin:/usr/bin/X11:/usr/openwin/bin:/sbin:/usr/sbin:/etc:/usr/etc
		WHOAMI=`/usr/bin/id | sed 's/^[^(]*.\([^)]*\).*/\1/'`
		DFTDAEMONDIR=sun4/sunOS5
		DFCMD="df -k"
	else
		DFTTAPEPATH=/dev/rst0
		# For echo without newline under BSD, set EB and EE variables
		EB="-n "
		EE=""
		PATH=/usr/ucb:/usr/bin:/bin:/usr/bin/X11:/usr/openwin/bin:/sbin:/etc:/usr/etc
		WHOAMI=`/usr/ucb/whoami`
		DFTDAEMONDIR=sun4/sunOS4
		DFCMD="df"
	fi
	CLEAR=/usr/ucb/clear
	DFTCDROMPATH=/cdrom
	DFTTOPDIR=/usr/adobe
	KEYSYMDBFILE=/usr/openwin/lib/XKeysymDB
	KBYTES_AVAIL_FIELD=4
	GETHOSTID="hostid"

elif [ $osname = "IRIX" ] ; then
	RETURNKEYNAME="Enter"
	DFTTAPEPATH=/dev/tape
	DFTCDROMPATH=/CDROM
	DFTTOPDIR=/usr/adobe
	KEYSYMDBFILE=/usr/lib/X11/XKeysymDB
	DFCMD="df -k"
	KBYTES_AVAIL_FIELD=5
	GETHOSTID='sysinfo | head -2 | tail -1 | awk '\''{ printf "%s%s%s%s", $1, $2, $3, $4; }'\'
	CLEAR=/usr/bsd/clear
	WHOAMI=`/usr/bin/id | sed 's/^[^(]*.\([^)]*\).*/\1/'`
	# For echo without newline under Sys V, set EB and EE variables
	EB=""
	EE="\c"
	PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/bin/X11:/usr/openwin/bin:/etc:/usr/etc
	DFTDAEMONDIR=sgi/v5
fi
if [ "$osname" = "UNKNOWN" -o "$osversion" = "UNKNOWN" ] ; then
	echo ""
	echo "Unrecognized operating system: $osname $osversion."
	echo "Cannot install: $DISTRIB_DESC"
	eval ${ABORTCMD}
fi

# Temporary directory used by this install script.
if [ "$INSTALLTEMPDIR" = "" ] ; then
	INSTALLTEMPDIR="/tmp"
fi
PKGLISTFILE=$INSTALLTEMPDIR"/Packages."$$

# Installation device (CDROM or TAPE)
if [ "$INSTALLDEVICE" = "" ] ; then
	INSTALLDEVICE="CDROM"
fi

# Make sure we have proper access to installation temp file.
if [ ! -w $INSTALLTEMPDIR ] ; then
	echo "Permission denied in writing to directory $INSTALLTEMPDIR."
	echo "Please change permissions and rerun this script."
	echo ""
	exit 1
fi
if [ -f $PKGLISTFILE -a ! -w $PKGLISTFILE ] ; then
	echo "Permission denied in creating file $PKGLISTFILE."
	echo "Please change permissions and rerun this script."
	echo ""
	exit 1
fi

# Description of this distribution.
DISTRIB_DESC="Adobe Photoshop Version 2.5.2 for Irix 5.2"

# Which packages to install (prompt or ALL or list of numbers)
WHICH_PACKAGES="prompt"
if [ "$WHICH_PACKAGES" = "" ] ; then
	WHICH_PACKAGES="prompt"
fi

# Descriptions of packages included with this distribution.
# NPKGS indicates how many packages are included in this distribution.
# Following NPKGS is the printed table which appears to the user when
# choosing which packages to install.
# This table is stored in a temporary file while the install script runs.
# PKG_$i_PKGFULLDESC: Full product description (version, platform included)
# PKG_$i_PKGDESC: Descriptive product name
# PKG_$i_VERSIONDESC: Descriptive product version
# PKG_$i_PLATFORMDESC: Description of platform required to run package
# PKG_$i_KBYTES: Space required for package (in kilobytes. No trailing K)
# PKG_$i_PKGABBR: Abbreviated product name (no spaces or underscores)
# PKG_$i_PKGVERS: Abbreviated version number (no spaces or underscores)
# PKG_$i_BINLINKS: List of programs requiring auto sym links to /usr/bin (or other dir)
# PKG_$i_XKEYSYMDB: Set this to "1" if package required updates to XKeysymDB
# PKG_$i_SCRIPT: Name of script to run after package is installed (or empty string)
# PKG_$i_LMFEATURE: Describes components requiring a password (null string if none)
# PKG_$i_LMVERSION: Corresponding FlexLM version string.
# PKG_$i_LMQUOTES: Corresponding FlexLM string within quotes.
# PKG_$i_CDROM_FROMFILES: Name of files on CDROM to copy into install tree.
#                    Relative to dir with install script.
# PKG_$i_CDROM_TOFILES: What to rename the files specified in CDROM_FROMFILES.
#                    Relative to base dir for product tree.
NPKGS="1"
cat << EOF > $PKGLISTFILE
         # Package Description       Version    Platform      KBytes
        -- -------------------       -------    --------      ------
         1 AdobePhotoshop            2.5.2    Irix 5.2  16000

EOF
PKG_1_PKGFULLDESC="Adobe Photoshop Version 2.5.2 for Irix 5.2"
PKG_1_PKGDESC="Adobe Photoshop"
PKG_1_VERSIONDESC="Version 2.5.2"
PKG_1_PLATFORMDESC="IRIX 5.2"
PKG_1_KBYTES="16000"
PKG_1_PKGABBR="Photoshop"
PKG_1_PKGVERS="2.5.2"
PKG_1_BINLINKS="bin/photoshop"
PKG_1_XKEYSYMDB="0"
PKG_1_SCRIPT="installscripts/postinstall"
PKG_1_LMFEATURE="AdobePhotoshop"
PKG_1_LMVERSION="2.500"
PKG_1_LMQUOTES=""
PKG_1_CDROM_FROMFILES="../readme"
PKG_1_CDROM_TOFILES="readme"

# Name of CD-ROM archive file.
CDARCHIVEFILE="photoshp.tar"

# Name of directory where CD is mounted.
# If null, then directory is figured out automatically by script.
#CDDIR=""

# Whether you must be root to run the installer.
ROOT_REQUIRED="1"
if [ "$ROOT_REQUIRED" = "" ] ; then
	ROOT_REQUIRED="1"
fi

# Whether to prompt for root directory (y or n)
ROOTDIR_PROMPT="y"
if [ "$ROOTDIR_PROMPT" = "" ] ; then
	ROOTDIR_PROMPT="y"
fi

# Whether to prompt for license data file location (y or n)
LICENSE_PROMPT="y"
if [ "$LICENSE_PROMPT" = "" ] ; then
	LICENSE_PROMPT="y"
fi

# Directory for security files.
# If a relative path is given, then the path is relative to 
# the directory into which the software is installed.
if [ "$DFTSECURITYDIR" = "" ] ; then
	DFTSECURITYDIR="/usr/local/flexlm/licenses"
fi

# Directory for Adobe license daemon.
# If a relative path is given, then the path is relative to 
# the directory above the directory containing the license file.
DAEMONDIR="sgi/v5"
if [ "$DAEMONDIR" = "" ] ; then
	DAEMONDIR="$DFTDAEMONDIR"
fi

# License security file within license security directory.
if [ "$DFTSECURITYFILE" = "" ] ; then
	DFTSECURITYFILE="license.dat"
fi

# Whether to install automatic symbolic links for programs
# (1 or 0 or prompt or makescript)
AUTOSYMLINK="makescript"
if [ "$AUTOSYMLINK" = "" ] ; then
	AUTOSYMLINK="makescript"
fi

# Prompt to give for whether to establish automatic symbolic links
if [ "$SYMLINK_PROMPT_1_TEXT" = "" ] ; then
	SYMLINK_PROMPT_1_TEXT="This installation script places program launch scripts in locaions that
probably are not on your PATH. Do you want symbolic links for the launch
scripts installed in another directory (e.g., /usr/bin or /usr/local/bin)?"
fi

# Prompt to ask for directory for automatic symbolic links
if [ "$SYMLINK_PROMPT_2_TEXT" = "" ] ; then
	SYMLINK_PROMPT_2_TEXT="Enter name of alternate directory for program launch scripts"
fi

# Location of script which will be created if AUTOSYMLINK=makescript
SYMLINKSCRIPT="/tmp/photoshop.makelinks"
if [ "$SYMLINKSCRIPT" = "" ] ; then
	SYMLINKSCRIPT="/tmp/adobe_install_make_links"
fi

# Whether to prompt for directory for installing automatic symbolic links
# (y or n)
SYMLINKDIR_PROMPT="n"
if [ "$SYMLINKDIR_PROMPT" = "" ] ; then
	SYMLINKDIR_PROMPT="y"
fi

# Directory to install automatic symbolic links for programs
# If a relative path is given, then the path is relative to 
# the directory into which the software is installed.
if [ "$DFTSYMLINKDIR" = "" ] ; then
	DFTSYMLINKDIR="/usr/bin"
fi

# Directory relative to installation root dir for keeping XKeysymDB file.
if [ "$XKEYSYMDBDIR" = "" ] ; then
	XKEYSYMDBDIR="installscripts"
fi

# File name for XKeysymDB fixes relative to XKEYSYMDBDIR.
if [ "$XKEYSYMDBFILE" = "" ] ; then
	XKEYSYMDBFILE="XKeysymDB"
fi

# Whether to prompt for PS resource path (y or n)
PSRES_PROMPT="y"
if [ "$PSRES_PROMPT" = "" ] ; then
	PSRES_PROMPT="n"
fi

# Whether to write out a file pointing to PSRES_PATH (y or n)
if [ "$PSRES_WRITEFILE" = "" ] ; then
	PSRES_WRITEFILE="n"
fi

# Default list of directories into which application will look for
# PostScript resources
if [ "$PSRES_DEFAULT" = "" ] ; then
	PSRES_DEFAULT='$HOME/psres:/usr/psres'
fi

# File name to write out value of PSRES_PATH (for PSRES_WRITEFILE=y)
# If a relative path is given, then the path is relative to 
# the directory into which the software is installed.
if [ "$PSRES_FILE" = "" ] ; then
	PSRES_FILE="custom/SITE_PSRESOURCEPATH"
fi

# Whether to write out a file pointing to LM_LICENSE_FILE (y or n)
LM_WRITEFILE="y"
if [ "$LM_WRITEFILE" = "" ] ; then
	LM_WRITEFILE="n"
fi

# File name to write out value of LM_LICENSE_FILE (for LM_WRITEFILE=y)
# If a relative path is given, then the path is relative to 
# the directory into which the software is installed.
if [ "$LM_FILE" = "" ] ; then
	LM_FILE="custom/LM_LICENSE_FILE"
fi

# Number of times prompting loops are permitted to loop.
# This is necessary on some platforms where double-clicking
# on a script from the desktop causes script to run with
# Return automatically supplied to all possible prompts.
if [ "$LOOP_LIMIT" = "" ] ; then
	LOOP_LIMIT="25"
fi

# Process command line parameters.
while [ $# -gt 0 ] ; do

	# "xxx=yyy" allows particular values from this script
	# to be overwritten from the command line.
	# For example, CDDIR=/usr/cdrom
	nequal=`expr $1 : '[^=][^=]*=[^=][^=]*'`
	if [ $nequal -ge 1 ] ; then
		eval "$1"
		shift
	else
		echo "Invalid parameter: $1"
		echo "Usage: $0 [<var>=<value>]..."
		exit 1
	fi
done

# Initialize variables
RHOST=""
DEVNAME=""
DOSYMLINKS=0
ABORTCMD='${RM} $PKGLISTFILE; echo ""; echo ""; echo "*** Installation canceled ***"; echo ""; exit 1;'

umask 022

if [ $ROOT_REQUIRED = 1 ] ; then
	# Abort installation if user not superuser
	if [ "$WHOAMI" != root ] ; then
		echo ""
		echo "You must be logged in as root to install"
		echo "$DISTRIB_DESC."
		echo 'Type "su root" and enter the password to become root.'
		eval ${ABORTCMD}
	fi
fi

# Stop the script if user hit interrupt
trap 'eval ${ABORTCMD}' 2

# Loop until user says to continue with the installation.
outermost_loop=0
while : ; do
	outermost_loop=`expr $outermost_loop + 1`
	if [ $outermost_loop -ge $LOOP_LIMIT ] ; then
		echo ""
		echo "LOOP_LIMIT exceeded."
		eval ${ABORTCMD}
	fi

	ALLOK1=1
	$CLEAR
	echo "" 
	echo ""
	echo "	Installation Script For"
	echo "	${DISTRIB_DESC}"
	echo ""
	echo "	Copyright (c) 1994 Adobe Systems Incorporated"
	echo "	All Rights Reserved "
	echo ""
	sleep 2

	if [ $NPKGS = 1 ] ; then
		A="ALL"
	elif [ "$WHICH_PACKAGES" != "prompt" ] ; then
		A="$WHICH_PACKAGES"
	else
		echo ""
		echo "The following packages are available for installation:"
		echo ""
		cat $PKGLISTFILE
		echo ""
		echo 'Which packages do you wish to install?'
		echo '[Press '$RETURNKEYNAME' for All or type a list of numbers separated by'
		echo $EB'spaces or type Q to quit]: '$EE
		read A
		ntokens=`echo ${A} | wc -w`
		if [ $ntokens -eq 0 ] ; then
			A="ALL"
		elif [ "$A" = "Q" -o "$A" = "q" -o "$A" = "Quit" -o "$A" = "quit" -o "$A" = "QUIT" ] ; then
			eval ${ABORTCMD}
		elif [ "$A" = "ALL" -o "$A" = "All" -o "$A" = "all" ] ; then
			A="ALL"
		else
			# Convert commas to spaces
			A=`echo "$A" | tr ',' ' '`

			# Make sure only valid numbers are present.
			for i in $A ; do
				package_num=1
				found=0
				while [ $package_num -le $NPKGS ] ; do
					if [ "$i" -eq "$package_num" ] ; then
						found=1
						break
					fi
					package_num=`expr $package_num + 1`
				done
				if [ $found = 0 ] ; then
					echo ""
					echo "Invalid entry: $i. Try again."
					ALLOK1=0
					break
				fi
			done
		fi
		$CLEAR
	fi

	if [ $ALLOK1 = 1 ] ; then
		if [ "$A" = "ALL" ] ; then
			A=""
			package_num=1
			while [ $package_num -le $NPKGS ] ; do
				A="$A $package_num"
				package_num=`expr $package_num + 1`
			done
		fi
		PKGS_TO_INSTALL="${A}"
		echo ""
		echo ""
		for package_num in ${PKGS_TO_INSTALL} ; do
			packagedesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
			platformdesc=`eval echo '$PKG_'$package_num'_PLATFORMDESC'`
			echo "$platformdesc is required to run $packagedesc"
		done
		echo "$osname $osversion is currently installed on this machine"
		echo ""
		echo ""

		if [ "$INSTALLDEVICE" = "" ] ; then
			echo ""
			cdtape_loop=0
			while : ; do
				cdtape_loop=`expr $cdtape_loop + 1`
				if [ $cdtape_loop -ge $LOOP_LIMIT ] ; then
					echo ""
					echo "LOOP_LIMIT exceeded."
					eval ${ABORTCMD}
				fi
				echo ""
				echo ""
				echo "Do you want to install"
				echo "from a CD-ROM drive or a tape drive?"
				echo $EB"Type in 'c' for CD-ROM or 't' for TAPE (cdrom/tape) "$EE
				read A
				if [ "$A" = "CD-ROM" -o "$A" = "C" -o "$A" = "cdrom" -o "$A" = "c" ] ; then
					USECD=1
					DFTDEVPATH=$DFTCDROMPATH
					break
				elif [ "$A" = "TAPE" -o "$A" = "T" -o "$A" = "tape" -o "$A" = "t" ] ; then
					USECD=0
					DFTDEVPATH=$DFTTAPEPATH
					break
				else
					echo ""
					echo "You must select CD-ROM or TAPE.  Try again."
				fi
			done
		elif [ "$INSTALLDEVICE" = "CDROM" ] ; then
			USECD=1
		else
			USECD=0
		fi

		# Determine host and path from where release can be extracted
		if [ $USECD = 1 ] ; then
			# Determine name of this file on CDROM.
			if [ "$CDDIR" = "" ] ; then
				cddir=`expr "$0" : '\(.*\)/'`
				if [ "$cddir" = "" -o "$cddir" = "." ] ; then
					cddir=`pwd`
				fi
			else
				cddir="$CDDIR"
			fi
			DEVPATH=${cddir}'/'${CDARCHIVEFILE}
			if [ ! -f $DEVPATH ] ; then
				echo ""
				echo "Cannot find CDROM release in ${cddir}."
				echo "Re-read installation instructions and start again."
				eval ${ABORTCMD}
			fi
		else
			tapelr1_loop=0
			while : ; do
				tapelr1_loop=`expr $tapelr1_loop + 1`
				if [ $tapelr1_loop -ge $LOOP_LIMIT ] ; then
					echo ""
					echo "LOOP_LIMIT exceeded."
					eval ${ABORTCMD}
				fi
				tapelr2_loop=0
				while : ; do
					tapelr2_loop=`expr $tapelr2_loop + 1`
					if [ $tapelr2_loop -ge $LOOP_LIMIT ] ; then
						echo ""
						echo "LOOP_LIMIT exceeded."
						eval ${ABORTCMD}
					fi
					echo ""
					echo ""
					echo $EB"Do you want to install from a tape "$EE
					echo "drive connected to your local"
					echo $EB"computer or from a remote host (local/remote)? "$EE
					read A
					if [ "$A" = "LOCAL" -o "$A" = "L" -o "$A" = "local" -o "$A" = "l" -o \
							$A = "REMOTE" -o "$A" = "R" -o "$A" = "remote" -o "$A" = "r" ] ; then
						if [ "$A" = "REMOTE" -o "$A" = "R" -o "$A" = "remote" -o "$A" = "r" ] ; then
							remotehost_loop=0
							while : ; do
								remotehost_loop=`expr $remotehost_loop + 1`
								if [ $remotehost_loop -ge $LOOP_LIMIT ] ; then
									echo ""
									echo "LOOP_LIMIT exceeded."
									eval ${ABORTCMD}
								fi
								echo ""
								echo $EB"Enter name of the remote host: "$EE
								read RHOST
								if [ "$RHOST" = "" ] ; then
									echo ""
									echo "You must specify a remote host.  Try again."
								else
									break
								fi
							done
							# check if we can connect to remote host
							if rsh -n $RHOST /usr/bin/test 1> /dev/null 2>&1 ; then status=0; else status=1; fi
							if [ $status != 0 ] ; then
							   echo ""
							   echo "You are not authorized to connect to $RHOST"
							   echo "Check that your machine is listed in /.rhosts file on $RHOST."
							   echo "For more help, talk to your System Administrator."
							   ALLOK1=0
							fi 
						else
							RHOST=""
						fi


						if [ $ALLOK1 = 1 ]; then
							echo ""
							echo $EB"Specify the pathname of the device mounted on "$EE
							if [ "$RHOST" = "" ] ; then
								echo "this computer."
							else
								echo "$RHOST."
							fi
							echo "A tape drive usually has a default mountpoint of "$DFTDEVPATH"."
							echo "Please refer to the Installation Guide for additional information."
							echo ""
							echo $EB'Pathname of device [press '$RETURNKEYNAME' for '$DFTDEVPATH']: '$EE
							read A
							if [ "$A" = "" ] ; then
								DEVPATH=$DFTDEVPATH
							else
								DEVPATH=$A
							fi
						fi
						break
					else
						echo ""
						echo "You must specify LOCAL or REMOTE.  Try again."
					fi
				done


				if [ $ALLOK1 = 1 ] ; then
					if [ "$RHOST" = ""  ] ; then
						if [ ! -r $DEVPATH ] ; then
							echo ""
							echo "The device $DEVPATH does not exist."
							echo "You must select an available device.  Try again."
						fi
					fi
				break
				fi
			done
		fi

		if [ $ALLOK1 = 1 ] ; then
			if [ "$ROOTDIR_PROMPT" = "y" ] ; then
				rootdir_loop=0
				while : ; do
					rootdir_loop=`expr $rootdir_loop + 1`
					if [ $rootdir_loop -ge $LOOP_LIMIT ] ; then
						echo ""
						echo "LOOP_LIMIT exceeded."
						eval ${ABORTCMD}
					fi
					ALLOK2=1
					echo ""
					echo ""
					echo "This script installs software relative to a specified installation"
					echo "directory <installdir>. If you accept the default value for"
					echo "<installdir>, which is $DFTTOPDIR, the following directories"
					echo "will be created:"
					echo ""
					for package_num in ${PKGS_TO_INSTALL} ; do
						packagedesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
						pabbr=`eval echo '$PKG_'$package_num'_PKGABBR'`
						pver=`eval echo '$PKG_'$package_num'_PKGVERS'`
						package_dir=$pabbr"_"$pver
						echo "    $DFTTOPDIR/$package_dir"
					done
					echo ""
					echo "Enter the full path name for the <installdir> into which you want to"
					echo $EB'install the software [press '$RETURNKEYNAME' for '$DFTTOPDIR']: '$EE
					read A
					if [ "$A" = ""  ] ; then
						TOPDIR="$DFTTOPDIR"
					else
						TOPDIR="$A"
					fi

					if [ ! -d $TOPDIR  ] ; then
						if $MKDIR $TOPDIR ; then status=0 ; else status=1; fi
						if [ $status != 0  ] ; then
							echo ""
							echo "Could not create directory $TOPDIR."
							eval ${ABORTCMD}
						fi

					elif [ ! -w $TOPDIR  ] ; then
						echo ""
						echo "You do not have write permissions for the directory"
						echo "$TOPDIR.  Please choose another directory."
						ALLOK2=0
					fi
					if [ $ALLOK2 = 1 ] ; then
						break
					fi
				done
			else
				TOPDIR="$DFTTOPDIR"
				if [ ! -d $TOPDIR  ] ; then
					if $MKDIR $TOPDIR ; then status=0 ; else status=1; fi
					if [ $status != 0  ] ; then
						echo ""
						echo "Could not create directory $TOPDIR."
						eval ${ABORTCMD}
					fi

				elif [ ! -w $TOPDIR  ] ; then
					echo ""
					echo "You do not have write permissions for the directory"
					echo "$TOPDIR."
					eval ${ABORTCMD}
				fi
			fi
		fi
	fi

	# Only ask next set of questions if user answered YES above.
	if [ $ALLOK1 = 1 ] ; then

		# See if any files/directories already exist with target names.
		deletedir=0
		for package_num in ${PKGS_TO_INSTALL} ; do
			packagedesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
			pabbr=`eval echo '$PKG_'$package_num'_PKGABBR'`
			pver=`eval echo '$PKG_'$package_num'_PKGVERS'`
			package_dir=$pabbr"_"$pver
			fulldir=$TOPDIR/$package_dir
			if [ -d $fulldir -o -f $fulldir -o -h $fulldir ] ; then
				deletedir=1
				break
			fi
		done

		# If any exist, prompt user whether it is OK to delete these files/dirs.
		if [ $deletedir = 1 ] ; then
			overwritedir_loop=0
			while : ; do
				overwritedir_loop=`expr $overwritedir_loop + 1`
				if [ $overwritedir_loop -ge $LOOP_LIMIT ] ; then
					echo ""
					echo "LOOP_LIMIT exceeded."
					eval ${ABORTCMD}
				fi
				echo "" 
				echo ""
				echo "*** WARNING ***"
				echo "The following files/directories already exist and will be completely"
				echo "overwritten by this installation. If you have personal files saved in"
				echo "these files/directories, you may want to copy them to another"
				echo "location before continuing with this procedure:"

				for package_num in ${PKGS_TO_INSTALL} ; do
					packagedesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
					pabbr=`eval echo '$PKG_'$package_num'_PKGABBR'`
					pver=`eval echo '$PKG_'$package_num'_PKGVERS'`
					package_dir=$pabbr"_"$pver
					fulldir=$TOPDIR/$package_dir
					if [ -d $fulldir -o -f $fulldir -o -h $fulldir ] ; then
						echo "        $fulldir"
					fi
				done

				echo ""
				echo $EB"OK to remove the above files/directories and their contents (YES/NO)? "$EE
				read A
				echo ""
				if [ "$A" = "YES" -o "$A" = "Y" -o "$A" = "yes" -o "$A" = "y" -o "$A" = "Yes" ] ; then
					break
				elif [ "$A" = "NO" -o "$A" = "N" -o "$A" = "no" -o "$A" = "n" -o "$A" = "No" ] ; then
					echo ""
					echo "Please specify a different location for installing the packages"
					if [ "$WHICH_PACKAGES" = "prompt" ] ; then
						echo "or a different set of packages to install"
					fi
					echo "Press $RETURNKEYNAME to restart the script or use your interrupt key to exit the script"
					read A
					ALLOK1=0
					break
				else
					echo ""
					echo "You must specify YES or NO.  Try again."
				fi
			done
		fi

		# Remove any files/directories that will be overwritten.
		if [ $ALLOK1 = 1 -a $deletedir = 1 ] ; then
			echo ""
			echo "Removing the following files/directories:"
			for package_num in ${PKGS_TO_INSTALL} ; do
				packagedesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
				pabbr=`eval echo '$PKG_'$package_num'_PKGABBR'`
				pver=`eval echo '$PKG_'$package_num'_PKGVERS'`
				package_dir=$pabbr"_"$pver
				fulldir=$TOPDIR/$package_dir
				if [ -d $fulldir -o -f $fulldir -o -h $fulldir ] ; then
					echo $EB"        "$fulldir"..."$EE
					${RM} -r $fulldir
					echo done
				fi
			done
			echo ""
		fi

		if [ $ALLOK1 = 1 ] ; then
			# Get last line of df statement.
			# Prepend X because if the mount point is too long,
			# the df command will result in two lines, with the
			# second line having blanks for the first field.
			lastdfline="X"`$DFCMD ${TOPDIR} | $LASTLINECMD`

			# Determine if there is enough disk space for this install.
			case $KBYTES_AVAIL_FIELD in
				1)
					disk_kbytes=`echo $lastdfline | awk '{ print $1 }'`
					;;
				2)
					disk_kbytes=`echo $lastdfline | awk '{ print $2 }'`
					;;
				3)
					disk_kbytes=`echo $lastdfline | awk '{ print $3 }'`
					;;
				4)
					disk_kbytes=`echo $lastdfline | awk '{ print $4 }'`
					;;
				5)
					disk_kbytes=`echo $lastdfline | awk '{ print $5 }'`
					;;
				*)
					echo ""
					echo "Internal error. Unable to determine disk space."
					eval ${ABORTCMD}
					;;
			esac
			total_kbytes=0
			for package_num in ${PKGS_TO_INSTALL} ; do
				packagefulldesc=`eval echo '$PKG_'$package_num'_PKGFULLDESC'`
				kbytes=`eval echo '$PKG_'$package_num'_KBYTES'`
				total_kbytes=`expr $total_kbytes + $kbytes`
			done
			if [ $total_kbytes -ge $disk_kbytes ] ; then
				echo ""
				echo ""
				echo "There is not enough disk space for the installation."
				echo "The installation you requested requires $total_kbytes kilobytes of disk space"
				echo "and you currently have only $disk_kbytes kilobytes of available disk space"
				echo "in directory ${TOPDIR}."
				if [ "$NPKGS" -gt 1 ] ; then
					echo "Either install fewer packages or choose a different location to install"
					echo "the packages."
				else
					echo "Choose a different location to install the packages."
				fi
				echo ""
				echo ""
				echo "Press $RETURNKEYNAME to continue"
				read A

				# Make sure that ROOTDIR_PROMPT is "y" so that the next
				# time through the user has an opportunity to pick a
				# non-default <root directory>.
				ROOTDIR_PROMPT="y"
				ALLOK1=0
			fi
		fi

		if [ $ALLOK1 = 1 ] ; then
			ANYSECURED=0
			for package_num in ${PKGS_TO_INSTALL} ; do
				lmfeature=`eval echo '$PKG_'$package_num'_LMFEATURE'`
				ntokens=`echo $lmfeature | wc -w`
				if [ $ntokens -gt 0 ] ; then
					ANYSECURED=1
					break
				fi
			done
			if [ $ANYSECURED = 1 ] ; then
				abspath=`expr "$DFTSECURITYDIR" : '^/'`
				if [ $abspath = 1 ] ; then
					SECURITYDIR="$DFTSECURITYDIR"
				else
					SECURITYDIR=${TOPDIR}'/'"$DFTSECURITYDIR"
				fi
				if [ "$LICENSE_PROMPT" = "y" ] ; then
					licensefile_loop=0
					while : ; do
						licensefile_loop=`expr $licensefile_loop + 1`
						if [ $licensefile_loop -ge $LOOP_LIMIT ] ; then
							echo ""
							echo "LOOP_LIMIT exceeded."
							eval ${ABORTCMD}
						fi
						echo ""
						echo "Enter name of license data file"
						echo $EB'[press '$RETURNKEYNAME' for '$SECURITYDIR'/'$DFTSECURITYFILE']: '$EE
						read A
						if [ "$A" != "" ] ; then
							SECURITYFILE="$A"
						else
							SECURITYFILE="$SECURITYDIR/$DFTSECURITYFILE"
						fi
						dir=`expr "$SECURITYFILE" : '\(.*\)/'`
						if [ "$dir" = "" -o "$dir" = "." ] ; then
							echo ""
							echo ""
							echo "You must enter a fully qualified name beginning with '/'."
							continue
						else
							break
						fi
					done
				else
					SECURITYFILE="$SECURITYDIR/$DFTSECURITYFILE"
				fi
			fi
		fi
		if [ $ALLOK1 = 1 ] ; then
			ANYSYMLINKS=0
			for package_num in ${PKGS_TO_INSTALL} ; do
				binlinks=`eval echo '$PKG_'$package_num'_BINLINKS'`
				ntokens=`echo $binlinks | wc -w`
				if [ $ntokens -gt 0 ] ; then
					ANYSYMLINKS=1
					break
				fi
			done
			DOSYMLINKS=$ANYSYMLINKS
			if [ $ANYSYMLINKS = 1 ] ; then
				if [ "$AUTOSYMLINK" = "makescript" ] ; then
					dir=`expr "$SYMLINKSCRIPT" : '\(.*\)/'`
					if [ ! -w "$dir" ] ; then
						echo ""
						echo ""
						echo "You do not have permission to write to directory $dir."
						echo "Change permissions and then rerun $0."
						eval ${ABORTCMD}
					fi
					if [ -s "$SYMLINKSCRIPT" -o -f "$SYMLINKSCRIPT" ] ; then
						if [ ! -w "$SYMLINKSCRIPT" ] ; then
							echo ""
							echo ""
							echo "You do not have permission to write to file $SYMLINKSCRIPT."
							echo "Change permissions and then rerun $0."
							eval ${ABORTCMD}
						fi
						${RM} "$SYMLINKSCRIPT"
					fi
					DOSYMLINKS=0

				elif [ "$AUTOSYMLINK" = "prompt" ] ; then

					dosymlinks_loop=0
					while : ; do
						dosymlinks_loop=`expr $dosymlinks_loop + 1`
						if [ $dosymlinks_loop -ge $LOOP_LIMIT ] ; then
							echo ""
							echo "LOOP_LIMIT exceeded."
							eval ${ABORTCMD}
						fi
						echo ""
						echo ""
						echo "$SYMLINK_PROMPT_1_TEXT"
						echo $EB"[YES/NO: Press $RETURNKEYNAME for YES]: "$EE
						read A
						if [ "$A" = "YES" -o "$A" = "Y" -o "$A" = "yes" -o "$A" = "y" -o "$A" = "Yes" -o "$A" = ""  ] ; then
							break
						elif [ "$A" = "NO" -o "$A" = "N" -o "$A" = "no" -o "$A" = "n" -o "$A" = "No" ] ; then
							DOSYMLINKS=0
							break
						else
							echo ""
							echo "You must specify YES or NO.  Try again."
						fi
					done
				fi


				if [ $DOSYMLINKS = 1 ] ; then
					abspath=`expr $DFTSYMLINKDIR : '^/'`
					if [ $abspath = 1 ] ; then
						AUTOSYMLINKDIR="$DFTSYMLINKDIR"
					else
						AUTOSYMLINKDIR=${TOPDIR}'/'"$DFTSYMLINKDIR"
					fi
					if [ "$SYMLINKDIR_PROMPT" = "y" ] ; then
						symlinkdir_loop=0
						while : ; do
							symlinkdir_loop=`expr $symlinkdir_loop + 1`
							if [ $symlinkdir_loop -ge $LOOP_LIMIT ] ; then
								echo ""
								echo "LOOP_LIMIT exceeded."
								eval ${ABORTCMD}
							fi
							echo ""
							echo "$SYMLINK_PROMPT_2_TEXT"
							echo $EB'[press '$RETURNKEYNAME' for '$AUTOSYMLINKDIR']: '$EE
							read A
							if [ "$A" != "" ] ; then
								AUTOSYMLINKDIR="$A"
							fi
							if [ ! -d "$AUTOSYMLINKDIR"  ] ; then
								if $MKDIR $AUTOSYMLINKDIR ; then error=0; else error=1; fi
								if [ $error != 0  ] ; then
									echo "cannot create directory $AUTOSYMLINKDIR"
									eval ${ABORTCMD}
								fi
								chmod u+w $AUTOSYMLINKDIR
							fi
							if [ ! -w $AUTOSYMLINKDIR ] ; then
								echo ""
								echo ""
								echo "You do not have permission to write to $AUTOSYMLINKDIR."
								ALLOK1=0
							else
								break
							fi
						done
					else
						if [ ! -d "$AUTOSYMLINKDIR"  ] ; then
							if $MKDIR $AUTOSYMLINKDIR ; then error=0; else error=1; fi
							if [ $error != 0  ] ; then
								echo "cannot create directory $AUTOSYMLINKDIR"
								eval ${ABORTCMD}
							fi
							chmod u+w $AUTOSYMLINKDIR
						fi
						if [ ! -w $AUTOSYMLINKDIR ] ; then
							echo ""
							echo ""
							echo "You do not have permission to write to $AUTOSYMLINKDIR."
							eval ${ABORTCMD}
						fi
					fi
				fi
			fi
		fi

		# See if we will override any existing files with auto symbolic links.
		SYMLINKANYOLD=0
		if [ $ALLOK1 = 1 -a $DOSYMLINKS = 1 ] ; then
			for package_num in ${PKGS_TO_INSTALL} ; do
				binlinks=`eval echo '$PKG_'$package_num'_BINLINKS'`
				ntokens=`echo $binlinks | wc -w`
				if [ $ntokens -gt 0 ] ; then
					for bin in $binlinks ; do
						# Next line is equiv to csh: set name=$bin:t
						name=`expr //$bin : '.*/\(.*\)'`
						if [ -f $AUTOSYMLINKDIR/$name -o -d $AUTOSYMLINKDIR/$name -o -h $AUTOSYMLINKDIR/$name ]; then
							SYMLINKANYOLD=1
							break
						fi
					done
				fi
				if [ $SYMLINKANYOLD = 1 ] ; then
					break
				fi
			done
		fi
		if [ $ALLOK1 = 1 -a $SYMLINKANYOLD = 1 ] ; then
			echo ""
			echo ""
			echo "*** WARNING ***"
			echo "The following files will be overridden by this installation."
			echo "You might want to stop/pause this installation as you move these"
			echo "files to another location or you might want to choose a different"
			echo "location for creating symbolic links."
			echo ""
			for package_num in ${PKGS_TO_INSTALL} ; do
				binlinks=`eval echo '$PKG_'$package_num'_BINLINKS'`
				ntokens=`echo $binlinks | wc -w`
				if [ $ntokens -gt 0 ] ; then
					for bin in $binlinks ; do
						# Next line is equiv to csh: set name=$bin:t
						name=`expr //$bin : '.*/\(.*\)'`
						if [ -f $AUTOSYMLINKDIR/$name -o -d $AUTOSYMLINKDIR/$name -o -h $AUTOSYMLINKDIR/$name ]; then
							echo "        $AUTOSYMLINKDIR/$name"
						fi
					done
				fi
			done
			overwritelink_loop=0
			while : ; do
				overwritelink_loop=`expr $overwritelink_loop + 1`
				if [ $overwritelink_loop -ge $LOOP_LIMIT ] ; then
					echo ""
					echo "LOOP_LIMIT exceeded."
					eval ${ABORTCMD}
				fi
				echo ""
				echo $EB'OK to remove these files/directories (YES/NO)? '$EE
				read A
				if [ "$A" = "YES" -o "$A" = "Y" -o "$A" = "yes" -o "$A" = "y" -o "$A" = "Yes" ] ; then
					echo ""
					break
				elif [ "$A" = "NO" -o "$A" = "N" -o "$A" = "no" -o "$A" = "n" -o "$A" = "No" ] ; then
					if [ "SYMLINKDIR_PROMPT" = "n" ] ; then
						echo ""
						echo "Installation canceled."
						exit 1
					else
						echo ""
						echo "Please specify a different location for installing symbolic links"
						echo "Press $RETURNKEYNAME to restart the script or use your interrupt key to exit the script"
						read A
						ALLOK1=0
						break
					fi
				else
					echo ""
					echo "You must specify YES or NO.  Try again."
				fi
			done
			echo ""
			echo "Removing the following files/directories:"
			echo ""
			if [ $ALLOK1 = 1 ] ; then
				for package_num in ${PKGS_TO_INSTALL} ; do
					binlinks=`eval echo '$PKG_'$package_num'_BINLINKS'`
					ntokens=`echo $binlinks | wc -w`
					if [ $ntokens -gt 0 ] ; then
						for bin in $binlinks ; do
							# Next line is equiv to csh: set name=$bin:t
							name=`expr //$bin : '.*/\(.*\)'`
							if [ -f $AUTOSYMLINKDIR/$name -o -d $AUTOSYMLINKDIR/$name -o -h $AUTOSYMLINKDIR/$name ]; then
								echo "        $AUTOSYMLINKDIR/$name"
								${RM} $AUTOSYMLINKDIR/$name
							fi
						done
					fi
				done
			fi
		fi
	fi




	if [ $ALLOK1 = 1 ] ; then
		PSRES_PATH=""
		if [ "$PSRES_PROMPT" = "y" ] ; then
			echo ""
			echo ""
			echo "Enter a list of network or local directories, separated by colons, for"
			echo "installing PostScript resources such as fonts. The following directory(ies)"
			echo "are included automatically and do not have to be specified:"
			echo ""
			echo "   $PSRES_DEFAULT"
			echo ""
			echo "Enter a list of site-specific directories for PostScript resources"
			echo "[or press $RETURNKEYNAME if no additional directories]: "$EE
			read PSRES_PATH
		fi
		if [ "$PSRES_PATH" = "" ] ; then
			PSRES_PATH="$PSRES_DEFAULT"
		elif [ "$PSRES_DEFAULT" != "" ] ; then
			PSRES_PATH="$PSRES_PATH:$PSRES_DEFAULT"
		fi
	fi

	ANY_XKEYSYMDB=0
	for package_num in ${PKGS_TO_INSTALL} ; do
		xkeysymdb=`eval echo '$PKG_'$package_num'_XKEYSYMDB'`
		if [ "$xkeysymdb" = 1 ] ; then
			ANY_XKEYSYMDB=1
			break
		fi
	done

	if [ $ALLOK1 = 1 ] ; then

		okproceed_loop=0
		while : ; do
			okproceed_loop=`expr $okproceed_loop + 1`
			if [ $okproceed_loop -ge $LOOP_LIMIT ] ; then
				echo ""
				echo "LOOP_LIMIT exceeded."
				eval ${ABORTCMD}
			fi
			echo ""
			echo ""
			echo "The following packages will be installed in ${TOPDIR}."
			echo ""
			for package_num in ${PKGS_TO_INSTALL} ; do
				packagefulldesc=`eval echo '$PKG_'$package_num'_PKGFULLDESC'`
				kbytes=`eval echo '$PKG_'$package_num'_KBYTES'`
				echo "    "$packagefulldesc '('$kbytes'K)'
			done

			if [ $DOSYMLINKS = 1 ] ; then
				echo ""
				echo "The following symbolic links will be created:"
				echo ""
				for package_num in ${PKGS_TO_INSTALL} ; do
					packagedesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
					pabbr=`eval echo '$PKG_'$package_num'_PKGABBR'`
					pver=`eval echo '$PKG_'$package_num'_PKGVERS'`
					package_dir=$pabbr"_"$pver
					fulldir=$TOPDIR/$package_dir
					binlinks=`eval echo '$PKG_'$package_num'_BINLINKS'`
					ntokens=`echo $binlinks | wc -w`
					if [ $ntokens -gt 0 ] ; then
						for bin in $binlinks ; do
							# Next line is equiv to csh: set name=$bin:t
							name=`expr //$bin : '.*/\(.*\)'`
							echo "    ${LN} $fulldir/$bin $AUTOSYMLINKDIR/$name"
						done
					fi
				done
			fi
			echo ""
			echo ""
			echo $EB'Do you want to proceed with the installation (YES/NO)? '$EE
			read A
			if [ "$A" = "YES" -o "$A" = "Y" -o "$A" = "yes" -o "$A" = "y" -o "$A" = "Yes" ] ; then
				echo ""
				break
			elif [ "$A" = "NO" -o "$A" = "N" -o "$A" = "no" -o "$A" = "n" -o "$A" = "No" ] ; then
				eval ${ABORTCMD}
			else
				echo ""
				echo "You must specify YES or NO.  Try again."
			fi
		done
	fi

	# Can we proceed with the installation?
	if [ $ALLOK1 = 1 ] ; then
		break
	fi
done

$CLEAR
echo "" 
echo ""
echo "Beginning installation..."
echo ""
echo "This may take some time, depending on the number of items"
echo "you have selected and the performance of your chosen device."
echo ""
echo ""

# Build a list of desired packages to extract.
FILELIST=""
for package_num in ${PKGS_TO_INSTALL} ; do
	packagedesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
	pabbr=`eval echo '$PKG_'$package_num'_PKGABBR'`
	pver=`eval echo '$PKG_'$package_num'_PKGVERS'`
	package_dir=$pabbr"_"$pver
	FILELIST=${FILELIST}\'$package_dir\'' '
done

# Extract the desired packages.
if [ "$RHOST" = "" ] ; then
	TARCMD="$TAR $TAR_OPTS $DEVPATH ${FILELIST}"
else
	TARCMD="rsh -n $RHOST dd if=$DEVPATH | $TAR $TAR_OPTS ${FILELIST}"
fi
olddir=`pwd`
cd $TOPDIR
eval "${TARCMD}"
cd $olddir

ALREADY_XKEYSYMDB=0
LMFEATURELIST=""
for package_num in 0 ${PKGS_TO_INSTALL} ; do
	packagedesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
	pabbr=`eval echo '$PKG_'$package_num'_PKGABBR'`
	pver=`eval echo '$PKG_'$package_num'_PKGVERS'`
	package_dir=$pabbr"_"$pver
	fulldir=$TOPDIR/$package_dir

	# Install makelinks scripts for all installed packages in /tmp if "makescript" and
	# any symlinks in this installation.
	# Install makelinks scripts for each package in installscripts/ if
	# package_num>0 and any symlinks.
	if [ $package_num != 0 -o "$AUTOSYMLINK" = "makescript" -a $ANYSYMLINKS = 1 ] ; then

		# Put a script in $SYMLINKSCRIPT that creates symbolic
		# links for all installed packages. Also, put a
		# script in the installscripts directory for each package which
		# can be run to create links for that package.
		# The "0" option below covers the $SYMLINKSCRIPT case.
		binlist=""
		if [ "$package_num" = 0 ] ; then
			scriptfile="$SYMLINKSCRIPT"
			# Construct a list of absolute paths to launch scripts.
			for package_num0 in ${PKGS_TO_INSTALL} ; do
				pabbr0=`eval echo '$PKG_'$package_num0'_PKGABBR'`
				pver0=`eval echo '$PKG_'$package_num0'_PKGVERS'`
				package_dir0=$pabbr0"_"$pver0
				fulldir0=$TOPDIR/$package_dir0
				binlinks0=`eval echo '$PKG_'$package_num0'_BINLINKS'`
				ntokens0=`echo $binlinks0 | wc -w`
				if [ $ntokens0 -gt 0 ] ; then
					for bin0 in $binlinks0 ; do
						binlist="$binlist $fulldir0/$bin0"
					done
				fi
			done
		else
			binlinks=`eval echo '$PKG_'$package_num'_BINLINKS'`
			ntokens=`echo $binlinks | wc -w`
			if [ $ntokens -gt 0 ] ; then
				scriptdir=$fulldir/installscripts
				if [ ! -d "$scriptdir" ] ; then
					$MKDIR $scriptdir
				fi
				scriptfile="$scriptdir"/makelinks
				for bin in $binlinks ; do
					binlist="$binlist $bin"
				done
			else
				continue
			fi
		fi
		echo '#!/bin/sh
# Shell script for automatically installing launch scripts and
# other small programs into an alternate launch script directory.' > "$scriptfile"
						echo 'binlinks="'"$binlist"'"' >> "$scriptfile"
						echo 'LOOP_LIMIT='$LOOP_LIMIT >> "$scriptfile"
						echo 'defaultinstalldir="'"$fulldir"'"' >> "$scriptfile"
						echo 'defaultdir="/usr/bin"
# For echo without newline under BSD, set EB and EE variables
MKDIR="/usr/bin/mkdir -p "
RMDIR="/usr/bin/rmdir "
LN="/usr/bin/ln -s"
RM="/usr/bin/rm -f"
ECHO=/usr/bin/echo
SED=/usr/bin/sed
LS=/usr/bin/ls
EXPR=/usr/bin/expr
PWDPROG=/usr/bin/pwd
EB="-n "
EE=""
osname="UNKNOWN"
osversion="UNKNOWN"
if [ -x /bin/uname ]
then
	osname=`/bin/uname -s`
	osversion=`/bin/uname -r`
	check=`echo "$osversion" | egrep '\''^[0-9]\.[0-9]*'\''`
	if [ "$check" != "" ]
	then
		# osmajorminor will be like "4.2". osmajor: "4". osminor:"2".
		osmajorminor=`echo "$osversion" | sed -e '\''s/^\([0-9]\.[0-9]\).*/\1/'\''`
		osmajor=`echo "$osversion" | sed -e '\''s/^\([0-9][0-9]*\).*/\1/'\''`
		osminor=`echo "$osversion" | sed -e '\''s/^[0-9]\.\([0-9][0-9]*\).*/\1/'\''`
	else
		osversion="UNKNOWN"
	fi
fi
if [ $osname = "SunOS" ]
then
	RETURNKEYNAME="Return"
	if [ $osmajor -ge 5 ]
	then
		# For echo without newline under Sys V, set EB and EE variables
		EB=""
		EE="'\\\\'c"
		PATH=/usr/sbin:/usr/bin:/bin:/usr/bin/X11:/usr/openwin/bin:/sbin:/usr/sbin:/etc:/usr/etc
	else
		# For echo without newline under BSD, set EB and EE variables
		EB="-n "
		EE=""
		PATH=/usr/bin:/bin:/usr/bin/X11:/usr/openwin/bin:/sbin:/etc:/usr/etc
	fi

elif [ $osname = "IRIX" ]
then
	RETURNKEYNAME="Enter"
	# For echo without newline under Sys V, set EB and EE variables
	EB=""
	EE="'\\\\'c"
	PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/bin/X11:/usr/openwin/bin:/etc:/usr/etc
fi
if [ "$osname" = "UNKNOWN" -o "$osversion" = "UNKNOWN" ]
then
	echo ""
	echo "Unrecognized operating system. Cannot make links."
	exit 1
fi
installdir="$defaultinstalldir"
# Try to determine the parent directory to this launch script.
# Follow any symbolic links in thisscriptname.
thisscriptname=$0
while :
do
	lsresult=`$LS -l $thisscriptname`
	symlink=`$EXPR "$lsresult" : '\''.*>'\''.*`
	if [ "$symlink" -gt 0 ]
	then
		oldscriptname="$thisscriptname"
		thisscriptname=`$ECHO $lsresult|$SED -e '\''s/^.*-> *\(.*\) *$/\1/g'\''`
		abspath_new=`$EXPR "$thisscriptname" : '\''^/'\''`
		if [ $abspath_new != 1 ]
		then
			abspath_old=`$EXPR "$oldscriptname" : '\''^/'\''`
			if [ $abspath_old != 1 ]
			then
				olddir=`$PWDPROG`
			else
				olddir=`$EXPR "$oldscriptname" : '\''\(.*\)/'\''` 
			fi
			thisscriptname="$olddir/$thisscriptname"
		fi
	else
		break
	fi
done
# Determine directory containing this shell script.
scriptdir=`$EXPR $thisscriptname : '\''\(.*\)/'\''` 
if [ "$scriptdir" = "" -o "$scriptdir" = "." ]
then
	scriptdir=`$PWDPROG`
fi
# If scriptdir is /tmp, then do not try to override defaultdir.
if [ "$scriptdir" != "/tmp" ]
then
	# Determine root directory for installation ($scriptdir/..).
	parentdir=`$EXPR $scriptdir : '\''\(.*\)/'\''` 
	if [ "$parentdir" != "" ]
	then
		installdir="$parentdir"
	fi
fi
echo ""
echo ""
echo "Enter the full path of the directory into which you want to create"
echo "symbolic links for the launch scripts and other small programs"
echo $EB"[Press $RETURNKEYNAME for /usr/bin]: "$EE
read launchdir
if [ "$launchdir" = "" ] 
then
	launchdir="$defaultdir"
fi
if [ ! -d "$launchdir"  ] 
then
	if $MKDIR $launchdir
	then error=0
	else error=1
	fi
	if [ $error != 0  ]
	then
		echo "Cannot create directory $launchdir"
		echo "You must choose different options or change permissions"
		echo "and then rerun this script."
		exit 1
	fi
	chmod u+w "$launchdir"
fi
if [ ! -w $launchdir ]
then
	echo ""
	echo ""
	echo "You do not have permission to write to $launchdir."
	echo "You must choose different options or change permissions"
	echo "and then rerun this script."
	exit 1
fi
makelinks_loop=0
while :
do
	makelinks_loop=`expr $makelinks_loop + 1`
	if [ $makelinks_loop -ge $LOOP_LIMIT ]
	then
		echo ""
		echo "LOOP_LIMIT exceeded."
		exit 1
	fi
	echo ""
	echo ""
	echo "This script will issue the following commands to install the"
	echo "launch scripts and other small programs:"
	echo ""
	for bin in $binlinks ; do
		# Next line extracts filename from full path
		name=`expr //$bin : '\''.*/\(.*\)'\''`
		abspath_bin=`$EXPR "$bin" : '\''^/'\''`
		if [ $abspath_bin != 1 ] ; then
			echo ${LN} "$installdir/$bin" "$launchdir/$name"
		else
			echo ${LN} "$bin" "$launchdir/$name"
		fi
	done
	echo ""
	echo $EB"OK to proceed (YES/NO)? "$EE
	read A
	if [ "$A" = "YES" -o "$A" = "Y" -o "$A" = "yes" -o "$A" = "y" -o "$A" = "Yes" ] ; then
		break
	elif [ "$A" = "NO" -o "$A" = "N" -o "$A" = "no" -o "$A" = "n" -o "$A" = "No" ] ; then
		DOSYMLINKS=0
		echo "Installation of launch scripts and other small programs cancelled."
		exit 1
	else
		echo ""
		echo "You must specify YES or NO.  Try again."
	fi
done

for bin in $binlinks ; do
	# Next line extracts filename from full path
	name=`expr //$bin : '\''.*/\(.*\)'\''`
	if [ -f "$launchdir/$name" -o -d "$launchdir/$name" -o -h "$launchdir/$name" ]
	then
		overwritelink_loop=0
		while :
		do
			overwritelink_loop=`expr $overwritelink_loop + 1`
			if [ $overwritelink_loop -ge $LOOP_LIMIT ] ; then
				echo ""
				echo "LOOP_LIMIT exceeded."
				eval ${ABORTCMD}
			fi
			echo ""
			echo "File $launchdir/$name already exists. OK to replace"
			echo $EB"(YES/NO)? "$EE
			read A
			if [ "$A" = "YES" -o "$A" = "Y" -o "$A" = "yes" -o "$A" = "y" -o "$A" = "Yes" ] ; then
				${RM} "$launchdir/$name"
				abspath_bin=`$EXPR "$bin" : '\''^/'\''`
				if [ $abspath_bin != 1 ] ; then
					${LN} "$installdir/$bin" "$launchdir/$name"
				else
					${LN} "$bin" "$launchdir/$name"
				fi
				break
			elif [ "$A" = "NO" -o "$A" = "N" -o "$A" = "no" -o "$A" = "n" -o "$A" = "No" ] ; then
				break
			else
				echo ""
				echo "You must specify YES or NO.  Try again."
			fi
		done
	else
		abspath_bin=`$EXPR "$bin" : '\''^/'\''`
		if [ $abspath_bin != 1 ] ; then
			${LN} "$installdir/$bin" "$launchdir/$name"
		else
			${LN} "$bin" "$launchdir/$name"
		fi
	fi
done
echo ""
echo ""
echo "Installation of launch scripts and other small programs successful."
echo ""
' >> "$scriptfile"
		chmod 777 "$scriptfile"
	fi

	# Skip the rest of the processing for package_num = 0
	if [ "$package_num" = 0 ] ; then
		continue
	fi

	if [ ! -d ${fulldir} ] ; then
		echo ""
		echo $EB"Your "$EE
		if [ $USECD = 1 ] ; then
			echo $EB"CD-ROM "$EE
		else
			echo $EB"tape "$EE
		fi
		if [ "$RHOST" = "" ] ; then
		   echo "could not be read from $DEVPATH."
		else
		   echo "could not be read from $DEVPATH on $RHOST."
		fi
		eval "${RM} ${FILELIST}"
		eval ${ABORTCMD}
	fi

	# Force proper permissions.
	# Comment out for now. Assume permissions were set properly
	# when application created the tree for each package.
	#find $fulldir -type f -exec chmod a+r,a-w {} \;
	#find $fulldir -type d -exec chmod 755 {} \;
	#chown -Rf root.staff $fulldir

	# Establish automatic symbolic links if so desired.
	if [ $DOSYMLINKS = 1 ] ; then
		binlinks=`eval echo '$PKG_'$package_num'_BINLINKS'`
		ntokens=`echo $binlinks | wc -w`
		if [ $ntokens -gt 0 ] ; then
			for bin in $binlinks ; do
				# Next line is equiv to csh: set name=$bin:t
				name=`expr //$bin : '.*/\(.*\)'`
				${LN} $fulldir/$bin $AUTOSYMLINKDIR/$name
			done
		fi
	fi

	# Put addlicense and requestlicense scripts in correct place.
	lmfeature=`eval echo '$PKG_'$package_num'_LMFEATURE'`
	lmversion=`eval echo '$PKG_'$package_num'_LMVERSION'`
	lmquotes=`eval echo '$PKG_'$package_num'_LMQUOTES'`
	pkgdesc=`eval echo '$PKG_'$package_num'_PKGDESC'`
	pkgvers=`eval echo '$PKG_'$package_num'_PKGVERS'`
	ntokens=`echo $lmfeature | wc -w`
	if [ $ntokens -gt 0 ] ; then
		licensedir=$fulldir/installscripts
		if [ ! -d "$licensedir" ] ; then
			$MKDIR "$licensedir"
		fi
		num=1
		while [ $num -le $ntokens ] ; do
			lmfeat=`eval 'echo $lmfeature | awk '\''{ print $'$num' }'\'`
			lmvers=`eval 'echo $lmversion | awk '\''{ print $'$num' }'\'`
			lmquot=`eval 'echo $lmquotes | awk '\''{ print $'$num' }'\'`
			already_lmfeat=`echo $LMFEATURELIST | grep '^'"$lmfeat"'$'`
			# Skip this if this feature has already been processed.
			if [ "$already_lmfeat" != "" ] ; then
				break
			fi
			LMFEATURELIST=$LMFEATURELIST$lmfeat'
'

			# Copy addlicense script to ./installscripts and
			# automatically make changes in place.
			addlicensefname="$licensedir/$lmfeat"'.addlicense'
			if [ -f "$addlicensefname" ] ; then
				licensefname="$SECURITYFILE"
				$CAT "$addlicensefname" \
				| sed 's%^LM_LICENSE_FILE=""$%LM_LICENSE_FILE="'$licensefname'"%' \
				| sed 's%^LM_REF_FILE=""$%LM_REF_FILE="'$LM_FILE'"%' \
				| sed 's%^LM_DAEMON_DIR=""$%LM_DAEMON_DIR="'$DAEMONDIR'"%' \
				| sed 's%^LM_FEATURE=""$%LM_FEATURE="'$lmfeat'"%' \
				| sed 's%^LM_VERSION=""$%LM_VERSION="'$lmvers'"%' \
				| sed 's%^LM_QUOTES=""$%LM_QUOTES="'$lmquot'"%' \
				| sed 's%^PRODUCT_NAME=""$%PRODUCT_NAME="'"$pkgdesc"'"%' \
				| sed 's%^PRODUCT_VERSION=""$%PRODUCT_VERSION="'"$pkgvers"'"%' \
				> "$addlicensefname".temp
				${MV} "$addlicensefname".temp "$addlicensefname"
				chmod 555 $addlicensefname
			fi

			# Copy requestlicense script to ./installscripts and
			# automatically make changes in place.
			requestlicensefname="$licensedir/$lmfeat"'.requestlicense'
			if [ -f "$requestlicensefname" ] ; then
				licensefname="$SECURITYFILE"
				$CAT "$requestlicensefname" \
				| sed 's%^LM_LICENSE_FILE=""$%LM_LICENSE_FILE="'$licensefname'"%' \
				| sed 's%^LM_REF_FILE=""$%LM_REF_FILE="'$LM_FILE'"%' \
				| sed 's%^LM_DAEMON_DIR=""$%LM_DAEMON_DIR="'$DAEMONDIR'"%' \
				| sed 's%^LM_FEATURE=""$%LM_FEATURE="'$lmfeat'"%' \
				| sed 's%^LM_VERSION=""$%LM_VERSION="'$lmvers'"%' \
				| sed 's%^LM_QUOTES=""$%LM_QUOTES="'$lmquot'"%' \
				| sed 's%^PRODUCT_NAME=""$%PRODUCT_NAME="'"$pkgdesc"'"%' \
				| sed 's%^PRODUCT_VERSION=""$%PRODUCT_VERSION="'"$pkgvers"'"%' \
				> "$requestlicensefname".temp
				${MV} "$requestlicensefname".temp "$requestlicensefname"
				chmod 555 $requestlicensefname
			fi
			num=`expr $num + 1`
		done
	fi

	# Write out PSRES_PATH to PSRES_FILE, if necessary.
	if [ "$PSRES_WRITEFILE" = "y" ] ; then
		abspath=`expr $PSRES_FILE : '^/'`
		if [ $abspath = 1 ] ; then
			psres_file="$PSRES_FILE"
		else
			psres_file=${fulldir}'/'"$PSRES_FILE"
		fi
		# Determine parent dir for psres_file and make, if necessary.
		dir=`expr "$psres_file" : '\(.*\)/'`
		if [ ! -d "$dir" ] ; then
			$MKDIR $dir
		fi
		echo '#
# This file contains the default path which the application should use for
# finding its PostScript resources, such as fonts. The format is
# a single line beginning in column 1 of the form SITE_PSRESOURCEPATH=xxx,
# where xxx is a list of directories separated by colons.
# The application might add its own set of directories to this default
# path - consult the application launch script if you have questions.
# Users can override the default path by setting environment variable
# PSRESOURCEPATH to the list of directories to use for PostScript resources.
# If the user sets PSRESOURCEPATH, he is very much encouraged to include a 
# double colon (::) in the path (e.g., /usr/lib/dps/fonts::) so that the 
# application will still find its own default PostScript resources.

SITE_PSRESOURCEPATH='"$PSRES_PATH" > "$psres_file"
	fi

	# Write out LM_FILE with proper value for LM_LICENSE_FILE, if necessary.
	if [ "$LM_WRITEFILE" = "y" ] ; then
		abspath=`expr $LM_FILE : '^/'`
		if [ $abspath = 1 ] ; then
			lm_file="$LM_FILE"
		else
			lm_file=${fulldir}'/'"$LM_FILE"
		fi
		# Determine parent dir for lm_file and make, if necessary.
		dir=`expr "$lm_file" : '\(.*\)/'`
		if [ ! -d "$dir" ] ; then
			$MKDIR $dir
		fi
		echo '#
# This file contains the path which the application should use for
# finding its license data file. The format is a single line beginning
# in column 1 of the form LM_LICENSE_FILE=xxx, where xxx is usually a
# single file name but can be a list of files separated by colons.

LM_LICENSE_FILE='"$SECURITYFILE" > "$lm_file"
	fi

	# Copy files such as README from CDROM to installation tree, if so requested.
	cdrom_fromfiles=`eval echo '$PKG_'$package_num'_CDROM_FROMFILES'`
	if [ "$cdrom_fromfiles" = "" ] ; then
		# Backwards compatibility. Also accept CDROM_FROMFILE
		cdrom_fromfiles=`eval echo '$PKG_'$package_num'_CDROM_FROMFILE'`
	fi
	cdrom_tofiles=`eval echo '$PKG_'$package_num'_CDROM_TOFILES'`
	if [ "$cdrom_tofiles" = "" ] ; then
		# Backwards compatibility. Also accept CDROM_TOFILE
		cdrom_tofiles=`eval echo '$PKG_'$package_num'_CDROM_TOFILE'`
	fi
	ntokens_from=`echo $cdrom_fromfiles | wc -w`
	ntokens_to=`echo $cdrom_tofiles | wc -w`
	if [ $ntokens_from -eq $ntokens_to -a $ntokens_from -gt 0 ] ; then
		i=1
		for fromfile in $cdrom_fromfiles ; do
			eval fromfile_$i=$fromfile
			i=`expr $i + 1`
		done
		i=1
		for tofile in $cdrom_tofiles ; do
			eval tofile_$i=$tofile
			i=`expr $i + 1`
		done
		i=1
		while [ $i -le $ntokens_from ] ; do
			eval fromfile=\$fromfile_$i
			eval tofile=\$tofile_$i
			if [ "$fromfile" != "" -a -f "$cddir/$fromfile" ] ; then
				$RM "$fulldir/$tofile"
				$CP -p "$cddir/$fromfile" "$fulldir/$tofile"
			fi
			i=`expr $i + 1`
		done
	fi

	# Run the post-installation scripts, if present
	script=`eval echo '$PKG_'$package_num'_SCRIPT'`
	ntokens=`echo $script | wc -w`
	if [ $ntokens -gt 0 ] ; then
		script=$fulldir"/"$script
		if [ ! -f "$script" ] ; then
			echo ""
			echo "Install script error:"
			echo "Cannot find post-install script $script."
			eval "${RM} ${FILELIST}"
			eval ${ABORTCMD}
		fi
		if [ ! -x "$script" ] ; then
			echo ""
			echo "Install script error:"
			echo "Cannot execute post-install script $script."
			eval "${RM} ${FILELIST}"
			eval ${ABORTCMD}
		fi
		if $script $fulldir $SECURITYFILE ; then error=0; else error=1; fi
		if [ $error != 0  ] ; then
			echo "Post installation script returned an unexpected error code!"
			eval "${RM} ${FILELIST}"
			eval ${ABORTCMD}
		fi
	fi

	xkeysymdb=`eval echo '$PKG_'$package_num'_XKEYSYMDB'`
	if [ "$xkeysymdb" = 1 ] ; then
		# Write out XKeysymDB file.
		$MKDIR ${fulldir}/${XKEYSYMDBDIR}
		fixfile=${fulldir}/${XKEYSYMDBDIR}/${XKEYSYMDBFILE}
		if [ -r ${fixfile} -a ! -w ${fixfile}  ] ; then
			echo ""
			echo "${fixfile} already exists and this script cannot overwrite."
		else
			${RM} ${fixfile}
			echo '!' > ${fixfile}
			echo '!		OSF Keysyms' >> ${fixfile}
			echo '!' >> ${fixfile}
			echo 'osfBackSpace			:1004FF08' >> ${fixfile}
			echo 'osfInsert			:1004FF63' >> ${fixfile}
			echo 'osfDelete			:1004FFFF' >> ${fixfile}
			echo 'osfCopy				:1004FF02' >> ${fixfile}
			echo 'osfCut				:1004FF03' >> ${fixfile}
			echo 'osfPaste			:1004FF04' >> ${fixfile}
			echo '' >> ${fixfile}
			echo 'osfAddMode			:1004FF31' >> ${fixfile}
			echo 'osfPrimaryPaste			:1004FF32' >> ${fixfile}
			echo 'osfQuickPaste			:1004FF33' >> ${fixfile}
			echo '' >> ${fixfile}
			echo 'osfPageUp			:1004FF41' >> ${fixfile}
			echo 'osfPageDown			:1004FF42' >> ${fixfile}
			echo '' >> ${fixfile}
			echo 'osfEndLine			:1004FF57' >> ${fixfile}
			echo 'osfBeginLine			:1004FF58' >> ${fixfile}
			echo '' >> ${fixfile}
			echo 'osfActivate			:1004FF44' >> ${fixfile}
			echo '' >> ${fixfile}
			echo 'osfMenuBar			:1004FF45' >> ${fixfile}
			echo '' >> ${fixfile}
			echo 'osfClear			:1004FF0B' >> ${fixfile}
			echo 'osfCancel			:1004FF69' >> ${fixfile}
			echo 'osfHelp				:1004FF6A' >> ${fixfile}
			echo 'osfMenu				:1004FF67' >> ${fixfile}
			echo 'osfSelect			:1004FF60' >> ${fixfile}
			echo 'osfUndo				:1004FF65' >> ${fixfile}
			echo '' >> ${fixfile}
			echo 'osfLeft				:1004FF51' >> ${fixfile}
			echo 'osfUp				:1004FF52' >> ${fixfile}
			echo 'osfRight			:1004FF53' >> ${fixfile}
			echo 'osfDown				:1004FF54' >> ${fixfile}
		fi

		if [ "$ALREADY_XKEYSYMDB" != 1 ] ; then
			# check if XKeysymDB file contains osf bindings. If it doesn't then
			# append them to /usr/openwin/lib/XKeysymDB file. On many systems
			# XKeysymDB file contains keysym like osfXK_. These are wrong so
			# just ignore them

			if grepout=`grep -v '^osfXK' "$KEYSYMDBFILE" | grep '^osf'` ; then status=0; else status=1; fi
			if [ $status != 0 ] ; then
				echo ""
				echo "It seems that your $KEYSYMDBFILE does not contain"
				echo "OSF keysyms."
				# The next line is equiv to csh: set dirpath=$KEYSYMDBFILE:h
				dirpath=`expr $KEYSYMDBFILE : '\(.*\)/' \| $KEYSYMDBFILE`
				if [ ! -w $KEYSYMDBFILE -o ! -w $dirpath  ] ; then
					echo "This script does not have permission to automatically alter $KEYSYMDBFILE."
					echo "In case you see messages complaining about unknown OSF keysyms"
					echo "at program startup, then append file ${fixfile}"
					echo "to the end of $KEYSYMDBFILE."
				else
					echo "Appending additional keysyms to $KEYSYMDBFILE."
					echo "Old $KEYSYMDBFILE file will be saved in ${KEYSYMDBFILE}.org"
					$RM ${KEYSYMDBFILE}.org
					$MV $KEYSYMDBFILE ${KEYSYMDBFILE}.org
					$CAT ${KEYSYMDBFILE}.org ${fixfile} > $KEYSYMDBFILE
				fi
			else
				echo ""
				echo "It is good that you have OSF keysyms in $KEYSYMDBFILE."
				echo "In case you see messages complaining about unknown OSF keysyms"
				echo "at program startup, then append ${fixfile}"
				echo "to the end of $KEYSYMDBFILE"
			fi
			ALREADY_XKEYSYMDB=1
		fi
	fi
done

echo ""
echo ""
echo "*** Installation complete ***"
echo ""

# Notify user that license keys are needed.
if [ $ALLOK1 = 1 -a $ANYSECURED = 1 ] ; then
	echo ""
	echo "You will need license activation keys for the following applications:"
	echo ""
	LMFEATURELIST=""
	for package_num in ${PKGS_TO_INSTALL} ; do
		lmfeat=`eval echo '$PKG_'$package_num'_LMFEATURE'`
		ntokens=`echo $lmfeat | wc -w`
		if [ $ntokens -gt 0 ] ; then
			already_lmfeat=`echo $LMFEATURELIST | grep '^'"$lmfeat"'$'`
			# Skip this if this feature has already been processed.
			if [ "$already_lmfeat" != "" ] ; then
				break
			fi
			LMFEATURELIST=$LMFEATURELIST$lmfeat'
'
			echo "        "$lmfeat
		fi
	done
	echo ""
	echo "Refer to the Getting Started guide for information on how to"
	echo "obtain and install your license activation keys."
	echo ""
fi

${RM} $PKGLISTFILE
exit 0

