From 8d8c09f5cc4f2bb4b5f443323e0db7b9570c9d18 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 1 Aug 2024 17:24:00 +0100 Subject: [PATCH] JAL-3631 Added a test for a specified update and a usage line. update.ps1 tested on macos --- utils/getdown/bin/update.ps1 | 66 +++++++++++++++++++++++++++++++++--------- utils/getdown/bin/update.sh | 17 ++++++++--- 2 files changed, 65 insertions(+), 18 deletions(-) diff --git a/utils/getdown/bin/update.ps1 b/utils/getdown/bin/update.ps1 index 171bece..d01747a 100644 --- a/utils/getdown/bin/update.ps1 +++ b/utils/getdown/bin/update.ps1 @@ -16,6 +16,8 @@ if ( $IsWindows -eq $null ) { $myIsMacOS = $IsMacOS } +$USAGE = "Please use either --installation or --userspace." + [bool] $debug = 0 [bool] $userspace = 0 [bool] $installation = 0 @@ -33,10 +35,15 @@ Switch ($args) { Continue } Default { - throw "Unknown option '$_'. Please use either --installation or --userspace." + throw "Unknown option '$_'. ${USAGE}." } } +if ( -not ( $userspace -or -$installation ) ) { + Write-Output "${USAGE}." + Exit +} + # 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) @@ -121,50 +128,81 @@ if ( Test-Path -Path $GETDOWNCOREJAR ) { # USER space update if ( $userspace ) { if ( Test-Path -Path $VMOPTIONS ) { + $LINENUM = 0 foreach ( $line in Get-Content $VMOPTIONS ) { + # remove comments $line -Replace "#.*", "" + # remove leading and trailing whitespace + $line -Replace "(^\s+|\s+$)", "" + $LINENUM++ + if ( $line -Match "^-Dsetuserappdirpath=" ) { $JVMARGS += $line } if ( $line -Match "^-Dnouserdefaultappdir=" ) { $NOUSERUPDATEVALUE = ( $line -Replace ".*=", "" ).ToLower() if ( $NOUSERUPDATEVALUE -eq "true" ) { - ### HERE + throw "Cannot perform manual user-space update when user-space updates are disabled.`nSee line ${LINENUM} (${line}) in file '${VMOPTIONS}'." } $JVMARGS += $line } } } + $JVMARGS += "-Duserdefaultappdir=true" + $JVMARGS += "-Dnouserdefaultappdir=false" } +# INSTALLATION update +if ( $installation ) { + $JVMARGS += "-Duserdefaultappdir=false" + $JVMARGS += "-Dnouserdefaultappdir=true" + $JVMARGS += "-Dlauncher.appdir=${APPDIR}" + $JVMARGS += "-Dappdir=${APPDIR}" +} +# setting the appdir arg[0] and appid arg[1] to blank values +# so appDir is determined by EnvConfig.getUserAppdir() or appdir property +# and appId is passed as system property appid +$GDL_ARGS = @( "", "" ) - -# get console width -$JVMARGS += "-Dgetdownappdir=${APPDIR}" +# both USER and INSTALLATION updates $JVMARGS += "-Dinstaller.appdir=${APPDIR}" +$JVMARGS += "-Dinstaller.application_folder=${US_NAME}" $JVMARGS += "-Dlauncher.script=${SCRIPT}" +$JVMARGS += "-Dlauncher.update=true" +$JVMARGS += "-Dchannel.app_name=${NAME}" +$JVMARGS += "-Dappid=jalview" + +# IMPORTANT! tell getdown to update jalview withouth launching +$JVMARGS += "-Dsilent=true" + +# add these Just In Case although jalview shouldn't be launched due to -Dsilent=true +$GDL_ARGS += ( "--headless", "--quit", "--nojavaconsole", "--nosplash", "--nonews" ) # look for bundled JRE. Might not be there if unix installer used in which case just invoke "java" -if ( -not ( Test-Path -Path "${JAVA}" ) ) { +if ( -not ( Test-Path -Path $JAVA ) ) { Write-Host "Cannot find bundled ${JAVA}. Using system ${JAVAEXE} and hoping for the best!" $JAVA = $JAVAEXE } -# we should always have at least one JVMARGS so this is okay +# we should always have at least one JVMARGS and GDL_ARGS so this is okay $myJvmArgsString = '"' + $($JVMARGS -join '" "') + '"' +$myGdlArgsString = '"' + $($GDL_ARGS -join '" "') + '"' # quote the args and the command (in case of spaces) with escape chars (`) and precede with & to indicate a command not string -if ( $myArgs.count -eq 0 ) { - $COMMAND = "& `"${JAVA}`" ${myJvmArgsString} -cp `"${CLASSPATH}`" $CLASS" -} else { - $myArgsString = '"' + $($myArgs -join '" "') + '"' - $COMMAND = "& `"${JAVA}`" ${myJvmArgsString} -cp `"${CLASSPATH}`" $CLASS ${myArgsString}" -} +$COMMAND = "& `"${JAVA}`" ${myJvmArgsString} -cp `"${GDL_CLASSPATH}`" com.threerings.getdown.launcher.GetdownApp ${myGdlArgsString}" -if ( $debug -or $help ) { +if ( $debug ) { Write-Error -Message "Shell running: ${COMMAND}" } Invoke-Expression -Command ${COMMAND} +# move updated getdown-launcher.jar into place +$COMMAND = "& `"${JAVA}`" ${myJvmArgsString} -cp `"${GDC_CLASSPATH}`" jalview.bin.GetdownLauncherUpdate" + +if ( $debug ) { + Write-Error -Message "Shell running: ${COMMAND}" +} + +Invoke-Expression -Command ${COMMAND} diff --git a/utils/getdown/bin/update.sh b/utils/getdown/bin/update.sh index bfb0ba1..28755aa 100755 --- a/utils/getdown/bin/update.sh +++ b/utils/getdown/bin/update.sh @@ -7,6 +7,8 @@ if [ "$( uname -s )" = "Darwin" ]; then ISMACOS=1 fi +USAGE="Please use either --installation or --userspace" + DEBUG=0 USERSPACE=0 INSTALLATION=0 @@ -23,11 +25,16 @@ for RAWARG in "${@}"; do USERSPACE=1 ;; *) - echo "Unknown option '${ARG}'. Please use either --installation or --userspace." >&2 + echo "Unknown option '${ARG}'. ${USAGE}." >&2 exit 2 esac done +if [ "${USERSPACE}${INSTALLATION}" = "00" ]; then + echo "${USAGE}." + exit +fi + # this whole next part is because there's no readlink -f in Darwin function readlinkf() { FINDFILE="$1" @@ -126,8 +133,9 @@ if [ "${USERSPACE}" = 1 ]; then while IFS= read -r line; do # remove comments line=${line%%#*} - # remove trailing whitespace + # remove leading and trailing whitespace line="${line%"${line##*[![:space:]]}"}" + line="${line#"${line%%[![:space:]]*}"}" LINENUM=$((LINENUM+1)) # add settings for user appdir @@ -148,7 +156,6 @@ if [ "${USERSPACE}" = 1 ]; then fi JVMARGS=( "${JVMARGS[@]}" "-Duserdefaultappdir=true" ) JVMARGS=( "${JVMARGS[@]}" "-Dnouserdefaultappdir=false" ) - # setting the appdir arg[0] to a blank value so appDir is determined by EnvConfig.getUserAppdir() fi # INSTALLATION update @@ -157,9 +164,11 @@ if [ "${INSTALLATION}" = 1 ]; then JVMARGS=( "${JVMARGS[@]}" "-Dnouserdefaultappdir=true" ) JVMARGS=( "${JVMARGS[@]}" "-Dlauncher.appdir=${APPDIR}" ) JVMARGS=( "${JVMARGS[@]}" "-Dappdir=${APPDIR}" ) - # set GDL_ARGS to these two values fi +# setting the appdir arg[0] and appid arg[1] to blank values +# so appDir is determined by EnvConfig.getUserAppdir() or appdir property +# and appId is passed as system property appid GDL_ARGS=( "" "" ) # both USER and INSTALLATION updates -- 1.7.10.2