#!/usr/bin/env bash
-ARG1=$1
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
-APP=${DIR%/Contents/*}
+ARG1="$1"
+
+# this whole next part is because there's no readlink -f in Darwin
+function readlinkf() {
+ FINDFILE="$1"
+ FILE="${FINDFILE}"
+ PREVFILE=""
+ C=0
+ MAX=100 # just in case we end up in a loop
+ FOUND=0
+ while [ "${C}" -lt "${MAX}" -a "${FILE}" != "${PREVFILE}" -a "${FOUND}" -ne 1 ]; do
+ PREVFILE="${FILE}"
+ FILE="$(readlink "${FILE}")"
+ if [ -z "${FILE}" ]; then
+ # the readlink is empty means we've arrived at the script, let's canonicalize with pwd
+ FILE="$(cd "$(dirname "${PREVFILE}")" &> /dev/null && pwd -P)"/"$(basename "${PREVFILE}")"
+ FOUND=1
+ elif [ "${FILE#/}" = "${FILE}" ]; then
+ # FILE is not an absolute path link, we need to add the relative path to the previous dir
+ FILE="$(dirname "${PREVFILE}")/${FILE}"
+ fi
+ C=$((C+1))
+ done
+ if [ "${FOUND}" -ne 1 ]; then
+ echo "Could not determine path to actual file '$(basename "${FINDFILE}")'" >&2
+ exit 1
+ fi
+ echo "${FILE}"
+}
+
+DIR="$(dirname "$(readlinkf "$0")")"
+APP="${DIR%.app/Contents/*}".app
if [ "${APP}" = "${APP%.app}" ]; then
- echo "Could not find .app dir" >&2
- exit 1
+ echo "Could not find Jalview.app dir" >&2
+ exit 2
fi
# check to see if $1 is set and is not start of other cli set args
OPEN=""
-if [ -n "$ARG1" -a "$ARG1" = "${ARG1#-}" -a \! "$ARG1" = "open" ]; then
+if [ -n "${ARG1}" -a "${ARG1}" = "${ARG1#-}" -a "${ARG1}" != "open" ]; then
# first argument exists and does not start with a "-" and is not "open"
OPEN="-open"
fi
APPDIR="${APP}/Contents/Resources/app"
JAVA="${APPDIR}/jre/Contents/Home/bin/java"
GETDOWNTXT="${APPDIR}/getdown.txt"
-# always check grep and sed regexes on macOS -- they're not the same
-if [ -e "$GETDOWNTXT" ]; then
- CLASSPATH=""
- for x in $(grep -e 'code = ' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do
- [ -n "$CLASSPATH" ] && CLASSPATH="${CLASSPATH}:"
- CLASSPATH="${CLASSPATH}${APPDIR}/${x}"
+CLASSPATH=""
+if [ -e "${GETDOWNTXT}" ]; then
+ # always check grep and sed regexes on macOS -- they're not the same
+ for JAR in $(grep -e '^code\s*=\s*' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do
+ [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH}:"
+ CLASSPATH="${CLASSPATH}${APPDIR}/${JAR}"
done
else
echo "Cannot find getdown.txt" >&2
- exit 1
+ exit 3
+fi
+
+if [ \! -e "${JAVA}" ]; then
+ echo "Cannot find bundled java, using system and hoping for the best!" >&2
+ JAVA=java
fi
-"$JAVA" -cp "$CLASSPATH" jalview.bin.Launcher $OPEN "$@"
+# don't quote $OPEN
+"${JAVA}" -Xdock:icon="${APPDIR}"/resource/jalview_logo.png -cp "${CLASSPATH}" jalview.bin.Launcher ${OPEN} "$@"