Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix powershell script for non-windows users #815

Merged
merged 4 commits into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Make sure to source `jabba.sh` in your environment if you skip it:
```sh
[ -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 -
`curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash; and . ~/.jabba/jabba.fish`
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)
"@