-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall.ps1
More file actions
177 lines (157 loc) · 7.68 KB
/
Copy pathinstall.ps1
File metadata and controls
177 lines (157 loc) · 7.68 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
$ErrorActionPreference = "Stop"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$repo = "sewandev/Reverbic"
# Only add proxy parameters if Windows has one configured for this URL;
# passing -ProxyUseDefaultCredentials without -Proxy causes an error on networks without a proxy.
function Get-ProxyParams([string]$uri) {
$proxy = [System.Net.WebRequest]::GetSystemWebProxy().GetProxy([Uri]$uri)
if ($proxy -and $proxy.AbsoluteUri -ne $uri) {
return @{ Proxy = $proxy; ProxyUseDefaultCredentials = $true }
}
return @{}
}
Write-Host ""
Write-Host " =====================================" -ForegroundColor Cyan
Write-Host " Reverbic Installer " -ForegroundColor Cyan
Write-Host " =====================================" -ForegroundColor Cyan
Write-Host ""
# Any non-empty value in REVERBIC_PRERELEASE enables this mode
# (includes versions marked as pre-release on GitHub).
if ($env:REVERBIC_PRERELEASE) {
$releaseUrl = "https://api.github.com/repos/$repo/releases"
} else {
$releaseUrl = "https://api.github.com/repos/$repo/releases/latest"
}
Write-Host "[1/4] Looking for the latest version on GitHub..."
try {
$proxyParams = Get-ProxyParams $releaseUrl
$response = Invoke-RestMethod -Uri $releaseUrl -UseBasicParsing @proxyParams
} catch {
if ($_.Exception.Response -and $_.Exception.Response.StatusCode.value__ -eq 403) {
Write-Host ""
Write-Host "GitHub temporarily rate-limited anonymous requests from your network (HTTP 403)." -ForegroundColor Red
Write-Host "Try again in a few minutes or download Reverbic manually from:" -ForegroundColor Yellow
Write-Host " https://github.com/$repo/releases/latest" -ForegroundColor Cyan
} else {
Write-Host ""
Write-Host "Could not contact GitHub: $($_.Exception.Message)" -ForegroundColor Red
}
exit 1
}
$releaseData = if ($env:REVERBIC_PRERELEASE) { $response | Select-Object -First 1 } else { $response }
# PROCESSOR_ARCHITECTURE reflects the process architecture, not the system's:
# on 32-bit PowerShell running on 64-bit Windows, the real one is in PROCESSOR_ARCHITEW6432.
$architecture = $env:PROCESSOR_ARCHITECTURE
if ($env:PROCESSOR_ARCHITEW6432) {
$architecture = $env:PROCESSOR_ARCHITEW6432
}
# Only x86_64 binaries are published. On ARM64, the same binary is used via emulation.
switch ($architecture) {
"ARM64" { $patterns = @("aarch64-windows", "x86_64-windows") }
"AMD64" { $patterns = @("x86_64-windows") }
default {
Write-Host ""
Write-Host "Unsupported architecture: $architecture." -ForegroundColor Red
Write-Host "Reverbic requires 64-bit Windows (x86_64 or ARM64)." -ForegroundColor Yellow
exit 1
}
}
$asset = $null
foreach ($pattern in $patterns) {
$asset = $releaseData.assets | Where-Object { $_.name -match "$pattern\.exe$" } | Select-Object -First 1
if ($asset) { break }
}
if (-not $asset) {
Write-Host ""
Write-Host "Error: No release with a compatible Windows executable was found." -ForegroundColor Red
exit 1
}
$downloadUrl = $asset.browser_download_url
$fileName = $asset.name
$tempDir = [System.IO.Path]::GetTempPath()
$tempPath = Join-Path $tempDir $fileName
Write-Host "[2/4] Downloading $($releaseData.tag_name) ($fileName)..."
try {
$proxyParams = Get-ProxyParams $downloadUrl
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempPath -UseBasicParsing @proxyParams
} catch {
Write-Host ""
Write-Host "Download failed: $($_.Exception.Message)" -ForegroundColor Red
if ($_.Exception -is [System.IO.IOException]) {
Write-Host "If Reverbic is already open from a previous installation, close it (press 'q') and try again." -ForegroundColor Yellow
}
Remove-Item -Path $tempPath -Force -ErrorAction SilentlyContinue
exit 1
}
# By default the script aborts if the release asset has no SHA256 digest to check
# against. REVERBIC_SKIP_VERIFY is an explicit opt-in to run an unverified binary.
Write-Host "[3/4] Verifying integrity..."
try {
if ($asset.digest -and $asset.digest -match '^sha256:([0-9a-fA-F]{64})$') {
$expectedHash = $matches[1].ToLower()
$actualHash = (Get-FileHash -Path $tempPath -Algorithm SHA256).Hash.ToLower()
if ($actualHash -ne $expectedHash) {
Write-Host ""
Write-Host "SHA256 integrity verification failed." -ForegroundColor Red
Write-Host "The download may have been corrupted or tampered with. Installation aborted." -ForegroundColor Yellow
Remove-Item -Path $tempPath -Force -ErrorAction SilentlyContinue
exit 1
}
Write-Host " SHA256 hash verified successfully." -ForegroundColor DarkGray
} elseif ($env:REVERBIC_SKIP_VERIFY) {
Write-Host ""
Write-Host " Warning: the release does not include a SHA256 hash, and REVERBIC_SKIP_VERIFY is set." -ForegroundColor DarkYellow
Write-Host " Running the downloaded file WITHOUT integrity verification." -ForegroundColor DarkYellow
} else {
Write-Host ""
Write-Host "Error: the release asset does not include a SHA256 hash to verify." -ForegroundColor Red
Write-Host "Installation aborted for safety. To proceed at your own risk, set REVERBIC_SKIP_VERIFY=1 and try again." -ForegroundColor Yellow
Remove-Item -Path $tempPath -Force -ErrorAction SilentlyContinue
exit 1
}
} catch {
Write-Host ""
Write-Host "Could not verify the downloaded file: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Your antivirus may have quarantined or is blocking it." -ForegroundColor Yellow
Write-Host "Check Windows Defender or your antivirus and try again." -ForegroundColor Yellow
Remove-Item -Path $tempPath -Force -ErrorAction SilentlyContinue
exit 1
}
# Removes the "downloaded from the internet" mark from the already-verified binary to avoid
# the SmartScreen warning when launching it.
Unblock-File -Path $tempPath -ErrorAction SilentlyContinue
Write-Host "[4/4] Starting Reverbic..."
Write-Host ""
Write-Host "Reverbic will now open in this same terminal." -ForegroundColor Yellow
Write-Host "Press 'q' to exit and see the installation summary." -ForegroundColor Yellow
Write-Host ""
try {
$env:REVERBIC_INSTALLER = "1"
& $tempPath
} catch {
Remove-Item -Path $tempPath -Force -ErrorAction SilentlyContinue
Remove-Item -Path "Env:\REVERBIC_INSTALLER" -ErrorAction SilentlyContinue
Write-Host ""
Write-Host "Could not start Reverbic: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Your antivirus may have blocked the executable. Check Windows Defender" -ForegroundColor Yellow
Write-Host "or download it manually from: https://github.com/$repo/releases/latest" -ForegroundColor Yellow
exit 1
}
Remove-Item -Path $tempPath -Force -ErrorAction SilentlyContinue
Remove-Item -Path "Env:\REVERBIC_INSTALLER" -ErrorAction SilentlyContinue
# Only append Reverbic's install folder to this session's PATH, without overwriting
# other variables the current session might have (e.g. virtual environments).
if ($env:LOCALAPPDATA) {
$installDir = Join-Path $env:LOCALAPPDATA "Programs\reverbic"
if ($env:PATH -notlike "*$installDir*") {
$env:PATH += ";$installDir"
}
}
Write-Host ""
Write-Host "======================================================" -ForegroundColor Green
Write-Host "Installation completed successfully!" -ForegroundColor Green
Write-Host "======================================================" -ForegroundColor Green
Write-Host ""
Write-Host "Reverbic has been copied to your local folder and added to your PATH." -ForegroundColor Yellow
Write-Host "You can now type 'reverbic' from this or any other terminal." -ForegroundColor Yellow
Write-Host ""