#!/bin/sh

# === UCSF ChimeraX Copyright ===
# Copyright 2022 Regents of the University of California. All rights reserved.
# This software is provided pursuant to the ChimeraX license agreement, which
# covers academic and commercial uses. For more information, see
# <https://www.rbvi.ucsf.edu/chimerax/docs/licensing.html>
#
# This file is part of the ChimeraX library. You can also redistribute and/or
# modify it under the GNU Lesser General Public License version 2.1 as
# published by the Free Software Foundation. For more details, see
# <https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>
#
# This file is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This notice
# must be embedded in or attached to all copies, including partial copies, of
# the software or any revisions or derivations thereof.
# === UCSF ChimeraX Copyright ===

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

# stop cd from echoing the directory
unset CDPATH

# Assume that the true location of MOD_NAME is in CHIMERAX/bin/ and
# deduce what CHIMERAX should be even if there are symbolic links
bindir=`dirname "$0"`
if test ! -L "$0"
then
	bindir=`cd "$bindir"; pwd -P`
else
	if link=`readlink "$0"`
	then :
	else
		# fallback if readlink doesn't exist
		link=`ls -l "$0" | sed 's/.* -> //'`
	fi
	# MOD_NAME was a (relative?) symbolic link
	tmp=`dirname "$link"`
	bindir=`cd "$bindir"; cd "$tmp"; pwd -P`
fi
CHIMERAX=`dirname "$bindir"`

app="$CHIMERAX/OS_BIN/APP_NAME"
if [ -e "${app}-console" ]
then
	app="${app}-console"
fi
if test $# -gt 0
then
	exec "$app" -m chimerax.MOD_NAME "$@"
else
	exec "$app" -m chimerax.MOD_NAME
fi
