JAL-3830 unix and macos wrappers. Symbolic link to jalviewc-macos in Contents/MacOS...
[jalview.git] / utils / getdown / jalviewc-macos
1 #!/usr/bin/env bash
2
3 ARG1=$1
4 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
5 APP=${DIR%/Contents/*}
6
7 if [ "${APP}" = "${APP%.app}" ]; then
8   echo "Could not find .app dir" >&2
9   exit 1
10 fi
11
12 # check to see if $1 is set and is not start of other cli set args
13 OPEN=""
14 if [ -n "$ARG1" -a "$ARG1" = "${ARG1#-}" -a \! "$ARG1" = "open" ]; then
15  # first argument exists and does not start with a "-" and is not "open"
16  OPEN="-open"
17 fi
18
19 APPDIR="${APP}/Contents/Resources/app"
20 JAVA="${APPDIR}/jre/Contents/Home/bin/java"
21 GETDOWNTXT="${APPDIR}/getdown.txt"
22 # always check grep and sed regexes on macOS -- they're not the same
23 if [ -e "$GETDOWNTXT" ]; then
24   CLASSPATH=""
25   for x in $(grep -e 'code = ' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do
26     [ -n "$CLASSPATH" ] && CLASSPATH="${CLASSPATH}:"
27     CLASSPATH="${CLASSPATH}${APPDIR}/${x}"
28   done
29 else
30   echo "Cannot find getdown.txt" >&2
31   exit 1
32 fi
33
34 "$JAVA" -cp "$CLASSPATH" jalview.bin.Launcher $OPEN "$@"