Skip to content

Commit

Permalink
Merge pull request #815 from sipgate/pwsh-cross-platform
Browse files Browse the repository at this point in the history
Fix powershell script for non-windows users
  • Loading branch information
willcohen authored Nov 20, 2021
2 parents 52ed3f0 + eedc1c6 commit c83236b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ Make sure to source `jabba.sh` in your environment if you skip it:
export JABBA_VERSION=...
[ -s "$JABBA_HOME/jabba.sh" ] && source "$JABBA_HOME/jabba.sh"
```
> (in powershell)
```powershell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-Expression (
Invoke-WebRequest https://github.com/shyiko/jabba/raw/master/install.ps1 -UseBasicParsing
).Content
```

> In [fish](https://fishshell.com/) command looks a little bit different -
> export JABBA_VERSION=...
Expand Down
50 changes: 43 additions & 7 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
$ErrorActionPreference = "Stop"

$jabbaHome = if ($env:JABBA_HOME) { $env:JABBA_HOME } else { if ($env:JABBA_DIR) { $env:JABBA_DIR } else { "$env:USERPROFILE\.jabba" } }
$sep = [IO.Path]::DirectorySeparatorChar
$jabbaHome = if ($env:JABBA_HOME) {
$env:JABBA_HOME
} else {
if ($env:JABBA_DIR) {
$env:JABBA_DIR
} else {
if($env:USERPROFILE){
"$env:USERPROFILE" + $sep + ".jabba"
}else{
"$env:HOME" + $sep + ".jabba"
}
}
}
$jabbaVersion = if ($env:JABBA_VERSION) { $env:JABBA_VERSION } else { "latest" }
# The Windows values of the Platform enum are:
# 0 (Win32NT), 1 (Win32S), 2 (Win32Windows) and 3 (WinCE).
# Other values are larger and indicate non Windows operating systems
$isOnWindows = [System.Environment]::OSVersion.Platform.value__ > 3
$jabbaExecutableName = $isOnWindows ? "jabba.exe" : "jabba"

if ($jabbaVersion -eq "latest")
{
Expand All @@ -25,17 +43,35 @@ if ($env:JABBA_MAKE_INSTALL -eq "true")
}
else
{
Invoke-WebRequest https://github.com/shyiko/jabba/releases/download/$jabbaVersion/jabba-$jabbaVersion-windows-amd64.exe -UseBasicParsing -OutFile $jabbaHome/bin/jabba.exe
# $isOnWindows, see top of the file
# macOS enum value: 6
# Unix enum value: 4
if($isOnWindows){
Invoke-WebRequest https://github.com/shyiko/jabba/releases/download/$jabbaVersion/jabba-$jabbaVersion-windows-amd64.exe -UseBasicParsing -OutFile $jabbaHome/bin/$jabbaExecutableName
}
elseif([System.Environment]::OSVersion.Platform.value__ -eq 4 || [System.Environment]::OSVersion.Platform.value__ -eq 6){
Invoke-WebRequest https://github.com/shyiko/jabba/releases/download/$jabbaVersion/jabba-$jabbaVersion-darwin-amd64 -UseBasicParsing -OutFile $jabbaHome/bin/$jabbaExecutableName
}else{
$osArch = [System.Environment]::Is64BitOperatingSystem ? "amd64" : "386"
Invoke-WebRequest https://github.com/shyiko/jabba/releases/download/$jabbaVersion/jabba-$jabbaVersion-linux-${OSARCH} -UseBasicParsing -OutFile $jabbaHome/bin/$jabbaExecutableName
}
}

$ErrorActionPreference="SilentlyContinue"
& $jabbaHome\bin\jabba.exe --version | Out-Null

if($isOnWindows){
& "$jabbaHome\bin\$jabbaExecutableName" --version | Out-Null
}else{
chmod a+x "$jabbaHome/bin/$jabbaExecutableName"
& "$jabbaHome/bin/$jabbaExecutableName" --version | Out-Null
}

$binaryValid = $?
$ErrorActionPreference="Continue"
if (-not $binaryValid)
{
Write-Host @"
$jabbaHome\bin\jabba does not appear to be a valid binary.
Write-Host -ForegroundColor Yellow @"
$jabbaHome\bin\$jabbaExecutableName does not appear to be a valid binary.
Check your Internet connection / proxy settings and try again.
if the problem persists - please create a ticket at https://github.com/shyiko/jabba/issues.
Expand All @@ -49,7 +85,7 @@ if the problem persists - please create a ticket at https://github.com/shyiko/ja
function jabba
{
`$fd3=`$([System.IO.Path]::GetTempFileName())
`$command="& '$jabbaHome\bin\jabba.exe' `$args --fd3 ```"`$fd3```""
`$command="& '$jabbaHome\bin\$jabbaExecutableName' `$args --fd3 ```"`$fd3```""
& { `$env:JABBA_SHELL_INTEGRATION="ON"; Invoke-Expression `$command }
`$fd3content=`$(Get-Content `$fd3)
if (`$fd3content) {
Expand Down Expand Up @@ -81,6 +117,6 @@ else

Write-Host @"
Installation completed
Installation completed (you might need to restart your terminal for the jabba command to be available)
(if you have any problems please report them at https://github.com/shyiko/jabba/issues)
"@

0 comments on commit c83236b

Please sign in to comment.