#!/usr/bin/env pwsh # save args and first parameter $myArgs = $args.Clone() $myArg1 = $args[0] # setup for powershell version < 6.0 [bool] $myIsWindows = 0 [bool] $myIsMacOS = 0 if ( $IsWindows -eq $null ) { # for powershell version < 6.0 let's assume Windows $myIsWindows = 1 $myIsMacOS = 0 } else { $myIsWindows = $IsWindows $myIsMacOS = $IsMacOS } # parent dir of this script (should be the getdown app dir). Follow symlinks. $TARGET = ( Get-Item $MyInvocation.MyCommand.Path ).Target $DIR = If ( $TARGET -eq $null -or $TARGET.LinkType -ne "SymbolicLink" ) { Split-Path $MyInvocation.MyCommand.Path -Parent } Else { Split-Path $TARGET -Parent } # set the "-open" parameter if myArg1 is non-zero-length, and not "open" or starts with a "-" $OPEN = "" if ( $myArg1.length -gt 0 -and ( -not $myArg1.StartsWith("-") ) -and $myArg1 -cne "open" ) { $OPEN = "-open" } $APPDIR = $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" # look for getdown.txt -- needed to create classpath if ( -not ( Test-Path -Path "${GETDOWNTXT}" ) ) { throw "Cannot find getdown.txt" } # 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 { ":" } ) # quote the args and the command (in case of spaces) with escape chars (`) and precede with & to indicate command not string $myArgsString = '"' + $($myArgs -join '" "') + '"' Invoke-Expression -Command "& `"${JAVA}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher ${OPEN} ${myArgsString}"