Skip to content

Commit 6359dee

Browse files
committed
feat(installer): auto-install bun and OpenSSL on Windows
1 parent 57a7ffa commit 6359dee

1 file changed

Lines changed: 69 additions & 11 deletions

File tree

install.ps1

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,71 @@ function Ensure-Path([string]$TargetDir) {
123123
}
124124
}
125125

126+
function Ensure-BunInstalled() {
127+
if (Test-Tool "bun") {
128+
$bunVersion = & bun --version
129+
Write-Pass "bun $bunVersion"
130+
return
131+
}
132+
133+
Write-WarnLine "bun not found. Installing via bun.sh..."
134+
$bunInstallCommand = 'irm bun.sh/install.ps1|iex'
135+
& powershell -NoProfile -ExecutionPolicy Bypass -Command $bunInstallCommand
136+
if ($LASTEXITCODE -ne 0) {
137+
Abort "Failed to install bun via bun.sh installer."
138+
}
139+
140+
foreach ($candidate in @((Join-Path $HOME ".bun\bin"), (Join-Path $env:USERPROFILE ".bun\bin"))) {
141+
if ($candidate -and (Test-Path $candidate)) {
142+
Ensure-Path $candidate
143+
}
144+
}
145+
146+
if (-not (Test-Tool "bun")) {
147+
Abort "bun installation completed but 'bun' is still not available in PATH."
148+
}
149+
150+
$bunVersion = & bun --version
151+
Write-Pass "bun $bunVersion"
152+
}
153+
154+
function Ensure-OpenSslInstalled() {
155+
$opensslBin = "C:\Program Files\OpenSSL-Win64\bin"
156+
if (Test-Tool "openssl") {
157+
Write-Pass "openssl installed"
158+
if (Test-Path $opensslBin) {
159+
Ensure-Path $opensslBin
160+
}
161+
return
162+
}
163+
164+
Write-WarnLine "openssl not found. Installing OpenSSL Light..."
165+
$url = "https://slproweb.com/download/Win64OpenSSL_Light-3_6_1.exe"
166+
$tmpExe = Join-Path $env:TEMP "Win64OpenSSL_Light-3_6_1.exe"
167+
try {
168+
Invoke-WebRequest -Uri $url -OutFile $tmpExe
169+
$proc = Start-Process -FilePath $tmpExe -ArgumentList "/verysilent", "/silent", "/sp-", "/norestart" -Wait -PassThru
170+
if ($proc.ExitCode -ne 0) {
171+
Abort "OpenSSL installer exited with code $($proc.ExitCode)."
172+
}
173+
}
174+
finally {
175+
if (Test-Path $tmpExe) {
176+
Remove-Item $tmpExe -Force -ErrorAction SilentlyContinue
177+
}
178+
}
179+
180+
if (Test-Path $opensslBin) {
181+
Ensure-Path $opensslBin
182+
}
183+
184+
if (-not (Test-Tool "openssl")) {
185+
Abort "OpenSSL installation completed but 'openssl' is still not available in PATH."
186+
}
187+
188+
Write-Pass "openssl installed"
189+
}
190+
126191
function Ensure-CommandViaWinget([string]$CommandName, [string]$WingetId, [string]$ManualHint) {
127192
if (Test-Tool $CommandName) {
128193
return
@@ -318,6 +383,9 @@ else {
318383
Write-WarnLine "winget not found (installer will not auto-install missing tools)."
319384
}
320385

386+
Ensure-BunInstalled
387+
Ensure-OpenSslInstalled
388+
321389
$hasGit = Test-Tool "git"
322390
$hasBun = Test-Tool "bun"
323391
$selectedMode = switch ($InstallMode) {
@@ -332,10 +400,6 @@ if ($selectedMode -eq "source") {
332400
if ($hasGit) {
333401
Write-Pass "git installed"
334402
}
335-
if ($hasBun) {
336-
$bunVersion = & bun --version
337-
Write-Pass "bun $bunVersion"
338-
}
339403
}
340404
else {
341405
if ($hasGit) {
@@ -345,13 +409,7 @@ else {
345409
Write-Host " git not required in release mode"
346410
}
347411

348-
if ($hasBun) {
349-
$bunVersion = & bun --version
350-
Write-Pass "bun $bunVersion (optional in release mode)"
351-
}
352-
else {
353-
Write-Host " bun not required in release mode"
354-
}
412+
Write-Pass "bun installed (optional in release mode)"
355413
}
356414

357415
Ensure-CommandViaWinget "codex" "OpenAI.Codex" "Install manually: https://github.com/openai/codex"

0 commit comments

Comments
 (0)