#!/bin/sh

if [ -z "$BEAST" ]; then
	## resolve links - $0 may be a link to application
	PRG="$0"

	# need this for relative symlinks
	while [ -h "$PRG" ] ; do
	    ls=`ls -ld "$PRG"`
	    link=`expr "$ls" : '.*-> \(.*\)$'`
	    if expr "$link" : '/.*' > /dev/null; then
		PRG="$link"
	    else
		PRG="`dirname "$PRG"`/$link"
	    fi
	done

	# make it fully qualified
	saveddir=`pwd`
	BEAST0=`dirname "$PRG"`/..
	BEAST=`cd "$BEAST0" && pwd`
	cd "$saveddir"
fi

BEAST_LIB="/opt/conda/conda-bld/beast2_1616700197481/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeh/share/beast2-2.4.5-3/lib"

if [ -z "$JAVA_HOME" ]; then
  JAVA=java
else
  JAVA=$JAVA_HOME/bin/java
fi


# use BEAGLE_LIB if the BEAGLE library is not in a standard location
if [ -n "$BEAGLE_LIB" ]; then
	if [ -n "$BEAST_EXTRA_LIBS" ]; then
		BEAST_EXTRA_LIBS=$BEAST_EXTRA_LIBS:$BEAGLE_LIB
	else
		BEAST_EXTRA_LIBS=$BEAGLE_LIB
	fi
fi
BEAST_EXTRA_LIBS=${BEAST_EXTRA_LIBS}:/opt/conda/conda-bld/beast2_1616700197481/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeh/lib
# Explicitly add /usr/local/lib to library search path to ensure 
# beast continues to find beagle when installed here.  (This is
# necessary due to known problems with certain JREs.)
if [ -z "$LD_LIBRARY_PATH" ]; then
    export LD_LIBRARY_PATH=/opt/conda/conda-bld/beast2_1616700197481/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeh/lib
else
    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":/opt/conda/conda-bld/beast2_1616700197481/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeh/lib
fi

# use BEAST_EXTRA_LIBS variable to load BEAGLE and other libraries from non-default locations 
# this assumes that the library path contains all these libraries (or are set through LD_LIBRARY_PATH)
if [ -n "$BEAST_EXTRA_LIBS" ]; then 
  $JAVA -Xms64m -Xmx4g -Djava.library.path=$BEAST_EXTRA_LIBS -cp "$BEAST_LIB/launcher.jar" beast.app.beastapp.BeastLauncher $*
else	
  $JAVA -Xms64m -Xmx4g -cp "$BEAST_LIB/launcher.jar" beast.app.beastapp.BeastLauncher $*
fi
