#!/bin/sh

#	$Header: /user/usource/ux_apps/ps30/ppdutil/printerconf.sh,v 1.4 1995/08/06 19:00:45 dtomm Exp $

# 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:/usr/openwin/bin
export PATH

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/bin/printerconf" ]; then
		INSTALL_DIR="$parentdir"
	fi
fi

# Make sure DISPLAY variable has a value
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
export DISPLAY

LD_LIBRARY_PATH=/usr/lib:/usr/openwin/lib:$INSTALL_DIR/lib
export LD_LIBRARY_PATH

# If PPDDIR has no setting, try to guess where the PPD
# directory is and set PPDDIR to that directory.
if [ "$PPDDIR" = "" ] ; then
	rootdir=`expr $INSTALL_DIR : '\(.*\)/'`
	if [ -d "$rootdir/PPD" ] ; then
		PPDDIR="$rootdir/PPD"
		export PPDDIR
	elif [ -d /usr/adobe/PPD ] ; then
		PPDDIR=/usr/adobe/PPD
		export PPDDIR
	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

$INSTALL_DIR/lib/printerconf_exec ${1+"$@"}

