-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
88 lines (75 loc) · 3.08 KB
/
Copy pathinstall.ps1
File metadata and controls
88 lines (75 loc) · 3.08 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<#
.SYNOPSIS
Ioruba installer for Windows.
.DESCRIPTION
Detects the architecture, downloads the matching installer from the latest
GitHub release (or a tag passed with -Version), verifies it against
SHA256SUMS.txt when available, and runs it.
.EXAMPLE
irm https://raw.githubusercontent.com/bernardopg/ioruba/main/scripts/install.ps1 | iex
.EXAMPLE
.\install.ps1 -Version v1.1.0 -Type nsis
#>
[CmdletBinding()]
param(
[string]$Version = "latest",
[ValidateSet("msi", "nsis")]
[string]$Type = "msi",
[string]$Repo = $env:IORUBA_REPO
)
$ErrorActionPreference = "Stop"
if ([string]::IsNullOrEmpty($Repo)) { $Repo = "bernardopg/ioruba" }
function Write-Step($msg) { Write-Host "▸ $msg" -ForegroundColor Cyan }
function Write-Warn($msg) { Write-Host "! $msg" -ForegroundColor Yellow }
$apiBase = "https://api.github.com/repos/$Repo/releases"
$apiUrl = if ($Version -eq "latest") { "$apiBase/latest" } else { "$apiBase/tags/$Version" }
Write-Step "Querying $Repo release: $Version"
$release = Invoke-RestMethod -Uri $apiUrl -Headers @{ "User-Agent" = "ioruba-installer" }
# Architecture token used in tauri Windows asset names.
$arch = if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x64" }
function Get-Asset($pattern) {
$release.assets | Where-Object { $_.name -match $pattern } | Select-Object -First 1
}
if ($Type -eq "msi") {
$archPattern = "_$arch.*\.msi$"
$anyPattern = "\.msi$"
} else {
$archPattern = "_$arch.*setup\.exe$"
$anyPattern = "setup\.exe$"
}
$asset = Get-Asset $archPattern
if (-not $asset) { $asset = Get-Asset $anyPattern }
if (-not $asset) { throw "No matching $Type installer found in release $Version." }
$tmp = Join-Path $env:TEMP ("ioruba-" + [System.Guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $tmp | Out-Null
try {
$installerPath = Join-Path $tmp $asset.name
Write-Step "Downloading $($asset.name)"
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $installerPath
# Verify against SHA256SUMS.txt when the release ships one.
$sums = Get-Asset "SHA256SUMS\.txt$"
if ($sums) {
$sumsPath = Join-Path $tmp "SHA256SUMS.txt"
Invoke-WebRequest -Uri $sums.browser_download_url -OutFile $sumsPath
$line = Select-String -Path $sumsPath -Pattern ([regex]::Escape($asset.name)) | Select-Object -First 1
if ($line) {
$expected = ($line.Line -split '\s+')[0].ToLower()
$actual = (Get-FileHash -Path $installerPath -Algorithm SHA256).Hash.ToLower()
if ($expected -ne $actual) { throw "Checksum mismatch for $($asset.name)." }
Write-Step "Checksum verified for $($asset.name)."
} else {
Write-Warn "No checksum entry for $($asset.name); skipping."
}
} else {
Write-Warn "No SHA256SUMS.txt in this release; skipping checksum verification."
}
Write-Step "Running installer"
if ($Type -eq "msi") {
Start-Process msiexec.exe -ArgumentList "/i", "`"$installerPath`"", "/qb" -Wait
} else {
Start-Process $installerPath -Wait
}
Write-Host "✓ Ioruba installed." -ForegroundColor Green
} finally {
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
}