$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 -Path $MyInvocation.MyCommand.Path -Parent } Else { Split-Path -Path $TARGET -Parent }
+# 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)
+ $Return = $null
+ $c = 0
+ $max = 100 # just in case we end up in a loop
+ [bool] $found = 0
+ $file = Get-Item -Path $Link
+ $prevfile = $null
+ While ( $c -lt $max -and "${file}" -ne "${prevfile}" -and -not $found ) {
+ $prevfile = $file
+ [string] $target = ( $file ).Target
+ If ( $target -eq $null -or ( $file ).LinkType -ne "SymbolicLink" ) {
+ $Return = $file
+ $found = 1
+ } Else {
+ If ( $( Split-Path -Path $target -IsAbsolute ) ) {
+ $file = Get-Item -Path $target
+ } Else {
+# symbolic link is relative: combine previous link parent dir with the link target and resolve
+ $file = Get-Item -Path ( Join-Path -Path ( Split-Path -Path $prevfile -Parent ) -ChildPath $target -Resolve )
+ }
+ }
+ $c++
+ }
+ if ( -not $found ) {
+ throw "Could not determine path to actual file $( Split-Path -Path $Link -Leaf )"
+ }
+ $Return
+}
+
+# Avert problem with unix version of powershell and tell user the reason (Windows must always have .ps1 extension)
+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
+$DIR = Split-Path -Path $SCRIPTPATH -Parent
# set the "-open" parameter if myArg1 is non-zero-length, and not "open" or starts with a "-"
$OPEN = ""
# look for getdown.txt -- needed to create classpath
if ( -not ( Test-Path -Path "${GETDOWNTXT}" ) ) {
- throw "Cannot find getdown.txt"
+ throw "Cannot find ${GETDOWNTXT}"
}
# look for bundled JRE. Might not be there if unix installer used in which case just invoke "java"