From b24edf3036e7cb5e8ea00855ad315d0c858c95a3 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 29 Jul 2024 19:44:49 +0100 Subject: [PATCH] JAL-3631 Add --updateuser and --updateinstallation to the jalview.sh script: This runs getdown in headless mode to run update of either user or installation appdir without launching Jalview --- utils/getdown/bin/jalview.sh | 79 +++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/utils/getdown/bin/jalview.sh b/utils/getdown/bin/jalview.sh index e2e7599..9fb7058 100755 --- a/utils/getdown/bin/jalview.sh +++ b/utils/getdown/bin/jalview.sh @@ -41,6 +41,8 @@ GUI=0 HELP=0 DEBUG=0 UPDATE=0 +UPDATEUSER=0 +UPDATEINSTALLATION=0 for RAWARG in "${@}"; do ARG="${RAWARG%%=*}" case "${ARG}" in @@ -49,6 +51,7 @@ for RAWARG in "${@}"; do ;; --help|--help-*|--version|-h) HELP=1 + HEADLESS=1 ;; --gui) GUI=1 @@ -56,24 +59,30 @@ for RAWARG in "${@}"; do --debug) DEBUG=1 ;; - --update) + --updateinstallation) UPDATE=1 + UPDATEINSTALLATION=1 + HEADLESS=1 + ;; + --updateuser) + UPDATE=1 + UPDATEUSER=1 + HEADLESS=1 ;; esac done if [ "${HELP}" = 1 ]; then # --help takes precedence - HEADLESS=1 GUI=0 elif [ "${UPDATE}" = 1 ]; then # --update takes precedence over everything else, we don't run jalview! - HEADLESS=1 GUI=0 elif [ "${GUI}" = 1 ]; then # --gui takes precedence over --headless HEADLESS=0 fi +# args for the JVM declare -a JVMARGS=() # set vars for being inside the macos App Bundle @@ -86,14 +95,21 @@ if [ "${ISMACOS}" = 1 ]; then if [ "${HEADLESS}" != 1 ]; then JVMARGS=( "${JVMARGS[@]}" "-Xdock:icon=${APPDIR}/resource/jalview_logo.png" ) fi + # e.g. APPFOLDER=/Applications/Jalview.app + APPFOLDER="${APPDIR%%.app/*}.app" + VMOPTIONS="${APPFOLDER}/Contents/vmoptions.txt" else # NOT MACOS SCRIPT="$(readlink -f "$0")" DIR="$(dirname "${SCRIPT}")" APPDIR="${DIR%/bin}" JAVA="${APPDIR}/jre/bin/java" + # e.g. APPFOLDER=/opt/jalview + APPFOLDER="${APPDIR}" + VMOPTIONS="${APPDIR}/jalviewg.vmoptions" fi +# headless java arguments if [ "${HEADLESS}" = 1 ]; then # not setting java.awt.headless in java invocation of running jalview due to problem with Jmol if [ "${HELP}" = 1 ]; then @@ -119,21 +135,59 @@ if [ "${UPDATE}" = 1 ]; then # JUST RUNNING A GETDOWN INSTALLATION UPDATE, not launching Jalview CLASS="com.threerings.getdown.launcher.GetdownApp" if [ -e "${GETDOWNJAR}" ]; then - CLASSPATH="${APPDIR}/${GETDOWNJAR}" - JARPATHS=( "${JARPATHS[@]}" "${APPDIR}/${GETDOWNJAR}" ) + CLASSPATH="${GETDOWNJAR}" + JARPATHS=( "${JARPATHS[@]}" "${GETDOWNJAR}" ) else echo "Cannot find getdown-launcher.jar to run update" >&2 exit 13 fi + # user-space update + if [ "${UPDATEUSER}" = 1 ]; then + if [ -e "${VMOPTIONS}" ]; then + LINENUM=0 + while IFS= read -r line; do + # remove comments + line=${line%%#*} + # remove trailing whitespace + line="${line%"${line##*[![:space:]]}"}" + LINENUM=$((LINENUM+1)) + + # add settings for user appdir + if [ "${line}" != "${line#-Dsetuserappdirpath=}" ]; then # starts with -Dsetuserappdirpath= + JVMARGS=( "${JVMARGS[@]}" "${line}" ) + fi + if [ "${line}" != "${line#-Dnouserdefaultappdir=}" ]; then # starts with -Dnouserdefaultappdir= + # don't perform user update if user updates are disabled + NOUSERUPDATEVALUE="$(echo "${line#-Dnouserdefaultappdir=}" | tr '[:upper:]' '[:lower:]')" + if [ "${NOUSERUPDATEVALUE}" = "true" ]; then + echo "Cannot perform manual user-space update when user-space updates are disabled." >&2 + echo "See line ${LINENUM} (${line}) in file '${VMOPTIONS}'." >&2 + exit 14 + fi + JVMARGS=( "${JVMARGS[@]}" "${line}" ) + fi + done < "${VMOPTIONS}" + fi + JVMARGS=( "${JVMARGS[@]}" "-Duserdefaultappdir=true" ) + fi + + # installation update + if [ "${UPDATEINSTALLATION}" = 1 ]; then + JVMARGS=( "${JVMARGS[@]}" "-Dnouserdefaultappdir=true" ) + fi + + # tell getdown to update jalview withouth launching JVMARGS=( "${JVMARGS[@]}" "-Dsilent=true" ) - JVMARGS=( "${JVMARGS[@]}" "-Dnouserdefaultappdir=true" ) + JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.script=${SCRIPT}" ) + JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.update=true" ) JVMARGS=( "${JVMARGS[@]}" "-Dappid=jalview" ) JVMARGS=( "${JVMARGS[@]}" "-Dinstaller.appdir=${APPDIR}" ) # resetting ARGS to just these two values ARGS=( "${APPDIR}" "jalview" ) - + # add these Just In Case although jalview shouldn't be launched + ARGS=( "${ARGS[@]}" "--headless" "--quit" "--nojavaconsole" "--nosplash" "--nonews" ) else # LAUNCHING JALVIEW without getdown-launcher @@ -166,13 +220,12 @@ else JVMARGS=( "${JVMARGS[@]}" "-Dinstaller.appdir=${APPDIR}" ) JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.appdir=${APPDIR}" ) JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.script=${SCRIPT}" ) - fi # WINDOWS ONLY (Cygwin or WSL) # change paths for Cygwin or Windows Subsystem for Linux (WSL) if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoid - if [ "$(uname -o)" = "Cygwin" ]; then + if [ "$(uname -o)" = "Cygwin" ]; then # Cygwin # CYGWIN CLASSPATH=$(cygpath -pw "${CLASSPATH}") # now for some arg paths fun. only translating paths starting with './', '../', '/' or '~' @@ -184,7 +237,7 @@ if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoi ARGS=( "${ARGS[@]}" "${ARG}" ) fi done - elif uname -r | grep -i microsoft | grep -i wsl >/dev/null; then + elif uname -r | grep -i microsoft | grep -i wsl >/dev/null; then # Windows Subsystem for Linux (WSL) # WSL CLASSPATH="" for JARPATH in "${JARPATHS[@]}"; do @@ -207,10 +260,10 @@ if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoi fi fi -# Is there a bundled Java? If not just try one in the PATH (do need .exe in WSL) +# Is there a bundled Java? If not just try one in the PATH (we need .exe in WSL, added above) if [ \! -e "${JAVA}" ]; then JAVA=$SYSJAVA - echo "Cannot find bundled java, using system ${JAVA} and hoping for the best!" >&2 + echo "Cannot find bundled ${JAVA}, using system ${SYSJAVA} and hoping for the best!" >&2 fi # This is just needed for display purposes @@ -229,7 +282,7 @@ JVMARGSSTR=$(quotearray "${JVMARGS[@]}") ARGSSTR=$(quotearray "${ARGS[@]}") if [ "${DEBUG}" = 1 ]; then - echo Shell running: \""${JAVA}"\" ${JVMARGSSTR} -cp \""${CLASSPATH}"\" "${CLASS}" ${ARGSSTR} + echo Shell running: \""${JAVA}"\" ${JVMARGSSTR} -cp \""${CLASSPATH}"\" \""${CLASS}"\" ${ARGSSTR} >&2 fi "${JAVA}" "${JVMARGS[@]}" -cp "${CLASSPATH}" "${CLASS}" "${ARGS[@]}" -- 1.7.10.2