Skip to content

Commit 5244d24

Browse files
committed
Fix install.ps1: replace exit 1 with throw, add archive name fallback, handle old binary rename
- Replace all exit 1 with throw (prevents terminal death via iex) - Try devbox_ archive first, fall back to devboxos_ for backward compatibility - Handle old devboxos.exe binary name by renaming to devbox.exe - Fix PATH advice line formatting
1 parent 646e8e5 commit 5244d24

1 file changed

Lines changed: 39 additions & 13 deletions

File tree

scripts/install.ps1

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,42 @@ if (-not $Version) {
4141
} catch {
4242
Write-Error "Failed to fetch latest version. Check your internet connection."
4343
Write-Error "You can set a specific version: `$env:DEVBOX_VERSION = 'v1.0.0'"
44-
exit 1
44+
throw "Failed to fetch latest version"
4545
}
4646
}
4747

4848
Write-Info "Installing DevBoxOS $Version"
4949

50-
$archiveName = "devbox_$($Version -replace '^v', '')_windows_$arch.zip"
51-
$downloadUrl = "https://github.com/$Repo/releases/download/$Version/$archiveName"
50+
$versionStr = $Version -replace '^v', ''
51+
$archiveNames = @(
52+
"devbox_${versionStr}_windows_${arch}.zip"
53+
"devboxos_${versionStr}_windows_${arch}.zip"
54+
)
55+
5256
$zipPath = "$env:TEMP\devbox_install.zip"
57+
$downloaded = $false
5358

54-
Write-Info "Downloading $archiveName ..."
55-
try {
56-
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -ErrorAction Stop
57-
} catch {
58-
Write-Error "Failed to download $downloadUrl"
59+
foreach ($name in $archiveNames) {
60+
$downloadUrl = "https://github.com/$Repo/releases/download/$Version/$name"
61+
Write-Info "Downloading $name ..."
62+
try {
63+
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -ErrorAction Stop
64+
$downloaded = $true
65+
break
66+
} catch {
67+
Write-Warn "Failed to download $name, trying next..."
68+
}
69+
}
70+
71+
if (-not $downloaded) {
72+
Write-Error "Failed to download from all archive names"
5973
Write-Error "Check available releases at https://github.com/$Repo/releases"
60-
exit 1
74+
throw "Download failed"
6175
}
6276

6377
if (-not (Test-Path $zipPath) -or (Get-Item $zipPath).Length -eq 0) {
6478
Write-Error "Downloaded file is empty or missing"
65-
exit 1
79+
throw "Downloaded file is empty"
6680
}
6781

6882
Write-Info "Installing to $InstallDir ..."
@@ -73,7 +87,7 @@ try {
7387
Expand-Archive -Path $zipPath -DestinationPath $InstallDir -Force
7488
} catch {
7589
Write-Error "Failed to extract archive: $_"
76-
exit 1
90+
throw "Extraction failed"
7791
}
7892

7993
Remove-Item -Path $zipPath -Force -ErrorAction SilentlyContinue
@@ -87,8 +101,20 @@ if ($currentPath -notlike "*$InstallDir*") {
87101
Write-Info "$InstallDir is already in PATH"
88102
}
89103

104+
# Handle old binary name (pre-rename releases had devboxos.exe)
90105
$cliPath = "$InstallDir\devbox.exe"
106+
if (-not (Test-Path $cliPath)) {
107+
$oldCli = "$InstallDir\devboxos.exe"
108+
if (Test-Path $oldCli) {
109+
Rename-Item -Path $oldCli -NewName "devbox.exe" -Force
110+
}
111+
}
112+
91113
$enginePath = "$InstallDir\devbox-engine.exe"
114+
$oldEngine = "$InstallDir\devboxos-engine.exe"
115+
if (-not (Test-Path $enginePath) -and (Test-Path $oldEngine)) {
116+
Rename-Item -Path $oldEngine -NewName "devbox-engine.exe" -Force
117+
}
92118

93119
if ((Test-Path $cliPath) -and (Test-Path $enginePath)) {
94120
Write-Info "DevBoxOS installed successfully!"
@@ -107,9 +133,9 @@ if ((Test-Path $cliPath) -and (Test-Path $enginePath)) {
107133
Write-Host " devbox doctor # Run diagnostics"
108134
Write-Host ""
109135
Write-Warn "Close and reopen your terminal, or run this to update PATH now:"
110-
Write-Host ' $env:Path = "'"$InstallDir"';$env:Path"'
136+
Write-Host " `$env:Path = `"$InstallDir;`$env:Path`""
111137
Write-Host ""
112138
} else {
113139
Write-Error "Installation failed - binaries not found in $InstallDir"
114-
exit 1
140+
throw "Installation failed"
115141
}

0 commit comments

Comments
 (0)