-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
59 lines (56 loc) · 2.59 KB
/
Copy pathbootstrap.ps1
File metadata and controls
59 lines (56 loc) · 2.59 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
# KAMP-K2 bootstrap -- iex-compatible entrypoint.
#
# `install.ps1` declares [CmdletBinding()] + param(), which PowerShell only
# accepts at the top of a script FILE. `Invoke-Expression` can't parse those
# constructs in an expression block, so piping install.ps1 through iex fails
# with "Unexpected attribute 'CmdletBinding'".
#
# This bootstrap is flat top-level code (no param block, no CmdletBinding),
# so `iwr | iex` works. It downloads install.ps1 to a temp file and runs it
# as a real script.
#
# One-liner for users:
#
# iwr -useb https://raw.githubusercontent.com/grant0013/KAMP-K2/main/bootstrap.ps1 | iex
$InstallUrl = "https://raw.githubusercontent.com/grant0013/KAMP-K2/main/install.ps1"
$TargetPath = Join-Path $env:TEMP "kamp-k2-install.ps1"
Write-Host ""
Write-Host "[*] Downloading KAMP-K2 installer..." -ForegroundColor Cyan
try {
Invoke-WebRequest -UseBasicParsing -Uri $InstallUrl -OutFile $TargetPath -ErrorAction Stop
} catch {
Write-Host "[x] Download failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Check your internet connection or open an issue:" -ForegroundColor Yellow
Write-Host " https://github.com/grant0013/KAMP-K2/issues" -ForegroundColor Yellow
exit 1
}
Write-Host "[+] Saved to $TargetPath" -ForegroundColor Green
Write-Host "[*] Launching installer..." -ForegroundColor Cyan
Write-Host ""
# Relaunch install.ps1 as a real script so its param() block and
# [CmdletBinding()] are honoured. Wrap in try/catch so ANY error surfaces
# to the user -- silent exits were a real reported issue.
#
# NOTE: we deliberately do NOT call `exit` here. bootstrap.ps1 is typically
# run via `iwr | iex`, which evaluates the script in the CURRENT shell scope.
# A top-level `exit` would close the user's PowerShell window instantly --
# swallowing any "Done!" or error text they'd need to read. install.ps1
# handles its own success/failure pause. Returning normally from iex just
# drops the user back at the PS prompt.
try {
& $TargetPath
} catch {
Write-Host ""
Write-Host "[x] Installer crashed with an error:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host ""
Write-Host "Script location: $TargetPath" -ForegroundColor Yellow
Write-Host "Stack trace:" -ForegroundColor Yellow
Write-Host $_.ScriptStackTrace -ForegroundColor Yellow
Write-Host ""
Write-Host "Paste the above into a GitHub issue:" -ForegroundColor Yellow
Write-Host " https://github.com/grant0013/KAMP-K2/issues" -ForegroundColor Yellow
Write-Host ""
Write-Host "Press Enter to close." -ForegroundColor Gray
$null = Read-Host
}