#!/bin/sh
#Tag 0x006d
# Copyright (c) 1993 by Adobe Systems Incorporated.
# All rights reserved.
#
# Shell script for launching Adobe Type Installer.
#
# In general, this script accepts command line parameters in the form:
#	-e xxx=yyy
# where "xxx" is a shell variable name and "yyy" is the value.
# For each parameter of this form, this script does an eval on the parameter.
#
###################################################################

productname="typeinstaller"
execname="typeinstaller_exec"
REQUIRED_CHIP_LIST="mips"
REQUIRED_OS_LIST="irix5"
EXEC_COMMAND=

# Not all platforms support "putenv" library call
PUTENV_LIBRARY_CALL=1

LS=/bin/ls
export PATH
PATH=/usr/bin/X11:/usr/bin:$PATH

# Determine the OS/productversion/chip/GUI
# appropriate for the current user based on the computer
# he is currently logged into.
os="UNKNOWN"
osname="UNKNOWN"
osversion="UNKNOWN"
osvers1="UNKNOWN"
osvers2="UNKNOWN"
osvers3="UNKNOWN"
error=0
if [ -r /bin/uname ]
then
	osname=`/bin/uname -s`
        # 64 bit IRIX6 returns IRIX64 for uname -s
	firstfour=`echo "$osname" | sed -e 's/^\(....\).*$/\1/g'`
        if [ "$firstfour" = "IRIX" ] ; then
                osname="IRIX"
        fi
	osversion=`/bin/uname -r`
	check2=`echo "$osversion" | egrep '^[0-9]*\.[0-9]*'`
	check3=`echo "$osversion" | egrep '^[0-9]*\.[0-9]*\.[0-9]*'`
	if [ "$check3" != "" ]
	then
		osvers1=`echo "$osversion" | sed -e 's/^\([0-9][0-9]*\).*/\1/'`
		osvers2=`echo "$osversion" | sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'`
		osvers3=`echo "$osversion" | sed -e 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'`
	elif [ "$check2" != "" ]
	then
		osvers1=`echo "$osversion" | sed -e 's/^\([0-9][0-9]*\).*/\1/'`
		osvers2=`echo "$osversion" | sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'`
	fi
fi
chip="UNKNOWN"

if [ "$osname" = "SunOS" ]
then
	PATH=/usr/openwin/bin:$PATH

	# Sun machines: we only support Sparc under SunOS5.3
	if [ -r /usr/bin/sparc ] && /usr/bin/sparc ; then
		chip="sparc"
		if [ "$osvers2" = "UNKNOWN" ] ; then
			echo Invalid operating system version returned from 'uname -r': $osversion$bell.
			error=1
		fi
		if [ "$osvers1" = "5" ] ; then
 			if [ "$osvers2" -lt 3 ] ; then
				echo Unsupported operating system version: $osversion. SunOS 5.3 is required.
				error=1
			else
				os="sunos5.3"
			fi
		elif [ "$osvers1" -gt "5" ] ; then
			os="sunos5.3"
		else
			echo Invalid operating system version returned from 'uname -r': $osversion$bell.
			error=1
		fi
	else
		echo $productname is not available for your type of Sun machine$bell.
		error=1
	fi

elif [ "$osname" = "ULTRIX" ]
then
	# Dec/Ultrix machines: we only support Ultrix4.2
	if [ -r /bin/machine ]
	then
		chip=`/bin/machine`
	fi
	if [ "$chip" = "mips" ]
	then
		if [ "$osvers1" = "4" ] && [ "$osvers2" -ge 2 ]
		then
			os="ultrix4.2"
		else
			echo Invalid operating system version returned from 'uname -r': $osversion$bell.

			error=1
		fi
	else
		echo $productname is not available for your type of Dec machine$bell.
		error=1
	fi

elif [ "$osname" = "IRIX" ]
then
	if [ -r /bin/mips ] && /bin/mips
	then
		chip="mips"
		if [ "$osvers1" -ge "5" ]
		then
			os="irix5"
		else
			echo Invalid operating system version returned from 'uname -r': $osversion$bell.
			error=1
		fi
	else
		echo $productname is not available for your type of SGI machine$bell.
		error=1
	fi
fi
chip_found=0
for i in $REQUIRED_CHIP_LIST; do
	if [ $i = $chip ] ; then
		chip_found=1
		break
	fi
done
if [ $chip_found != 1 ] ; then
	echo "This version of the application requires the following CPU: $REQUIRED_CHIP_LIST."
	error=1
fi
os_found=0
for i in $REQUIRED_OS_LIST; do
	if [ $i = $os ] ; then
		os_found=1
		break
	fi
done
if [ $os_found != 1 ] ; then
	echo "This version of the application requires the following OS: $REQUIRED_OS_LIST."
	error=1
fi
if [ $error != 0 ] ; then
	exit
fi

# <INSTALL_DIR> holds the directory into which the product
# was installed (e.g., /usr/adobe/ATI_1.0).
# This script computes the value of INSTALL_DIR as follows:
#	1) If environment variable ATI_HOME has a value, then that is used.
#	2) Otherwise, try to determine it automatically by determining the
#		location of this launch script and using its parent directory.
#		If file <parent directory>/exec/ati_exec exists, then assume
#		we have determined the parent directory correctly.
#	3) Otherwise, use the value hardcoded into this script.
INSTALL_DIR=
if [ "$ATI_HOME" != "" ] ; then
	INSTALL_DIR="$ATI_HOME"
else
	# Try to determine automatically the parent directory to this launch script.
	thisscriptname=$0

	# Follow any symbolic links in thisscriptname.
	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=`pwd`
				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=`pwd`
	fi

	# Determine root directory for installation ($scriptdir/..).
	parentdir=`expr $scriptdir : '\(.*\)/'` 

	if [ -r "$parentdir/exec/$execname" ] ; then
		INSTALL_DIR="$parentdir"
	fi
fi

# <SITE_PSRESOURCEPATH> is a list of directories containing
# site-specific PostScript resources (such as fonts) that might
# be useful to this application.
# This launch script first looks for a file of the name
# $INSTALL_DIR/custom/SITE_PSRESOURCEPATH and looks for a line in this file
# of the form "SITE_PSRESOURCEPATH=xxx" (must start in column 1)
# and sets environment variable SITE_PSRESOURCEPATH to xxx.
# If this application does not find it PostScript resources properly, it could
# be that this file is missing or has an incorrect value.
# If so, edit this file with a text editor.
# Alternatively, you can override the value of SITE_PSRESOURCEPATH by launching
# this script with '-e SITE_PSRESOURCEPATH=xxx' command line arguments.
# Finally, if $INSTALL_DIR/custom/SITE_PSRESOURCEPATH does not have a valid
# entry and if no '-e SITE_PSRESOURCEPATH=xxx' option is given, then this
# script will use the value of SITE_PSRESOURCEPATH that was inherited from the
# user's current environment.
if [ -f "$INSTALL_DIR/custom/SITE_PSRESOURCEPATH" ] ; then
	site_path=`grep '^SITE_PSRESOURCEPATH' "$INSTALL_DIR/custom/SITE_PSRESOURCEPATH"  | sed -e 's/^SITE_PSRESOURCEPATH= *\([^ ]\)/\1/'`
	if [ "$site_path" != "" ] ; then
		eval SITE_PSRESOURCEPATH="$site_path"
	fi
fi

# Directory for $execname
execdir="$INSTALL_DIR/exec"

# Save tail of argv[0] in environment variable RESOURCE_NAME.  This value
# will be used by Xt to establish the name of the app, instead of using
# the argv[0] found by the executable (i.e., ati_exec).  This allows
# users to get the expected app name, based on the name of the script
# they are invoking.  (This also allows the "-name" command-line argument
# to take precedence, as it should.)
RESOURCE_NAME=`basename $0`

# Set up environment variable XFILESEARCHPATH
# so TypeInstaller can find its resource files
XFILESEARCHPATH="$INSTALL_DIR/%L/%T/%N%S:$INSTALL_DIR/%l/%T/%N%S:$INSTALL_DIR/%T/%N%S${XFILESEARCHPATH+:$XFILESEARCHPATH}"
export XFILESEARCHPATH

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

	# "-help" prints a usage message and then exits.
	if [ "$1" = "-help" ] ; then
		echo ""
		echo "Usage: $RESOURCE_NAME [options] [list of files]"
		echo ""
		echo "Adobe Type Installer launch script. Options:"
		echo "    -display <display>"
		echo "        This option specifies the host and display to use."
		echo "    -help"
		echo "        Prints the more common command-line options."
		echo "    -iconic"
		echo "        Launches $RESOURCE_NAME in an iconic state on the desktop."
		echo "    -xrm <X resource specification>"
		echo "        Standard X Window System resource specification on command line."
		echo ""
		exit 0

	# "-e" allows particular values from this script
	# to be overwritten from the command line.
	#
	# We insist that all of these "-e" args must come at the start
	# of the command line.  Any others will be passed along to the
	# application
	elif [ "$1" = "-e" ] ; then
		shift
		eval "$1"
		shift
	elif [ "$1" = "-n" ] ; then
		shift
		EXEC_COMMAND=echo
	else
		break
	fi
done

# Check for DPS freeze patch
if [ "$osname" = SunOS -a "$osvers1" -eq 5 -a "$osvers2" -le 3 ] ; then
    # Patches will end up with '<patchnum> <rev> <patchnum> <rev>...'
    patches=`/usr/bin/showrev -p | /usr/bin/awk '{ print $2; }' | /usr/bin/sed 's/-/ /g' | /usr/bin/tr '\012' ' '`
    patch_101362_08=0
    patchnum=0
    for value in $patches; do
        if [ $patchnum = 0 ] ; then
        patchnum=$value
        else
        rev=$value
        if [ "$patchnum" -eq 101362 -a "$rev" -ge 08 ] ; then
            patch_101362_08=1
        fi
        patchnum=0
        fi
    done
    if [ $patch_101362_08 = 0 ] ; then
        echo ""
        echo 'Warning: patch 101362-08 (or greater) is not installed on this'
        echo 'system and is necessary for certain product functions.'
        echo 'The software may hang without this patch.'
        echo 'Refer to Getting Started guide and readme for more details.'
    fi
fi

# Set the LD_LIBRARY_PATH so that we can use the latest Motif shared libs on
# Solaris 2.3 but let user's choice take precedence on Solaris2.4 and above.
if [ "$osname" = "SunOS" ] ; then
    export LD_LIBRARY_PATH
    if [ "$osmajor" -eq 5 -a "$osminor" -le 3 ] ; then
        LD_LIBRARY_PATH="$INSTALL_DIR/Motiflib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
    else
        LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$INSTALL_DIR/Motiflib"
    fi
fi

# Execute the binary for the application.
# The incantation ${1+"$@"} is black-magic to pass args correctly,
# even if some args contain embedded spaces
$EXEC_COMMAND $execdir/$execname \
	-rootDirectory "$INSTALL_DIR" \
	-siteDefaults "$SITE_PSRESOURCEPATH" \
	${1+"$@"}
