-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinstall.ps1
More file actions
69 lines (57 loc) · 2.29 KB
/
install.ps1
File metadata and controls
69 lines (57 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# jbundle installer for Windows
# Usage: irm https://raw.githubusercontent.com/avelino/jbundle/main/install.ps1 | iex
$ErrorActionPreference = "Stop"
$Repo = "avelino/jbundle"
$Artifact = "jbundle-windows-x86_64"
$InstallDir = if ($env:JBUNDLE_INSTALL_DIR) { $env:JBUNDLE_INSTALL_DIR } else { "$env:USERPROFILE\.jbundle\bin" }
function Get-LatestVersion {
try {
$release = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest"
return $release.tag_name
} catch {
return $null
}
}
$Version = if ($env:JBUNDLE_VERSION) { $env:JBUNDLE_VERSION } else { $null }
if (-not $Version) {
Write-Host "Fetching latest version..."
$Version = Get-LatestVersion
if (-not $Version) {
Write-Host "Could not determine latest version, using pre-release..."
$Version = "latest"
}
}
if ($Version -eq "latest") {
$ZipName = "$Artifact.zip"
} else {
$ZipName = "$Artifact-$Version.zip"
}
if ($Version -eq "latest") {
$DownloadUrl = "https://github.com/$Repo/releases/latest/download/$ZipName"
} else {
$DownloadUrl = "https://github.com/$Repo/releases/download/$Version/$ZipName"
}
Write-Host "Downloading jbundle $Version for Windows..."
Write-Host " $DownloadUrl"
$TmpDir = New-Item -ItemType Directory -Force -Path (Join-Path $env:TEMP "jbundle-install-$(Get-Random)")
$ZipPath = Join-Path $TmpDir $ZipName
try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipPath -UseBasicParsing
Expand-Archive -Path $ZipPath -DestinationPath $TmpDir -Force
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
Copy-Item (Join-Path $TmpDir "jbundle.exe") (Join-Path $InstallDir "jbundle.exe") -Force
# Add to PATH if not already there
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("Path", "$InstallDir;$UserPath", "User")
Write-Host ""
Write-Host "Added $InstallDir to your PATH."
Write-Host "Restart your terminal for PATH changes to take effect."
}
Write-Host ""
Write-Host "jbundle installed to $InstallDir\jbundle.exe"
Write-Host ""
Write-Host "Run 'jbundle --help' to get started."
} finally {
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
}