X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=utils%2Fgetdown%2Fjalviewc-macos;h=e34685d59360d1dd22a8b2cec4da8e34ae37da6d;hb=33f9fc9a47c1907525e07683fa66797afb233b3e;hp=32748cbdfa6c26bd9f96b66d4b34f0358d087dd6;hpb=fb2acffde9626c68514def6d609de3f39e2302dc;p=jalview.git diff --git a/utils/getdown/jalviewc-macos b/utils/getdown/jalviewc-macos index 32748cb..e34685d 100755 --- a/utils/getdown/jalviewc-macos +++ b/utils/getdown/jalviewc-macos @@ -1,17 +1,46 @@ #!/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 @@ -19,16 +48,22 @@ 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} "$@"