#!/bin/sh
#
#   Copyright (c) 1988-1996 Adobe Systems, Incorporated. All rights reserved.
#
# Adobe Frame products startup script.

# Unset ENV, which ksh uses as the name of its per-invocation startup file.
# Apparently some installations replace the UNIX shell with the Korn shell;
# this breaks things like
#	foo=`shell-command`
# if the ksh startup file named by $ENV happens to write something to
# the standard output.
if [ ! "X${ENV}" = 'X' ]; then
	unset ENV; export ENV
fi

# Keep LANG set to "C" while the script is running, and restore the original
# value just before exec'ing.  Launch running on SGI Japanese was failing
# with LANG set to "ja_JP.EUC", apparently because "ls -ld" output was not
# compatible with the symlink expansion code.
FM_SAVE_LANG="$LANG"
LANG=C
export LANG

# Determine FMHOME by working backward: after expanding symbolic links,
# this script's pathname is $FMHOME/bin/.wrapper, which we then solve
# for $FMHOME.
# We always determine FMHOME in this manner, instead of using one passed
# in from the environment, to ensure that we start the Frame product with
# FMHOME pointing to the right set of installation files.  With this scheme
# multiple Frame product installations can coexist; simply select (or type
# to a Shell) the name of the one you want, and it will start up correctly.
#
arg0=${0-maker} P=`pwd`
# capture myname before expanding symlinks
arg0=`echo $arg0 | sed -e 's#^\./##'`
myname=`expr //$arg0 : '.*/\(.*\)'`
case $arg0 in		# ensure that $arg0 is a full pathname
/*) ;;
*)  arg0=$P/$arg0;;
esac
expanded_link=
while			# while $arg0 is a symbolic link, arg0 = `read link`
	# thisdir=`dirname $arg0`, but dirname is not universally available.
	thisdir=`expr \
	  $arg0'/' : '\(/\)[^/]*/$' \
	  \| $arg0'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \
	  \| .`	# "cannot happen" because $arg0 is always a rooted pathname
	l=`ls -ld $arg0 | grep '^[Ll]'`
	[ -n "$l" ]
do
	m=`expr "$l" : '.* \(.*\)'`
	case $m in
	/*) arg0=$m ;;
	*)  arg0=$thisdir/$m ;;
	esac
	expanded_link=t		# we expanded a symlink for $arg0 at least once
done
# Solve $thisdir==$FMHOME/bin for $FMHOME
FMHOME=`expr \
  $thisdir'/' : '\(/\)[^/]*/$' \
  \| $thisdir'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \
  \| .`
export FMHOME

[ ! -d $FMHOME/fminit ] && {
	echo "
""$myname: this Adobe software is not correctly installed.  Failed
""to set \$FMHOME to the installation directory (could not find
""$FMHOME/fminit).
""Please see your system administrator.
"
	exit 1
}

# Determine FMARCH if it is not already set or seems incorrect.
if [ -z "$FMARCH" -o ! -d "$FMHOME/bin/$FMARCH" ]; then
	FMARCH=`$FMHOME/bin/scripts/fmarch`
fi
if [ ! -d $FMHOME/bin/$FMARCH ]; then
	echo \
 "$myname: unable to locate binary directory for this architecture.
""Please see your system administrator."
	exit 1
fi
export FMARCH

[ $expanded_link ] || {
	echo "
""$myname: this Adobe software is not correctly installed.  The file
""($FMHOME/bin/$myname) must be a symbolic link.
""Please see your system administrator."
	exit 1
}

# Set the USER environment variable if need be.
# Do we need USER set?
if [ ! -z "$USER" ]; then
	USER="$USER"
elif [ ! -z "$LOGNAME" ]; then
	USER="$LOGNAME"
elif [ -x /usr/ucb/whoami ]; then
	USER=`/usr/ucb/whoami`
else
	USER=unknown
fi
export USER

# Set the INIDIR environment variable for filters if need be.
# Do we need INIDIR set?
if [ ! -z "$INIDIR" ]; then
        INIDIR="$INIDIR"
else
        INIDIR="$FMHOME/fminit/filters"
fi
export INIDIR

PATH="$FMHOME/bin:$PATH"
export PATH
if [ "$FMARCH" = "dec.osf.alpha" ]; then
uac p 0
fi

# set the environment for Inso word97 to pick up the shared libs
# from the $FMHOME/bin/$FMARCH directory
if [ "$FMARCH" = "sunxm.s5.sparc" -o "$FMARCH" = "sgi.irix.mips" ]; then
        LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$FMHOME/bin/$FMARCH"; export LD_LIBRARY_PATH
fi

if [ "$FMARCH" = "ibm.aix.pwr" ]; then
        LIBPATH="$LIBPATH:/usr/lib:/lib:$FMHOME/bin/$FMARCH"; export LIBPATH
fi
if [ "$FMARCH" = "hp.hpux.pa" ]; then
  SHLIB_PATH="$SHLIB_PATH:$FMHOME/bin/$FMARCH"; export SHLIB_PATH
fi
# Now restore the original value of $LANG just before exec'ing.
LANG="$FM_SAVE_LANG"
export LANG

if [ -x $FMHOME/bin/scripts/$myname ]; then
	exec $FMHOME/bin/scripts/$myname ${1+"$@"}
elif [ -x $FMHOME/bin/$FMARCH/$myname ]; then
	exec $FMHOME/bin/$FMARCH/$myname ${1+"$@"}
fi

echo \
 "$myname: Cannot find the script $FMHOME/bin/scripts/$myname
""  or the binary $FMHOME/bin/$FMARCH/$myname."
exit 1
