#!/bin/sh
# Copyright (c) 1993 by Adobe Systems Incorporated.
#
# Shell script for launching Photoshop.
#
# 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 that follows -e, this script does an eval on the parameter.
# The following shell variables are reasonable candidates for setting on the 
# command line (see comments below for a description of these variables):
#    LM_LICENSE_FILE
#    PHOTOSHOP_ROOT
#    PHOTOSHOP_VERSION
#    PHOTOSHOP_BUILD
#    CHIP
#    DIRECTXLIB
#    PREPENDFONTDIR
#    NEWFONTCACHE
# Example: photoshop -e LM_LICENSE_FILE=/usr/local/flexlm/licenses/license.dat
###################################################################

# Make sure Berkeley stuff and X stuff is on user's path so hostname can be found.
PATH=$PATH:/usr/ucb:/usr/bsd:/usr/bin/X11
export PATH

MKDIR="/usr/bin/mkdir -p"
LN="/usr/bin/ln -s"
LS=/usr/bin/ls
RM="/usr/bin/rm -f"
CP="/usr/bin/cp"
AWK="/usr/bin/awk"
SED="/usr/bin/sed"
MV="/usr/bin/mv"
USEDIRECTXLIB=0
EXECNAME=Photoshop.MacFiles/AdobePhotoshop2.5.2

OPTIONALS=":AlwaysResizeWindows:DisableClipboardSizeLimit:DisableScratchPageCompression:DontTagRGBPostScriptr:Dynamic Sliders:NeverResizeWindows:"
OptExtDir="Photoshop.MacFiles/Plug-ins/Optional_Extensions"

fontdatefile='.photoshop_fontdatefile'

# Number of processors on this CPU
nprocessors=1

ORIG_LICENSE_FILE="$LM_LICENSE_FILE"
LM_LICENSE_FILE=""

# <INSTALL_DIR> holds the directory into which the product
# was installed (e.g., /usr/adobe/Photoshop_2.5).
# This script computes the value of INSTALL_DIR as follows:
#	1) If environment variable PHOTOSHOP_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>/<executable> exists, then assume
#		we have determined the parent directory correctly.
#	3) Otherwise, use the value hardcoded into this script.
INSTALL_DIR=
if [ "$PHOTOSHOP_HOME" != "" ] ; then
	INSTALL_DIR="$PHOTOSHOP_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 [ -x "$parentdir/$EXECNAME" -o -x "$parentdir/$EXECNAME"_v8 -o -x "$parentdir/$EXECNAME"_v7 ]; then
		INSTALL_DIR="$parentdir"
	fi
fi

# <LM_LICENSE_FILE> is the file containing the license keys for this app.
# If this front-end shell script does not properly set the value of this
# environment variable or the license file does not contain appropriate license
# keys, the product will print an error message at start-up and will not run.
# This launch script gives first priority to the LM_LICENSE_FILE value
# the is passed on the command line via "-e LM_LICENSE_FILE=xxx".
# Second priority goes to the inherited vale of LM_LICENSE_FILE
# environment variable. Thirdly, this launch script first looks for the file of the name
# $INSTALL_DIR/custom/LM_LICENSE_FILE and looks for a line in this file
# of the form "LM_LICENSE_FILE=xxx" (must start in column 1)
# and sets environment variable LM_LICENSE_FILE to xxx.
# If licensing is not working properly, it may because 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 LM_LICENSE_FILE by launching
# this script with '-e LM_LICENSE_FILE=xxx' command line arguments.
export LM_LICENSE_FILE
if [ -f "$INSTALL_DIR/custom/LM_LICENSE_FILE" ] ; then
	CUSTOM_LICENSE_FILE=`grep '^LM_LICENSE_FILE' "$INSTALL_DIR/custom/LM_LICENSE_FILE"  | sed -e 's/^LM_LICENSE_FILE= *\([^ ]\)/\1/'`
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

# Make sure DISPLAY variable has a value
export DISPLAY
if [ "$DISPLAY" = "" ] ; then
    DISPLAY=":0"
else
    # If DISPLAY environment variable is of form <hostname>:0 and <hostname>
    # matches the name of this host, then strip off <hostname> to prevent
    # network accesses. 
    displayhost=`echo $DISPLAY | sed 's/:.*//'`
    if [ "$displayhost" = `hostname` ] ; then
	DISPLAY=`echo $DISPLAY | sed 's/.*:/:/'`
    fi
fi

# Set which version of Photoshop we should run.
DEFAULT_VERSION="2.5.2"
if [ "$PHOTOSHOP_VERSION" = "" ] ; then
	PHOTOSHOP_VERSION="$DEFAULT_VERSION"
fi
DEFAULT_BUILD="rc7"
if [ "$PHOTOSHOP_BUILD" = "" ] ; then
	PHOTOSHOP_BUILD="$DEFAULT_BUILD"
fi

# Determine the OS/productversion/CHIP/GUI
# appropriate for the current user based on the computer
# he is currently logged into.
MACHINE="UNKNOWN"
OS="UNKNOWN"
osname="UNKNOWN"
osversion="UNKNOWN"
osmajorminor="UNKNOWN"
osmajor="UNKNOWN"
osminor="UNKNOWN"
if [ -r /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
CHIP="UNKNOWN"
error=0

if [ "$osname" = "SunOS" ]
then
    PREPENDFONTDIR=1
    TYPE1FONTDIR=/usr/openwin/lib/X11/fonts/Type1/outline
    # Sun machines: we only support Sparc under SunOS5.3
    if [ -r /usr/bin/sparc ] && /usr/bin/sparc
    then
        MACHINE="sparc"
        if [ "$osmajor" = "5" ] && [ "$osminor" -ge 3 ]
        then
            OS="sunos5.3"
            if [ -x /usr/sbin/prtconf ] ; then
		# sort -u is for MP Sparc
                sparcversion=`/usr/sbin/prtconf -vp | fgrep 'sparc-version:' | sort -u | sed 's/.*sparc-version:[ 	0]*//'`
                if [ "$sparcversion" = "" ] ; then
                    sparcversion=7
                fi
            else
                sparcversion=7
            fi

            # Launch different binaries depending on type of Sparc processor.
            CHIP="sparc"
            if [ $sparcversion -gt 7 ] ; then
                CHIPVERSION="v8"
            else
                CHIPVERSION="v7"
            fi

            # Determine number of processors.
            if [ -x /usr/sbin/psrinfo ] ; then
                nprocessors=`/usr/sbin/psrinfo | fgrep -c 'on-line'`
            fi
        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" = "IRIX" ]
then
    PREPENDFONTDIR=0
    # SGI machines: we only support IRIX 5.0
    if [ -r /bin/mips ] && /bin/mips
    then
        MACHINE="mips"
        cpu=`hinv | awk '/^CPU:/ { print substr($3, 1, 2) }'`
        if [ "$cpu" = "R4" ] ; then
            CHIP="r4000"
            ALTCHIP="r3000"
        elif [ "$cpu" = "R3" ] ; then
            CHIP="r3000"
            ALTCHIP=""
        elif [ "$cpu" = "R2" ] ; then
            CHIP="r3000"
            ALTCHIP=""
        else
            echo $productname is not available for your type of SGI machine$bell.
            error=1
        fi
        if [ "$osmajor" = "5" ] && [ "$osminor" -ge 1 ]
        then
            OS="irix5.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 SGI machine$bell.
        error=1
    fi
fi
if [ $error = 1 ] ; then
    exit 1
fi

# We have to warn the users when they try to lauch two Photoshops
if [ `/usr/bin/ps -eafu $USER|grep AdobePhotoshop2.5.2|grep -v grep|wc -l` -gt 0 ] ; then
   if [ "$osname" = "IRIX" ] ; then
	# For SGI we post a confirm. Pass through args so that -display will work.
	# xconfirm ignores unused options from ${1+"$@"} magic.
   	result=`/usr/bin/X11/xconfirm -icon question \
		-t "Photoshop is already running. Running more than" \
		-t "one Photoshop may hang or produce bad effects." \
		-t "Do you want to continue ?" -B Quit -b Continue ${1+"$@"}`
	if [ "$result" = "Quit" ] ; then
		exit 1
	fi
   else
   	# We warn the SUN user
	echo ""
	echo "WARNING: Photoshop is already running. Running more than" 
	echo "         one Photoshop may hang or produce bad effects."
   fi
fi

# <DFT_PHOTOSHOP_ROOT> is the directory relative to $HOME which mirrors
# directory structure of <INSTALL_DIR>. Not used for local installations.
if [ "$DFT_PHOTOSHOP_ROOT" = "" ] ; then
    DFT_PHOTOSHOP_ROOT="$HOME/AdobePhotoshop"
fi

# Set up system dependent variable values.
if [ "$osname" = "IRIX" ] ; then
    DIRECTXLIB=""
else
    if [ "$OPENWINHOME" = "" ] ; then
        export OPENWINHOME
        OPENWINHOME=/usr/openwin
    fi
    PATH=$PATH:$OPENWINHOME/bin

    XILHOME=/opt/SUNWits/Graphics-sw/xil
    export XILHOME

    export LD_LIBRARY_PATH
    if [ "$LD_LIBRARY_PATH" = "" ] ; then
        LD_LIBRARY_PATH=$XILHOME/lib:$OPENWINHOME/lib
    else
        # We need to get direct XLIB stuff correctly, so insert
        # $OPENWINHOME/lib before user's LD_LIBRARY_PATH
        LD_LIBRARY_PATH=$XILHOME/lib:$OPENWINHOME/lib:$LD_LIBRARY_PATH
    fi

    # Location of direct XLIB directory.
    DIRECTXLIB=/opt/SUNWdxlib/bin/dxlib
fi

# Process command line parameters.
while [ $# -gt 0 ] ; do
    # "-e" allows particular values from this script
    # to be overwritten from the command line.
    # For example, -e LM_LICENSE_FILE=/usr/local/licenses
    if [ "$1" = "-e" ] ; then
        shift
        eval "$1"
        shift
    else
        break
    fi
done

# At this stage, if LM_LICENSE_FILE has a value, it came from "-e LM_LICENSE_FILE".
# ORIG_LICENSE_FILE holds value of LM_LICENSE_FILE when launch script was invoked.
# CUSTOM_LICENSE_FILE holds contents from <installdir>/custom/LM_LICENSE_FILE.
# 
# Set LM_LICENSE_FILE to be the union of these three settings.
if [ "$LM_LICENSE_FILE" != "" ] ; then
	if [ "$ORIG_LICENSE_FILE" != "" ] ; then
		LM_LICENSE_FILE="$LM_LICENSE_FILE:$ORIG_LICENSE_FILE"
	fi
else
	LM_LICENSE_FILE="$ORIG_LICENSE_FILE"
fi
if [ "$LM_LICENSE_FILE" != "" ] ; then
	if [ "$CUSTOM_LICENSE_FILE" != "" ] ; then
		LM_LICENSE_FILE="$LM_LICENSE_FILE:$CUSTOM_LICENSE_FILE"
	fi
else
	LM_LICENSE_FILE="$CUSTOM_LICENSE_FILE"
fi


# Set PHOTOSHOP_ROOT if not provided already by user.
# For shared installations, use DFT_PHOTOSHOP_ROOT to set PHOTOSHOP_ROOT.
# Otherwise, set PHOTOSHOP_ROOT to INSTALL_DIR.
if [ "$PHOTOSHOP_ROOT" = "" ] ; then
	PHOTOSHOP_ROOT="$DFT_PHOTOSHOP_ROOT"
fi
if [ ! -d "$PHOTOSHOP_ROOT" ] ; then
    ${MKDIR} "$PHOTOSHOP_ROOT"
fi

# Loop through SITE_PSRESOURCEPATH. If any directories exist and are not on
# the x font path, then add to the x font path.
# For Suns, make sure that /usr/openwin/lib/X11/fonts/Type1/outline is
# on their x font path before creating the font cache.
if [ "$PREPENDFONTDIR" = "1" ] ; then
    # Logic to try to figure out what display Photoshop will display on.
    # Look for -display in command line
    ydisplay=`echo $* | grep '[     ]-display[     ]'`

    # If present, then extract display string.
    if [ "$ydisplay" != "" ] ; then
	display=`echo $* | sed 's/.*-display[     ]*\([^     ]*\).*/\1/'`
    fi

    # Otherwise, look at environment variable.
    if [ "$display" = "" ] ; then
	display="$DISPLAY"
    fi

    # Otherwise, use default display.
    if [ "$display" = "" ] ; then
	display=':0'
    fi

    # Loop through all entries on SITE_PSRESOURCEPATH
    if [ "$SITE_PSRESOURCEPATH" != "" ] ; then
        for sitedir in `echo "$SITE_PSRESOURCEPATH" | awk -F: '{ for (i = 1; i <= NF; ++i) print $i }'`; do
            if [ "$sitedir" != "" ]; then
                fontdir="$sitedir/fonts"
                if [ -d "$fontdir" -a -x "$fontdir" -a -f "$fontdir/fonts.dir" ] ; then
                    found=`xset -display $display q | fgrep "$fontdir"`
                    if [ "$found" = "" -a -d "$fontdir" ] ; then
                
                        # Prepend directory to x font path so that
                        # Photoshop will find the correct fonts when building
                        echo "Prepending directory $fontdir to your X font path"
                        xset -display $display +fp "$fontdir"
                    fi
                fi
            fi
        done
    fi

    if [ "$osname" = "SunOS" ] ; then
        type1found=`xset -display $display q | fgrep 'Type1/outline'`
        if [ "$type1found" = "" -a -d "$TYPE1FONTDIR" -a -f "$TYPE1FONTDIR/fonts.dir" ] ; then
    
            # Prepend Type1 font directory to x font path so that
            # Photoshop will find the correct fonts when building
            echo Prepending directory /usr/openwin/lib/X11/fonts/Type1/outline to your X font path
            xset -display $display +fp $TYPE1FONTDIR
        fi
    fi
fi

# See if we need to rebuild Photoshop font cache by checking
# the results of an "ls -l" on all font directories against the
# version stored in a dot file.
if [ "$NEWFONTCACHE" = "" ] ; then
    if [ -f "$PHOTOSHOP_ROOT/$fontdatefile" ] ; then
        fontdates=`cat $PHOTOSHOP_ROOT/$fontdatefile`
    else
        fontdates=""
    fi
    xfontdirs=`xset q | $AWK '/Font Path:/ { getline; print; }' | $SED 's/,/ /g`
    eval 'targetfontdates=`'"$LS -lLcdg $xfontdirs"'`'

    # Create new font cache if previous installation does not match the new one
    if [ "$fontdates" != "$targetfontdates" ]; then
        ${RM} "$PHOTOSHOP_ROOT/$fontdatefile"
        echo "$targetfontdates" > "$PHOTOSHOP_ROOT/$fontdatefile"
        NEWFONTCACHE=1
    else
        NEWFONTCACHE=0
    fi
fi

# If things are installed properly, PHOTOSHOP_ROOT should be different
# from INSTALL_DIR.
if [ "$PHOTOSHOP_ROOT" = "$INSTALL_DIR" ] ; then
    echo ""
    echo "Incorrect settings for PHOTOSHOP_ROOT and INSTALL_DIR."
    echo "They are both set to: $PHOTOSHOP_ROOT."
    echo "Unable to launch $0."
    echo ""
    exit 1

else

    # Ensure that user has appropriate directories and symbolic
    # links in $HOME/AdobePhotoshop to real Photoshop install.

    # Check file which indicates last version user has run.
    if [ -f "$PHOTOSHOP_ROOT/.photoshop_version" ] ; then
        version=`cat $PHOTOSHOP_ROOT/.photoshop_version`
    else
        version=""
    fi
    targetversion="Photoshop_"$PHOTOSHOP_VERSION$PHOTOSHOP_BUILD"_"$OS"_"$MACHINE"_$INSTALL_DIR"

    # Create new links only if previous installation does not match the new one
    if [ "$version" != "$targetversion" ]; then
 
        ${RM} "$PHOTOSHOP_ROOT/.photoshop_version"
        echo "$targetversion" > "$PHOTOSHOP_ROOT/.photoshop_version"

	# Create directories for Fonts, Prefs, Scratch
        for dir in 'Photoshop.MacFiles/System/Fonts' \
               'Photoshop.MacFiles/System/Preferences' \
               'Photoshop.MacFiles/System/Temporary Items' ; do
            dir="$PHOTOSHOP_ROOT/$dir"
            if [ ! -d "$dir" ] ; then
                ${MKDIR} "$dir"
            fi
        done

	# Create links to standard keyboard (Motif and Macintosh styles) resources
        for dir in 'Photoshop.MacFiles/System/Preferences/Keyboards/Sparc' \
               'Photoshop.MacFiles/System/Preferences/Keyboards/SGI' \
               'Photoshop.MacFiles/System/Preferences/Keyboards/SGI-PS2' \
               'Photoshop.MacFiles/System/Preferences/Keyboards/HP' \
               'Photoshop.MacFiles/System/Preferences/Keyboards/Other' ; do
            dir="$PHOTOSHOP_ROOT"/$dir
            if [ ! -d "$dir" ] ; then
                ${MKDIR} "$dir"
            fi
        done

	subpath="Photoshop.MacFiles/System/Preferences/Keyboards"
	dirlist="Sparc SGI SGI-PS2"
	dft="Default Keyboard"

	for d in $dirlist ; do
	    ${RM} "$PHOTOSHOP_ROOT"/$subpath/$d/*eyboard
	    if [ "_`${LS} ${INSTALL_DIR}/${subpath}/${d}/*eyboard 2>/dev/null`" != '_' ] ; then
	        ${LN} "$INSTALL_DIR"/$subpath/$d/*eyboard "$PHOTOSHOP_ROOT"/$subpath/$d
		${CP} "$INSTALL_DIR/$subpath/$d/%UNIX-PC Keyboard" "$PHOTOSHOP_ROOT/$subpath/$d/%$dft"
		${RM} "$PHOTOSHOP_ROOT/$subpath/$d/$dft"
		${CP} "$INSTALL_DIR/$subpath/$d/UNIX-PC Keyboard" "$PHOTOSHOP_ROOT/$subpath/$d/$dft"
	    fi
	done

	# Create a QuorumApps file so that we don't ask for Application Folder
	${RM} "$PHOTOSHOP_ROOT/Photoshop.MacFiles/System/Preferences/QuorumApps"
	echo '8BIM Photoshop.MacFiles:AdobePhotoshop2.5.2' > "$PHOTOSHOP_ROOT/Photoshop.MacFiles/System/Preferences/QuorumApps"

	# Link Photoshop executable (See end for v7 or v8 version for Sparc)
	file="Photoshop.MacFiles/AdobePhotoshop2.5.2"
	${RM} "$PHOTOSHOP_ROOT/$file"
	if [ "$osname" = "IRIX" ] ; then
   	    ${LN} "$INSTALL_DIR/$file" "$PHOTOSHOP_ROOT/$file"
	fi

	# Create a Plug-ins directory and remove links to Standard plug-ins (Do not
	# remove other directories)
        file="Photoshop.MacFiles/Plug-ins"
        if [ ! -d "$PHOTOSHOP_ROOT/$file" ] ; then
            ${MKDIR} "$PHOTOSHOP_ROOT/$file"
	fi
	${RM} "$PHOTOSHOP_ROOT/$file/Adobe_Standard"
	${RM} "$PHOTOSHOP_ROOT/$file/SGI_Contributed"
	${RM} "$PHOTOSHOP_ROOT/$file/Third_Party"
	# Create new links to standard plug-ins
	# Link v7 or v8 version for Sparc everytime (see end of script)
        if [ "$osname" = "IRIX" ] ; then
	    ${LN} "$INSTALL_DIR/$file/Adobe_Standard" "$PHOTOSHOP_ROOT/$file/Adobe_Standard"

	    # Link SGI extensions and Plug-ins
	    ${LN} "$INSTALL_DIR/$file/SGI_Contributed" "$PHOTOSHOP_ROOT/$file/SGI_Contributed"
	fi
	${LN} "$INSTALL_DIR/$file/Third_Party" "$PHOTOSHOP_ROOT/$file/Third_Party"

	# Create empty Optional_Extensions directories
	file="$OptExtDir"
        if [ ! -d "$PHOTOSHOP_ROOT/$file" ] ; then
            ${MKDIR} "$PHOTOSHOP_ROOT/$file"
	fi

	# link custom brushes, palettes, curves, tutorials, optional_extension
        for dir in 'Brushes_and_Patterns' \
		   'Calibration' \
		   'Color_Palettes' \
		   'Duotone_Curves' \
		   'Tutorial' \
		   'procsets' ; do
            dir="Photoshop.MacFiles/$dir"
            ${RM} -r "$PHOTOSHOP_ROOT/$dir"
            ${LN} "$INSTALL_DIR/$dir" "$PHOTOSHOP_ROOT/$dir"
        done
        
	# Clean up the Fonts directory and relink Quorum fonts.
        ${RM} $PHOTOSHOP_ROOT/Photoshop.MacFiles/System/Fonts/*
        ${LN} $INSTALL_DIR/Photoshop.MacFiles/System/Fonts/* $PHOTOSHOP_ROOT/Photoshop.MacFiles/System/Fonts

	# link Photoshop and System resource files
        for file in 'Photoshop.MacFiles/System/%System' \
                'Photoshop.MacFiles/%AdobePhotoshop2.5.2' ; do
            ${RM} "$PHOTOSHOP_ROOT/$file"
            ${LN} "$INSTALL_DIR/$file" "$PHOTOSHOP_ROOT/$file"
        done

	# link readme file to PHOTOSHOP_ROOT
	file="readme"
	${RM} "$PHOTOSHOP_ROOT/$file"
        ${LN} "$INSTALL_DIR/$file" "$PHOTOSHOP_ROOT/$file"
    fi
fi

# Make sure that Xinet files are not present in the Photoshop.MacFiles area.
file="$PHOTOSHOP_ROOT/Photoshop.MacFiles/.HSancillary"
if [ -f "$file" -o -d "$file" ] ; then
    echo ""
    echo '*** Startup Error ***'
    echo ""
    echo Directory $PHOTOSHOP_ROOT/Photoshop.MacFiles
    echo contains a file/directory named .HSancillary. Photoshop
    echo will not launch with this file/directory present. Please
    echo remove this file/directory and relaunch Photoshop.
    exit 1
fi

# Quorum toolkit needs to be oriented with environment variable QUORUM_ROOT
export QUORUM_ROOT
QUORUM_ROOT="$PHOTOSHOP_ROOT"

# If PHOTOSHOP_DFT_FS is set, set QUORUM_DEFAULT_FS to the value of
# PHOTOSHOP_DFT_FS.
export QUORUM_DEFAULT_FS
case "$PHOTOSHOP_DFT_FS" in
AD|ad|APPLEDOUBLE|appledouble|AppleDouble|NFSShare|NFSshare|NFSSHARE|nfsshare)
    QUORUM_DEFAULT_FS="AD"
    ;;
ETHERSHARE|EtherShare|Ethershare|ethershare|Helios|HELIOS|helios)
    QUORUM_DEFAULT_FS="ETHERSHARE"
    ;;
K-ASHARE|K-AShare|KASHARE|KAShare|kashare|Xinet|XINET|xinet)
    QUORUM_DEFAULT_FS="K-ASHARE"
    ;;
PARTNER|Partner|partner|IPT|ipt)
    QUORUM_DEFAULT_FS="PARTNER"
    ;;
*)
    if [ "$PHOTOSHOP_DFT_FS" != "" ] ; then
        echo ""
        echo "PHOTOSHOP_DFT_FS has an invalid value: $PHOTOSHOP_DFT_FS."
        echo "Valid default file system types are AD, ETHERSHARE, K-ASHARE and PARTNER."
        echo "Will set PHOTOSHOP_DFT_FS to AD (Apple Double)."
    fi
    QUORUM_DEFAULT_FS="AD"
    ;;
esac

# Set the XFILESEARCHPATH so that Photoshop can find the Quorum resource file.
export XFILESEARCHPATH
if [ "$XFILESEARCHPATH" = "" ] ; then
    XFILESEARCHPATH="$INSTALL_DIR/%T/%N%S"
else
    XFILESEARCHPATH="$INSTALL_DIR/%T/%N%S:$XFILESEARCHPATH"
fi

# Set the QUORUM_SERVER_FONTS to just look for Adobe Type 1 scalable fonts
export QUORUM_SERVER_FONTS
if [ "$QUORUM_SERVER_FONTS" = "" ] ; then
    QUORUM_SERVER_FONTS='-adobe-*-*-*-*-*-0-0-0-0-*-*-*-*'
fi

# SUN v7 or v8 binary and plug-in linking.
if [ "$osname" = "SunOS" ] ; then
    # Link the Photoshop execuatble for SUN with every launch
    file="Photoshop.MacFiles/AdobePhotoshop2.5.2"
    ${RM} "$PHOTOSHOP_ROOT/$file"
    ${LN} "$INSTALL_DIR/$file"_"$CHIPVERSION" "$PHOTOSHOP_ROOT/$file"

    # Link Adobe Standard and SUN contributed plug-ins with every launch
    file="Photoshop.MacFiles/Plug-ins"
    ${RM} "$PHOTOSHOP_ROOT/$file/Adobe_Standard"
    ${LN} "$INSTALL_DIR/$file/Adobe_Standard"_"$CHIPVERSION" "$PHOTOSHOP_ROOT/$file/Adobe_Standard"
    ${RM} "$PHOTOSHOP_ROOT/$file/SUN_Contributed"

    echo "Running SUN Photoshop $CHIPVERSION version."
fi

# Determine whether to turn on SXCharged or MPCharged plug-ins.
if [ "$osname" = SunOS ] ; then
    case $PHOTOSHOP_SXCHARGED in
    true|True|TRUE|Yes|yes|YES|1|y|Y)
        PHOTOSHOP_SXCHARGED=true
        ;;
    false|False|FALSE|No|no|NO|0+n|N)
        PHOTOSHOP_SXCHARGED=false
        ;;
    *)
        if [ "$PHOTOSHOP_SXCHARGED" = "" ] ; then
            PHOTOSHOP_SXCHARGED=false
            if [ -x "$INSTALL_DIR/bin/sxmemory" ] ; then
                # If any SX memory allocated via sxconfig, turn on SXCharged plugin.
                sxmemory=`$INSTALL_DIR/bin/sxmemory`
                if [ "$sxmemory" -gt 0 -a "$CHIPVERSION" != v7 ] ; then
                    PHOTOSHOP_SXCHARGED=true
                fi
            fi
        else
            echo ""
            echo "PHOTOSHOP_SXCHARGED has an invalid value. Must be true or false. False assumed."
            PHOTOSHOP_SXCHARGED=false
        fi
        ;;
    esac
fi

if [ "$PHOTOSHOP_SXCHARGED" = 'true' ] ; then
    case "$PHOTOSHOP_USE_DGA" in
      true|True|TRUE|Yes|yes|YES|1|y|Y)
        unset SXPS_NO_DGA
        ;;
      *)
        SXPS_NO_DGA=true
        export SXPS_NO_DGA
        ;;
    esac
fi

case $PHOTOSHOP_MPCHARGED in
true|True|TRUE|Yes|yes|YES|1|y|Y)
    PHOTOSHOP_MPCHARGED=true
    ;;
false|False|FALSE|No|no|NO|0+n|N)
    PHOTOSHOP_MPCHARGED=false
    ;;
*)
    if [ "$PHOTOSHOP_MPCHARGED" = "" ] ; then
        PHOTOSHOP_MPCHARGED=false
        # If SXCharged is installed, don't try to install MPCharged.
        if [ "$PHOTOSHOP_SXCHARGED" != true ] ; then
            if [ "$nprocessors" -gt 1 ] ; then
                # If any more than one processor, turn on MPCharged plug-in
                PHOTOSHOP_MPCHARGED=true
            fi
        fi
    else
        echo ""
        echo "PHOTOSHOP_MPCHARGED has an invalid value. Must be true or false. False assumed."
        PHOTOSHOP_MPCHARGED=false
    fi
    ;;
esac

if [ "$osname" = SunOS -a "$osmajor" -eq 5 -a "$osminor" -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' ' '`
fi

# Make sure everything is OK with SXCharged and MPCharged plug-ins.
if [ "$PHOTOSHOP_MPCHARGED" = true -a "$PHOTOSHOP_SXCHARGED" = true ] ; then
    echo ""
    echo "Invalid values for PHOTOSHOP_SXCHARGED and PHOTOSHOP_MPCHARGED."
    echo "You cannot install both MPCharged and SXCharged. Both will be ignored."
    PHOTOSHOP_SXCHARGED=false
    PHOTOSHOP_MPCHARGED=false
elif [ "$PHOTOSHOP_SXCHARGED" = true ] ; then
    # Check for proper patches if running SunOS 5.3.
    if [ "$osname" = SunOS -a "$osmajor" -eq 5 -a "$osminor" -le 3 ] ; then
        # Check for patches 101318-42 and 101594-04 or greater.
        patch_101318_42=0
        patch_101594_04=0
        patchnum=0
        for value in $patches; do
            if [ $patchnum = 0 ] ; then
                patchnum=$value
            else
                rev=$value
                if [ "$patchnum" -eq 101318 -a "$rev" -ge 42 ] ; then
                    patch_101318_42=1
                elif [ "$patchnum" -eq 101594 -a "$rev" -ge 4 ] ; then
                    patch_101594_04=1
                fi
                patchnum=0
            fi
        done
        if [ $patch_101318_42 = 0 ] ; then
            echo ""
            echo 'Warning: patch 101318-42 (or greater) is not installed on this system'
            echo "and is required for SXCharged plug-in to work properly."
            echo "Refer to Getting Started guide and readme for more details."
        fi
        if [ $patch_101594_04 = 0 ] ; then
            echo ""
            echo 'Warning: patch 101594-04 (or greater) is not installed on this system'
            echo "and is required for SXCharged plug-in to work properly."
            echo "Refer to Getting Started guide and readme for more details."
        fi
        if [ "$CHIPVERSION" = v7 ] ; then
            echo ""
            echo "Warning: environment variable PHOTOSHOP_SXCHARGED is true,"
            echo "but this machine is an older Sparc and does not support this feature."
            echo "PHOTOSHOP_SXCHARGED will be ignored."
            PHOTOSHOP_SXCHARGED=false
        fi
        # Make sure some CMEM is allocated.
        # If PHOTOSHOP_MEMORY is not set, then set it to amount of
        # allocated CMEM from sxconfig.
        if [ -x "$INSTALL_DIR/bin/sxmemory" ] ; then
            sxmemory=`$INSTALL_DIR/bin/sxmemory`
            if [ "$sxmemory" -eq 0 ] ; then
                echo ""
                echo "Warning: PHOTOSHOP_SXCHARGED is true, but no SX memory has been"
                echo "allocated via sxconfig. PHOTOSHOP_SXCHARGED will be set to false."
                PHOTOSHOP_SXCHARGED=false
            elif [ "$PHOTOSHOP_MEMORY" = "" ] ; then
                PHOTOSHOP_MEMORY=$sxmemory
                export PHOTOSHOP_MEMORY
            fi
        fi
    fi
elif [ "$PHOTOSHOP_MPCHARGED" = true ] ; then
    # Check for proper chip if running SunOS 5.3.
    if [ "$osname" = SunOS -a "$osmajor" -eq 5 -a "$osminor" -le 3 ] ; then
        if [ "$CHIPVERSION" = v7 ] ; then
            echo ""
            echo "Warning: environment variable PHOTOSHOP_MPCHARGED is true,"
            echo "but this machine is an older Sparc and does not support this feature."
            echo "PHOTOSHOP_MPCHARGED will be ignored."
            PHOTOSHOP_MPCHARGED=false
        fi
    fi
fi

# Check for patches 101362-04 or greater.
if [ "$osname" = SunOS -a "$osmajor" -eq 5 -a "$osminor" -le 3 ] ; then
    patch_101362_04=0
    patchnum=0
    for value in $patches; do
        if [ $patchnum = 0 ] ; then
    	patchnum=$value
        else
    	rev=$value
    	if [ "$patchnum" -eq 101362 -a "$rev" -ge 04 ] ; then
    	    patch_101362_04=1
    	fi
    	patchnum=0
        fi
    done
    if [ $patch_101362_04 = 0 ] ; then
        echo ""
        echo 'Warning: patch 101362-04 (or greater) is not installed on this system'
        echo 'and is sometimes necessary for certain functions (e.g., Acquire EPS, text)'
        echo 'to work properly.'
        echo 'Refer to Getting Started guide and readme for more details.'
    fi
fi

# Use environment variable PHOTOSHOP_OPT_EXT to control
# which optional extensions to use for this invocation of Photoshop.

# Verify that all entries in PHOTOSHOP_OPT_EXT are recognizable.
IFS=:
for optional in $PHOTOSHOP_OPT_EXT ; do
    if [ "$optional" != "" ]; then
        if (echo "$OPTIONALS" | egrep ":$optional:" > /dev/null) ; then
            # Space holder statement
            ok=1
        else
            # When here, the user has specified an unrecognized optional extension.
            echo ""
            echo Warning: environment variable PHOTOSHOP_OPT_EXT specifies $optional,
            echo which is not a recognized optional extension and will be ignored.
        fi
    fi
done
IFS=' '

# Remove/add links for SXCharged and MPCharged directories.
${RM} -r "$PHOTOSHOP_ROOT/Photoshop.MacFiles/Plug-ins/SXCharged"
if [ "$PHOTOSHOP_SXCHARGED" = true ] ; then
    ${LN} "$INSTALL_DIR/Photoshop.MacFiles/Plug-ins/SXCharged" "$PHOTOSHOP_ROOT/Photoshop.MacFiles/Plug-ins/SXCharged" 
fi
# Put a delete character in front of MPCharged to get it to load last.
MPChargedDir_Install='MPCharged'
MPChargedDir_User='MPCharged'
${RM} -r "$PHOTOSHOP_ROOT/Photoshop.MacFiles/Plug-ins/$MPChargedDir_User"
if [ "$PHOTOSHOP_MPCHARGED" = true ] ; then
    ${LN} "$INSTALL_DIR/Photoshop.MacFiles/Plug-ins/$MPChargedDir_Install" "$PHOTOSHOP_ROOT/Photoshop.MacFiles/Plug-ins/$MPChargedDir_User" 
fi

# Loop through all possible optional extensions.
# Remove old links and add new ones as appropriate.
OptExtDir_Install="$INSTALL_DIR/$OptExtDir"
OptExtDir_User="$PHOTOSHOP_ROOT/$OptExtDir"
IFS=:
for optional in $OPTIONALS; do
    IFS=' '
    if [ "$optional" != "" ]; then
        if [ -h "$OptExtDir_User/$optional" ] ; then
            # If extension is present and is a link, remove the link
            ${RM} "$OptExtDir_User/$optional"
            ${RM} "$OptExtDir_User/%$optional"
        elif [ -f "$OptExtDir_User/$optional" ] ; then
            # If extension is present and is a file, print warning.
            echo ""
            echo "Warning: optional extension $optional exists as file:"
            if [ -f "$OptExtDir_User/$optional" ] ; then
                echo "$OptExtDir_User/$optional"
            fi
            echo "You should remove this file and specify $optional"
            echo "using environment variable PHOTOSHOP_OPT_EXT instead."
            continue
        fi
        if (echo ":$PHOTOSHOP_OPT_EXT:" | egrep ":$optional:" > /dev/null) ; then
            # When here, this optional extension has been requested by the user.
            # Create a symbolic link.
            ${LN} "$OptExtDir_Install/$optional" "$OptExtDir_User/$optional"
            ${LN} "$OptExtDir_Install/%$optional" "$OptExtDir_User/%$optional"
        fi
    fi
done


# Remove the font cache so that it can be recalculated.
if [ "$NEWFONTCACHE" = 1 ] ; then
    ${RM} $PHOTOSHOP_ROOT/Photoshop.MacFiles/System/Fonts/*Cache*
fi

# Execute the binary for the application.
# The incantation ${1+"$@"} is black-magic to pass args correctly,
# even if some args contain embedded spaces

if [ "$USEDIRECTXLIB" = 1 -a -x "$DIRECTXLIB" ] ; then
    # Use direct XLIB for this application if it is available.
    echo $DIRECTXLIB $PHOTOSHOP_ROOT/$EXECNAME ${1+"$@"}
    exec $DIRECTXLIB $PHOTOSHOP_ROOT/$EXECNAME ${1+"$@"}
else
    echo $PHOTOSHOP_ROOT/$EXECNAME ${1+"$@"}
    exec $PHOTOSHOP_ROOT/$EXECNAME ${1+"$@"}
fi
