#!/bin/sh
#
# --- UCSF Chimera Copyright ---
# Copyright (c) 2000 Regents of the University of California.
# All rights reserved.  This software provided pursuant to a
# license agreement containing restrictions on its disclosure,
# duplication and use.  This notice must be embedded in or
# attached to all copies, including partial copies, of the
# software or any revisions or derivations thereof.
# --- UCSF Chimera Copyright ---
#

# set path so we get the versions of command we expect
originalpath="$PATH"
PATH=/bin:/usr/bin:"$PATH"

# canonicalize CHIMERA for consistency with Tcl/Tk
if test "$CHIMERA"
then
	CHIMERA=`cd "$CHIMERA"; pwd -P`
else
	# Assume we were started as CHIMERA/bin/chimera and
	# deduce what CHIMERA should be.  Try to work when
	# chimera is linked to with a symbolic link
	tmp=`ls -l $0`
	CHIMERA=`echo "$tmp" | sed 's/.* -> //'`
	if test "$tmp" = "$CHIMERA"
	then
		CHIMERA="$0"
	fi
	
	CHIMERA=`dirname "$CHIMERA"`
	CHIMERA=`cd "$CHIMERA"; pwd -P`
	CHIMERA=`dirname "$CHIMERA"`
	CHIMERA=`dirname "$CHIMERA"`
fi
export CHIMERA

# system-dependent setup
case "`uname -s`" in
	IRIX|IRIX64)
		LD_LIBRARYN32_PATH="$CHIMERA/lib${LD_LIBRARYN32_PATH:+:$LD_LIBRARYN32_PATH}"
		export LD_LIBRARYN32_PATH
		;;
	OSF1)
		LD_LIBRARY_PATH="$CHIMERA/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
		export LD_LIBRARY_PATH
		;;
	Linux)
		LD_LIBRARY_PATH="$CHIMERA/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
		export LD_LIBRARY_PATH
		;;
	AIX*)
		# untested
		LIBPATH="$CHIMERA/lib${LIBPATH:+:$LIBPATH}"
		export LIBPATH
		;;
	Darwin*)
		DYLD_LIBRARY_PATH="$CHIMERA/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
		export DYLD_LIBRARY_PATH
		# Make the Tcl/Tk and Python frameworks accessible.
		DYLD_FRAMEWORK_PATH="$CHIMERA/Library/Frameworks${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}"
		export DYLD_FRAMEWORK_PATH
		# Chimera hangs on start-up on Mac OS 10.2 due to a semaphore lock
		# in the run-time linker unless the following variable is set.
		DYLD_BIND_AT_LAUNCH=1
		export DYLD_BIND_AT_LAUNCH
		;;
esac

# make sure we use our Tcl/Tk
TCL_LIBRARY="$CHIMERA/share/tcltk/tclTCL_VERSION"
export TCL_LIBRARY
TCLLIBPATH="{$CHIMERA/lib} {$CHIMERA/share/tcltk}"
export TCLLIBPATH

# deduce which python to use
if test -e "$CHIMERA/bin/python2.2"
then
	# using our distributed version of python, undo PYTHONHOME
	unset PYTHONHOME
	PYTHON="$CHIMERA/bin/python2.2"
else
	PATH="$originalpath"
	PYTHON="python2.2"
fi


$PYTHON $CHIMERA/share/DBPuppet/send_to_chimera.py $@
