From: Ben Soares Date: Wed, 31 Jul 2024 15:38:42 +0000 (+0100) Subject: JAL-3631 Changes to bash launcher to allow headless updates to user-space or installa... X-Git-Tag: Release_2_11_4_0~17^2~3^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ba6b59f8f3995f6161b0bd9518773e60a1ebcf16;p=jalview.git JAL-3631 Changes to bash launcher to allow headless updates to user-space or installation. Added some of this functionality to Powershell (work in progress). The update functionality is to be separated out to update.sh. --- diff --git a/utils/getdown/bin/jalview.ps1 b/utils/getdown/bin/jalview.ps1 index 1098010..d57b1de 100755 --- a/utils/getdown/bin/jalview.ps1 +++ b/utils/getdown/bin/jalview.ps1 @@ -16,6 +16,44 @@ if ( $IsWindows -eq $null ) { $myIsMacOS = $IsMacOS } +# are we running an update +[bool] $update = 0 +[bool] $updateuser = 0 +[bool] $updateinstallation = 0 +[bool] $headless = 0 +[bool] $help = 0 +[bool] $gui = 0 +[bool] $debug = 0 +for ( $i = 0; $i -lt $args.count; $i++ ) { + if ( $args[$i] -eq "--updateuser" ) { + $update = 1 + $updateuser = 1 + $headless = 1 + } + if ( $args[$i] -eq "--updateinstallation" ) { + $update = 1 + $updateinstallation = 1 + $headless = 1 + } + if ( $args[$i] -eq "--help" -or $args[$i].StartsWith("--help-") -or $args[$i] -eq "--version" -or $args[$i] -eq "-h" ) { + $help = 1 + $headless = 1 + } + if ( $args[$i] -eq "--gui" ) { + $gui = 1 + } + if ( $args[$i] -eq "--debug" ) { + $debug = 1 + } +} +if ( $help ) { + $gui = 0 +} elseif ( $update ) { + $gui = 0 +} elseif ( $gui ) { + $headless = 0 +} + # parent dir of this actual script (which should be the getdown appdir/bin). Follow all symlinks. Like GNU readlink -f function Readlink-f { Param($Link) @@ -52,37 +90,100 @@ if ( $MyInvocation.MyCommand.Path -eq $null ) { throw "Script or link to script must have extension .ps1" } - $CMDPATH = ( Get-Item $MyInvocation.MyCommand.Path ) $SCRIPTPATH = Readlink-f -Link $CMDPATH +$SCRIPT = $SCRIPTPATH $DIR = Split-Path -Path $SCRIPTPATH -Parent $APPDIR = If ( ( Split-Path -Path $DIR -Leaf ) -eq "bin" ) { Split-Path -Path $DIR -Parent } Else { $DIR } $JAVAEXE = If ( $myIsWindows ) { "java.exe" } Else { "java" } $JAVA = Join-Path -Path $APPDIR -ChildPath ( "jre/" + $( If ( $myIsMacOS ) { "Contents/Home/" } Else { "" } ) + "bin/${JAVAEXE}" ) -$GETDOWNTXT = Join-Path -Path $APPDIR -ChildPath "getdown.txt" +$JVMARGS = @() -# look for getdown.txt -- needed to create classpath -if ( -not ( Test-Path -Path "${GETDOWNTXT}" ) ) { - throw "Cannot find ${GETDOWNTXT}" +if ( $headless ) { + # not setting java.awt.headless in java invocation of running jalview due to problem with Jmol + if ( $help ) { + $JVMARGS += "-Djava.awt.headless=true" + } + # this suppresses the Java icon appearing in the macOS Dock + if ( $myIsMacOS ) { + $JVMARGS += "-Dapple.awt.UIElement=true" + } } +$GETDOWNTXT = Join-Path -Path $APPDIR -ChildPath "getdown.txt" +$GETDOWNJAR = Join-Path -Path $APPDIR -ChildPath "getdown-launcher.jar" + # look for bundled JRE. Might not be there if unix installer used in which case just invoke "java" if ( -not ( Test-Path -Path "${JAVA}" ) ) { Write-Host "Cannot find bundled ${JAVAEXE}. Using system ${JAVAEXE} and hoping for the best!" $JAVA = $JAVAEXE } -$CLASSPATH = ( Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { Join-Path -Path $APPDIR -ChildPath $($_.Matches.Groups[1].Value ) } ) -join $( If ( $myIsWindows ) { ";" } Else { ":" } ) +$CLASS = "jalview.bin.Launcher" +if ( $update ) { + + # JUST RUNNING A GETDOWN INSTALLATION UPDATE, not launching Jalview + $CLASS = "com.threerings.getdown.launcher.GetdownApp" -# get console width -$CONSOLEWIDTH = $Host.UI.RawUI.WindowSize.Width + $CLASSPATH = $GETDOWNJAR + + # installation update + if ( $updateinstallation ) { + $JVMARGS += "-Dnouserdefaultappdir=true" + } + + # tell getdown to update jalview without launching + $JVMARGS += "-Dsilent=true" + $JVMARGS += "-Dlauncher.script=${SCRIPT}" + $JVMARGS += "-Dlauncher.update=true" + $JVMARGS += "-Dappid=jalview" + $JVMARGS += "-Dinstaller.appdir=${APPDIR}" + # resetting ARGS to just these two values + $myArgs = @("${APPDIR}", "jalview") + # add these Just In Case although jalview shouldn't be launched + $myArgs += "--headless", "--quit", "--nojavaconsole", "--nosplash", "--nonews" + +} else { + + # LAUNCHING JALVIEW without getdown-launcher + $CLASS = "jalview.bin.Launcher" + # look for getdown.txt -- needed to create classpath + if ( -not ( Test-Path -Path "${GETDOWNTXT}" ) ) { + throw "Cannot find ${GETDOWNTXT}" + } + # get CLASSPATH from the code= entries in getdown.txt + $CLASSPATH = ( Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { Join-Path -Path $APPDIR -ChildPath $($_.Matches.Groups[1].Value ) } ) -join $( If ( $myIsWindows ) { ";" } Else { ":" } ) + + # get console width + $CONSOLEWIDTH = $Host.UI.RawUI.WindowSize.Width + $JVMARGS += "-DCONSOLEWIDTH=${CONSOLEWIDTH}" + $JVMARGS += "-Dgetdownappdir=${APPDIR}" + $JVMARGS += "-Dinstaller.appdir=${APPDIR}" + $JVMARGS += "-Dlauncher.appdir=${APPDIR}" + $JVMARGS += "-Dlauncher.script=${SCRIPT}" + +} + +# we should always have at least one JVMARGS +$myJvmArgsString = '"' + $($JVMARGS -join '" "') + '"' # quote the args and the command (in case of spaces) with escape chars (`) and precede with & to indicate command not string if ( $myArgs.count -eq 0 ) { - Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" `"-Dgetdownappdir=${APPDIR}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher" + $COMMAND = "& `"${JAVA}`" ${myJvmArgsString} -cp `"${CLASSPATH}`" $CLASS" } else { $myArgsString = '"' + $($myArgs -join '" "') + '"' - Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" `"-Dgetdownappdir=${APPDIR}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher ${myArgsString}" + $COMMAND = "& `"${JAVA}`" ${myJvmArgsString} -cp `"${CLASSPATH}`" $CLASS ${myArgsString}" } +if ( $debug -or $help ) { + Write-Error -Message "Shell running: ${COMMAND}" +} + +Invoke-Expression -Command ${COMMAND} + +# move updated getdown-launcher.jar into place +if ( $update ) + Invoke-Expression -Command "& `"${JAVA}`" ${myJvmArgString} -cp `"${GDCOREPATH}`" jalview.bin.GetdownUpdate `"${APPDIR}`" +fi + diff --git a/utils/getdown/bin/jalview.sh b/utils/getdown/bin/jalview.sh index 9fb7058..58a13d8 100755 --- a/utils/getdown/bin/jalview.sh +++ b/utils/getdown/bin/jalview.sh @@ -124,15 +124,37 @@ fi SYSJAVA=java GETDOWNTXT="${APPDIR}/getdown.txt" GETDOWNJAR="${APPDIR}/getdown-launcher.jar" +CHANNELPROPS="${APPDIR}/channel.props" +NAME="$( grep app_name= App/channel.props | cut -d= -f2 )" +US_NAME="${NAME// /_}" CLASSPATH="" # save an array of JAR paths in case we're in WSL (see later) declare -a JARPATHS=() +declare -a APPJARPATHS=() +GDCOREPATH="${APPDIR}/resource/getdown-core.jar" + +# get classpath from getdown.txt +if [ -e "${GETDOWNTXT}" ]; then + # always check grep and sed regexes on macos -- they're not the same + for JAR in $(grep -e '^code[[:space:]]*=[[:space:]]*' "${GETDOWNTXT}" | while read -r line; do echo $line | sed -E -e 's/code[[:space:]]*=[[:space:]]*//;'; done); + do + [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH}:" + CLASSPATH="${CLASSPATH}${APPDIR}/${JAR}" + APPJARPATHS=( "${APPJARPATHS[@]}" "${APPDIR}/${JAR}" ) + if [ "${JAR}" != "${JAR%getdown-core.jar}" -a \! -e "${GDCOREPATH}" ]; then + GDCOREPATH="${APPDIR}/${JAR}" + fi + done +else + echo "Cannot find getdown.txt" >&2 + exit 3 +fi CLASS="jalview.bin.Launcher" # set as default Just In Case if [ "${UPDATE}" = 1 ]; then - # JUST RUNNING A GETDOWN INSTALLATION UPDATE, not launching Jalview + # GETDOWN UPDATE ONLY, not launching Jalview CLASS="com.threerings.getdown.launcher.GetdownApp" if [ -e "${GETDOWNJAR}" ]; then CLASSPATH="${GETDOWNJAR}" @@ -142,7 +164,7 @@ if [ "${UPDATE}" = 1 ]; then exit 13 fi - # user-space update + # USER space update if [ "${UPDATEUSER}" = 1 ]; then if [ -e "${VMOPTIONS}" ]; then LINENUM=0 @@ -170,40 +192,37 @@ if [ "${UPDATE}" = 1 ]; then done < "${VMOPTIONS}" fi JVMARGS=( "${JVMARGS[@]}" "-Duserdefaultappdir=true" ) + # resetting ARGS to just these two blank values so userappdir is determined + ARGS=( "" "jalview" ) fi - # installation update + # INSTALLATION update if [ "${UPDATEINSTALLATION}" = 1 ]; then JVMARGS=( "${JVMARGS[@]}" "-Dnouserdefaultappdir=true" ) + JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.appdir=${APPDIR}" ) + # resetting ARGS to just these two values + ARGS=( "${APPDIR}" "jalview" ) fi + # both USER and INSTALLATION updates + JVMARGS=( "${JVMARGS[@]}" "-Dinstaller.appdir=${APPDIR}" ) + # tell getdown to update jalview withouth launching JVMARGS=( "${JVMARGS[@]}" "-Dsilent=true" ) - JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.script=${SCRIPT}" ) + JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.update=true" ) JVMARGS=( "${JVMARGS[@]}" "-Dappid=jalview" ) - JVMARGS=( "${JVMARGS[@]}" "-Dinstaller.appdir=${APPDIR}" ) + JVMARGS=( "${JVMARGS[@]}" "-Dchannel.app_name=${NAME}" ) + JVMARGS=( "${JVMARGS[@]}" "-Dinstaller.application_folder=${US_NAME}" ) - # resetting ARGS to just these two values - ARGS=( "${APPDIR}" "jalview" ) - # add these Just In Case although jalview shouldn't be launched + # add these Just In Case although jalview shouldn't be launched due to -Dsilent=true ARGS=( "${ARGS[@]}" "--headless" "--quit" "--nojavaconsole" "--nosplash" "--nonews" ) + else # LAUNCHING JALVIEW without getdown-launcher CLASS="jalview.bin.Launcher" - if [ -e "${GETDOWNTXT}" ]; then - # always check grep and sed regexes on macos -- they're not the same - for JAR in $(grep -e '^code[[:space:]]*=[[:space:]]*' "${GETDOWNTXT}" | while read -r line; do echo $line | sed -E -e 's/code[[:space:]]*=[[:space:]]*//;'; done); - do - [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH}:" - CLASSPATH="${CLASSPATH}${APPDIR}/${JAR}" - JARPATHS=( "${JARPATHS[@]}" "${APPDIR}/${JAR}" ) - done - else - echo "Cannot find getdown.txt" >&2 - exit 3 - fi + JARPATHS="${APPJARPATHS[@]}" COLUMNS=80 # get console width -- three ways to try, just in case (not needed for update) @@ -217,13 +236,13 @@ else JVMARGS=( "${JVMARGS[@]}" "-DCONSOLEWIDTH=${COLUMNS}" ) JVMARGS=( "${JVMARGS[@]}" "-Dgetdownappdir=${APPDIR}" ) - JVMARGS=( "${JVMARGS[@]}" "-Dinstaller.appdir=${APPDIR}" ) - JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.appdir=${APPDIR}" ) - JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.script=${SCRIPT}" ) + fi +JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.script=${SCRIPT}" ) +JVMARGS=( "${JVMARGS[@]}" "-Dinstaller.appdir=${APPDIR}" ) -# WINDOWS ONLY (Cygwin or WSL) -# change paths for Cygwin or Windows Subsystem for Linux (WSL) +# WINDOWS ONLY in Cygwin or Windows Subsystem for Linux (WSL) +# change paths for Cygwin or WSL if [ "${ISMACOS}" != 1 ]; then # older macos doesn't like uname -o, best to avoid if [ "$(uname -o)" = "Cygwin" ]; then # Cygwin # CYGWIN @@ -237,7 +256,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 # Windows Subsystem for Linux (WSL) + elif uname -r | grep -i microsoft | grep -i wsl >/dev/null; then # WSL # WSL CLASSPATH="" for JARPATH in "${JARPATHS[@]}"; do @@ -286,3 +305,11 @@ if [ "${DEBUG}" = 1 ]; then fi "${JAVA}" "${JVMARGS[@]}" -cp "${CLASSPATH}" "${CLASS}" "${ARGS[@]}" + +# move updated getdown-launcher.jar into place +if [ "${DEBUG}" = 1 ]; then + echo Shell running: \""${JAVA}"\" ${JVMARGSSTR} -cp \""${GDCOREPATH}"\" jalview.bin.GetdownLauncherUpdate >&2 +fi +if [ "${UPDATE}" = 1 ]; then + "${JAVA}" "${JVMARGS[@]}" -cp "${GDCOREPATH}" jalview.bin.GetdownLauncherUpdate +fi