forked from wowemulation-dev/warcraft-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
243 lines (201 loc) · 7.44 KB
/
install.ps1
File metadata and controls
243 lines (201 loc) · 7.44 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env pwsh
# Install script for warcraft-rs with ephemeral key verification
param(
[string]$Version = "",
[string]$InstallDir = "$env:LOCALAPPDATA\Programs\warcraft-rs",
[switch]$Help
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
$BinaryName = "warcraft-rs"
$Repo = "wowemulation-dev/warcraft-rs"
$BaseUrl = "https://github.com/$Repo/releases"
function Write-Info {
param($Message)
Write-Host "[INFO] " -ForegroundColor Green -NoNewline
Write-Host $Message
}
function Write-Warn {
param($Message)
Write-Host "[WARN] " -ForegroundColor Yellow -NoNewline
Write-Host $Message
}
function Write-Error-And-Exit {
param($Message)
Write-Host "[ERROR] " -ForegroundColor Red -NoNewline
Write-Host $Message
exit 1
}
function Get-LatestVersion {
try {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
$version = $release.tag_name -replace 'warcraft-rs-v', ''
return $version
} catch {
Write-Error-And-Exit "Failed to get latest version: $_"
}
}
function Get-Platform {
$arch = [System.Environment]::Is64BitOperatingSystem
if ($arch) {
$platform = "x86_64-pc-windows-msvc"
} else {
Write-Error-And-Exit "32-bit Windows is not supported"
}
# Check for ARM64
$processorArch = $env:PROCESSOR_ARCHITECTURE
if ($processorArch -eq "ARM64") {
$platform = "aarch64-pc-windows-msvc"
}
return $platform
}
function Download-File {
param(
[string]$Url,
[string]$OutFile
)
try {
Write-Info "Downloading from $Url"
Invoke-WebRequest -Uri $Url -OutFile $OutFile -UseBasicParsing
} catch {
if ($_.Exception.Response.StatusCode -eq 404) {
return $false
}
Write-Error-And-Exit "Failed to download: $_"
}
return $true
}
function Verify-Signature {
param(
[string]$File,
[string]$PublicKeyFile
)
# Check for rsign or minisign
$rsign = Get-Command rsign -ErrorAction SilentlyContinue
$minisign = Get-Command minisign -ErrorAction SilentlyContinue
if ($rsign) {
Write-Info "Verifying signature with rsign..."
$result = & rsign verify -p $PublicKeyFile $File 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-And-Exit "Signature verification failed: $result"
}
Write-Info "Signature verification successful"
} elseif ($minisign) {
Write-Info "Verifying signature with minisign..."
$result = & minisign -V -p $PublicKeyFile -m $File 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-And-Exit "Signature verification failed: $result"
}
Write-Info "Signature verification successful"
} else {
Write-Warn "Neither rsign nor minisign found, skipping verification"
Write-Warn "Install from: https://github.com/jedisct1/minisign/releases"
Write-Warn "Or install rsign with: cargo install rsign2"
}
}
function Install-WarcraftRS {
param(
[string]$Version,
[string]$InstallDir
)
# Get version if not specified
if ([string]::IsNullOrEmpty($Version)) {
Write-Info "Fetching latest version..."
$Version = Get-LatestVersion
}
Write-Info "Installing warcraft-rs v$Version"
# Detect platform
$platform = Get-Platform
Write-Info "Detected platform: $platform"
# Create temp directory
$tempDir = New-TemporaryFile | ForEach-Object { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
try {
# Download files
$fileName = "$BinaryName-$Version-$platform.zip"
$downloadUrl = "$BaseUrl/download/warcraft-rs-v$Version/$fileName"
$zipFile = Join-Path $tempDir $fileName
$sigFile = "$zipFile.sig"
$pubKeyFile = Join-Path $tempDir "minisign.pub"
if (-not (Download-File -Url $downloadUrl -OutFile $zipFile)) {
Write-Error-And-Exit "Failed to download binary"
}
# Download signature (ephemeral signing uses .sig extension)
$sigDownloaded = Download-File -Url "$downloadUrl.sig" -OutFile $sigFile
# Download public key (per-release ephemeral key)
$pubKeyDownloaded = Download-File -Url "$BaseUrl/download/warcraft-rs-v$Version/minisign.pub" -OutFile $pubKeyFile
# Verify signature if available
if ($sigDownloaded -and $pubKeyDownloaded -and (Test-Path $sigFile) -and (Test-Path $pubKeyFile)) {
Verify-Signature -File $zipFile -PublicKeyFile $pubKeyFile
} else {
Write-Warn "Signature or public key file not found, proceeding without verification"
}
# Extract binary
Write-Info "Extracting binary..."
Expand-Archive -Path $zipFile -DestinationPath $tempDir -Force
# Create install directory
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
# Install binary
$binaryName = "$BinaryName.exe"
$sourcePath = Join-Path $tempDir $binaryName
$destPath = Join-Path $InstallDir $binaryName
if (Test-Path $sourcePath) {
Write-Info "Installing to $destPath"
Copy-Item -Path $sourcePath -Destination $destPath -Force
} else {
Write-Error-And-Exit "Binary not found in archive"
}
# Verify installation
try {
$testOutput = & $destPath --version 2>&1
Write-Info "Installation successful!"
Write-Info "Binary installed to: $destPath"
Write-Info "Version: $testOutput"
} catch {
Write-Error-And-Exit "Installation verification failed"
}
# Check PATH
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$InstallDir*") {
Write-Warn "$InstallDir is not in your PATH"
Write-Info "To add it to PATH, run:"
Write-Host ' [Environment]::SetEnvironmentVariable("Path", $env:Path + ";' + $InstallDir + '", "User")'
Write-Info "Or restart your terminal after running:"
Write-Host " setx PATH `"%PATH%;$InstallDir`""
} else {
Write-Info "$BinaryName is available in your PATH"
}
} finally {
# Cleanup
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
# Main
if ($Help) {
Write-Host @"
Install script for warcraft-rs
USAGE:
install.ps1 [-Version <version>] [-InstallDir <path>] [-Help]
OPTIONS:
-Version Install specific version (default: latest)
-InstallDir Installation directory (default: $env:LOCALAPPDATA\Programs\warcraft-rs)
-Help Show this help message
EXAMPLES:
# Install latest version
.\install.ps1
# Install specific version
.\install.ps1 -Version 0.1.0
# Install to custom directory
.\install.ps1 -InstallDir C:\Tools\warcraft-rs
SIGNATURE VERIFICATION:
This script verifies ephemeral signatures when minisign or rsign is available.
Each release is signed with a unique ephemeral key for security.
To install minisign:
- Download from: https://github.com/jedisct1/minisign/releases
To install rsign:
- Run: cargo install rsign2
"@
exit 0
}
Install-WarcraftRS -Version $Version -InstallDir $InstallDir