3 declare -a ARGS=("${@}")
6 # this whole next part is because there's no readlink -f in Darwin
12 MAX=100 # just in case we end up in a loop
14 while [ "${C}" -lt "${MAX}" -a "${FILE}" != "${PREVFILE}" -a "${FOUND}" -ne 1 ]; do
16 FILE="$(readlink "${FILE}")"
17 if [ -z "${FILE}" ]; then
18 # the readlink is empty means we've arrived at the script, let's canonicalize with pwd
19 FILE="$(cd "$(dirname "${PREVFILE}")" &> /dev/null && pwd -P)"/"$(basename "${PREVFILE}")"
21 elif [ "${FILE#/}" = "${FILE}" ]; then
22 # FILE is not an absolute path link, we need to add the relative path to the previous dir
23 FILE="$(dirname "${PREVFILE}")/${FILE}"
27 if [ "${FOUND}" -ne 1 ]; then
28 echo "Could not determine path to actual file '$(basename "${FINDFILE}")'" >&2
35 if [ "$( uname -s )" = "Darwin" ]; then
39 # check for headless mode
42 if [ "${ARG}" = "--headless" ]; then
50 # set vars for being inside the macos App Bundle
51 if [ "${ISMACOS}" = 1 ]; then
53 DIR="$(dirname "$(readlinkf "$0")")"
54 APP="${DIR%.app/Contents/*}".app
55 if [ "${APP}" = "${APP%.app}" ]; then
56 echo "Could not find Jalview.app" >&2
59 APPDIR="${APP}/Contents/Resources/app"
60 JAVA="${APPDIR}/jre/Contents/Home/bin/java"
61 JVMARGS=( "${JVMARGS[@]}" "-Xdock:icon=${APPDIR}/resource/jalview_logo.png" )
64 DIR="$(dirname "$(readlink -f "$0")")"
66 JAVA="${APPDIR}/jre/bin/java"
69 if [ "${HEADLESS}" = 1 ]; then
70 # this suppresses the Java icon appearing in the macOS Dock and maybe other things in other OSes
71 JVMARGS=( "${JVMARGS[@]}" "-Djava.awt.headless=true" )
75 GETDOWNTXT="${APPDIR}/getdown.txt"
78 # save an array of JAR paths in case we're in WSL (see later)
79 declare -a JARPATHS=()
80 if [ -e "${GETDOWNTXT}" ]; then
81 # always check grep and sed regexes on macos -- they're not the same
82 for JAR in $(grep -e '^code[[:space:]]*=[[:space:]]*' "${GETDOWNTXT}" | while read -r line; do echo $line | sed -E -e 's/code[[:space:]]*=[[:space:]]*//;'; done);
84 [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH}:"
85 CLASSPATH="${CLASSPATH}${APPDIR}/${JAR}"
86 JARPATHS=( "${JARPATHS[@]}" "${APPDIR}/${JAR}" )
89 echo "Cannot find getdown.txt" >&2
93 # WINDOWS ONLY (Cygwin or WSL)
94 # change paths for Cygwin or Windows Subsystem for Linux (WSL)
95 if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoid
96 if [ "$(uname -o)" = "Cygwin" ]; then
98 CLASSPATH=$(cygpath -pw "${CLASSPATH}")
99 # now for some arg paths fun. only translating paths starting with './', '../', '/' or '~'
101 for ARG in "${@}"; do
102 if [ "${ARG}" != "${ARG#@(/|./|../|~)}" ]; then
103 ARGS=( "${ARGS[@]}" "$(cygpath -aw "${ARG}")" )
105 ARGS=( "${ARGS[@]}" "${ARG}" )
108 elif uname -r | grep -i microsoft | grep -i wsl >/dev/null; then
111 for JARPATH in "${JARPATHS[@]}"; do
112 [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH};"
113 CLASSPATH="${CLASSPATH}$(wslpath -aw "${JARPATH}")"
116 for ARG in "${@}"; do
117 if [ "${ARG}" != "${ARG#@(/|./|../|~)}" ]; then
118 # annoyingly wslpath does not work if the file doesn't exist!
119 ARGBASENAME="$(basename "${ARG}")"
120 ARGDIRNAME="$(dirname "${ARG}")"
121 ARGS=( "${ARGS[@]}" "$(wslpath -aw "${ARGDIRNAME}")\\${ARGBASENAME}" )
123 ARGS=( "${ARGS[@]}" "${ARG}" )
131 # get console width -- three ways to try, just in case
132 if command -v tput 2>&1 >/dev/null; then
133 COLUMNS=$(tput cols) 2>/dev/null
134 elif command -v stty 2>&1 >/dev/null; then
135 COLUMNS=$(stty size | cut -d" " -f2) 2>/dev/null
136 elif command -v resize 2>&1 >/dev/null; then
137 COLUMNS=$(resize -u | grep COLUMNS= | sed -e 's/.*=//;s/;//') 2>/dev/null
139 JVMARGS=( "${JVMARGS[@]}" "-DCONSOLEWIDTH=${COLUMNS}" )
140 JVMARGS=( "${JVMARGS[@]}" "-Dgetdownappdir=${APPDIR}" )
142 # Is there a bundled Java? If not just try one in the PATH (do need .exe in WSL)
143 if [ \! -e "${JAVA}" ]; then
145 echo "Cannot find bundled java, using system ${JAVA} and hoping for the best!" >&2
148 "${JAVA}" "${JVMARGS[@]}" -cp "${CLASSPATH}" jalview.bin.Launcher "${ARGS[@]}"