fix(install): do not kill PowerShell host under 'irm | iex'
The Windows installer used 'exit' inside Install-Octopus. When run via
'irm <url> | iex' (the documented one-liner), there is no script scope, so
'exit' terminates the entire PowerShell host process and closes the terminal
window instead of just ending the install. Most users hit this via the
'already installed' branch (exit 0).
Replace 'exit' with:
- 'return' for the success (already-installed) path
- 'throw' for error paths (still non-zero exit when run as .\install.ps1
in CI; prints the error and returns to the prompt under iex)
Add tests/test.ps1 as a regression guard (source-verification + a behavioral
test proving iex no longer terminates the host).
This commit is contained in:
+5
-11
@@ -96,16 +96,13 @@ function Install-Octopus {
|
||||
try {
|
||||
$null = Invoke-WebRequest -Uri $releaseUrl -Method Head -UseBasicParsing -ErrorAction Stop
|
||||
} catch {
|
||||
Write-Color "Error: Release v$specificVersion not found." "Red"
|
||||
Write-Color "Available releases: $baseUrl/$REPO/releases" "DarkGray"
|
||||
exit 1
|
||||
throw "Release v$specificVersion not found. Available releases: $baseUrl/$REPO/releases"
|
||||
}
|
||||
} else {
|
||||
Write-Color "Fetching latest version..." "DarkGray"
|
||||
$specificVersion = Get-LatestVersion
|
||||
if (-not $specificVersion) {
|
||||
Write-Color "Error: Failed to fetch latest version." "Red"
|
||||
exit 1
|
||||
throw "Failed to fetch latest version."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +113,7 @@ function Install-Octopus {
|
||||
$installedVersion = & $existing --version 2>$null
|
||||
if ($installedVersion -eq $specificVersion) {
|
||||
Write-Color "Version $specificVersion already installed." "DarkGray"
|
||||
exit 0
|
||||
return
|
||||
} else {
|
||||
Write-Color "Installed version: $installedVersion" "DarkGray"
|
||||
}
|
||||
@@ -144,10 +141,8 @@ function Install-Octopus {
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
|
||||
} catch {
|
||||
Write-Color "Error: Failed to download $downloadUrl" "Red"
|
||||
Write-Color $_.Exception.Message "Red"
|
||||
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
||||
exit 1
|
||||
throw "Failed to download $downloadUrl : $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
# Extract
|
||||
@@ -157,9 +152,8 @@ function Install-Octopus {
|
||||
New-Item -ItemType Directory -Path $INSTALL_DIR -Force | Out-Null
|
||||
$exeSrc = Join-Path $tmpDir "$APP.exe"
|
||||
if (-not (Test-Path $exeSrc)) {
|
||||
Write-Color "Error: $APP.exe not found in archive." "Red"
|
||||
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
||||
exit 1
|
||||
throw "$APP.exe not found in archive."
|
||||
}
|
||||
Copy-Item -Path $exeSrc -Destination (Join-Path $INSTALL_DIR "$APP.exe") -Force
|
||||
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
|
||||
|
||||
Reference in New Issue
Block a user