fix bootstrap

This commit is contained in:
Muzhen Gaming
2025-10-15 22:43:10 +08:00
parent cd600fd735
commit be07225cd1
3 changed files with 102 additions and 52 deletions

View File

@@ -32,10 +32,16 @@
**Shortest Pull-and-Run**
- Host the provided `bootstrap.ps1` (repo root) as raw text, then:
`iwr -useb https://your.domain/path/bootstrap.ps1 | iex`
- Simplest one-liner (no arguments needed):
`iwr -useb https://git.meoww.cc/admin/openai-code-script-poc/raw/branch/master/bootstrap.ps1 | iex`
- Optional one-liner with API key for this run only:
`powershell -NoProfile -ExecutionPolicy Bypass -Command "$env:OPENAI_API_KEY='sk-...'; iwr -useb https://your.domain/path/bootstrap.ps1 | iex"`
- Optional: set your API key inline for this run only:
`powershell -NoProfile -ExecutionPolicy Bypass -Command "$env:OPENAI_API_KEY='sk-...'; iwr -useb https://git.meoww.cc/admin/openai-code-script-poc/raw/branch/master/bootstrap.ps1 | iex"`
- Before hosting, open `bootstrap.ps1` and set either `$RepoUrl` (git clone) or `$ZipUrl` (download + expand). You can also pass `-ApiKey`, `-BaseUrl`, `-Dest`, and `-Force` when invoking.
- The original parameterized script (`bootstrap-old.ps1`) is intended to be run as a file (so the `param` block works). If you prefer that version, download then execute:
1) `iwr -useb https://git.meoww.cc/admin/openai-code-script-poc/raw/branch/master/bootstrap-old.ps1 -OutFile bootstrap.ps1`
2) `powershell -NoProfile -ExecutionPolicy Bypass -File .\bootstrap.ps1`
- Before hosting, open `bootstrap-old.ps1` if you need customization (`$RepoUrl`, `$ZipUrl`, etc.). The `bootstrap.ps1` uses the default ZIP URL and destination directory and is designed specifically for `iwr ... | iex` usage.
- bootstrap-old will probably will be removed in the future

71
bootstrap-old.ps1 Normal file
View File

@@ -0,0 +1,71 @@
$ErrorActionPreference = 'Stop'
[CmdletBinding()]
param(
[string] $ApiKey,
[string] $BaseUrl,
[string] $Dest = (Join-Path $env:USERPROFILE 'BgVisionAgent'),
[switch] $Force
)
# ---- Source configuration (edit these before hosting, or pass params) ----
$RepoUrl = '' # e.g. https://github.com/you/openai-code-script-poc.git
$ZipUrl = 'https://git.meoww.cc/admin/openai-code-script-poc/archive/master.zip' # e.g. https://your.domain/downloads/bgvisionagent.zip
$Branch = 'main' # used only for git
# -------------------------------------------------------------------------
function Have($name) { Get-Command $name -ErrorAction SilentlyContinue }
Write-Host "Bootstrap: preparing destination -> $Dest" -ForegroundColor Cyan
if (Test-Path $Dest) {
if ($Force) {
Write-Host "Removing existing destination (Force)..." -ForegroundColor DarkYellow
Remove-Item $Dest -Recurse -Force
}
}
if (!(Test-Path $Dest)) { New-Item -ItemType Directory -Path $Dest | Out-Null }
$root = $Dest
if ($ZipUrl) {
$zip = Join-Path $env:TEMP 'bgagent.zip'
Write-Host "Downloading ZIP from $ZipUrl ..." -ForegroundColor DarkCyan
iwr -useb $ZipUrl -OutFile $zip
Write-Host "Expanding archive to $Dest ..." -ForegroundColor DarkCyan
Expand-Archive $zip -DestinationPath $Dest -Force
# If the ZIP contains a single top-level folder, use it as root
$sub = Get-ChildItem $Dest | Where-Object { $_.PSIsContainer } | Select-Object -First 1
if ($sub) { $root = $sub.FullName }
}
elseif ($RepoUrl -and (Have 'git')) {
if (Test-Path (Join-Path $Dest '.git')) {
Write-Host "Updating existing git repo..." -ForegroundColor DarkCyan
Push-Location $Dest
git fetch --all --prune
git checkout $Branch 2>$null
git pull --ff-only
Pop-Location
} else {
Write-Host "Cloning $RepoUrl -> $Dest ..." -ForegroundColor DarkCyan
git clone --branch $Branch --depth 1 $RepoUrl $Dest
}
}
else {
Write-Host "No ZIP URL and git not available or RepoUrl empty. Nothing to fetch." -ForegroundColor Red
Write-Host "Edit bootstrap.ps1 to set $RepoUrl or $ZipUrl, or pass -Dest with files present." -ForegroundColor Yellow
}
# Optionally set env vars for this session (inherited by run.ps1 and pythonw)
if ($ApiKey) { $env:OPENAI_API_KEY = $ApiKey }
if ($BaseUrl) { $env:OPENAI_BASE_URL = $BaseUrl }
Set-Location $root
Write-Host "Invoking run.ps1 ..." -ForegroundColor Green
try {
& .\run.ps1
} catch {
Write-Host "run.ps1 failed to execute in-session. Retrying via Bypass..." -ForegroundColor DarkYellow
powershell -NoProfile -ExecutionPolicy Bypass -File .\run.ps1
}
Write-Host "Bootstrap completed." -ForegroundColor Green

View File

@@ -1,63 +1,35 @@
$ErrorActionPreference = 'Stop'
[CmdletBinding()]
param(
[string] $ApiKey,
[string] $BaseUrl,
[string] $Dest = (Join-Path $env:USERPROFILE 'BgVisionAgent'),
[switch] $Force
)
# Simple, IEX-safe bootstrapper (no param / CmdletBinding)
# Usage (copy/paste):
# iwr -useb https://git.meoww.cc/admin/openai-code-script-poc/raw/branch/master/bootstrap-lite.ps1 | iex
# Optional: set OPENAI_API_KEY in the same command before piping.
# ---- Source configuration (edit these before hosting, or pass params) ----
$RepoUrl = '' # e.g. https://github.com/you/openai-code-script-poc.git
$ZipUrl = 'https://git.meoww.cc/admin/openai-code-script-poc/archive/master.zip' # e.g. https://your.domain/downloads/bgvisionagent.zip
$Branch = 'main' # used only for git
# -------------------------------------------------------------------------
$ZipUrl = 'https://git.meoww.cc/admin/openai-code-script-poc/archive/master.zip'
$Dest = Join-Path $env:USERPROFILE 'BgVisionAgent'
$Force = ($env:BG_FORCE -eq '1' -or $env:BG_FORCE -eq 'true')
function Have($name) { Get-Command $name -ErrorAction SilentlyContinue }
Write-Host "Bootstrap: preparing destination -> $Dest" -ForegroundColor Cyan
Write-Host "Bootstrap (lite): preparing -> $Dest" -ForegroundColor Cyan
if (Test-Path $Dest) {
if ($Force) {
Write-Host "Removing existing destination (Force)..." -ForegroundColor DarkYellow
Write-Host "Removing existing destination (BG_FORCE=1)..." -ForegroundColor DarkYellow
Remove-Item $Dest -Recurse -Force
}
}
if (!(Test-Path $Dest)) { New-Item -ItemType Directory -Path $Dest | Out-Null }
$root = $Dest
$zip = Join-Path $env:TEMP 'bgagent.zip'
if ($ZipUrl) {
$zip = Join-Path $env:TEMP 'bgagent.zip'
Write-Host "Downloading ZIP from $ZipUrl ..." -ForegroundColor DarkCyan
iwr -useb $ZipUrl -OutFile $zip
Write-Host "Expanding archive to $Dest ..." -ForegroundColor DarkCyan
Expand-Archive $zip -DestinationPath $Dest -Force
# If the ZIP contains a single top-level folder, use it as root
$sub = Get-ChildItem $Dest | Where-Object { $_.PSIsContainer } | Select-Object -First 1
if ($sub) { $root = $sub.FullName }
}
elseif ($RepoUrl -and (Have 'git')) {
if (Test-Path (Join-Path $Dest '.git')) {
Write-Host "Updating existing git repo..." -ForegroundColor DarkCyan
Push-Location $Dest
git fetch --all --prune
git checkout $Branch 2>$null
git pull --ff-only
Pop-Location
} else {
Write-Host "Cloning $RepoUrl -> $Dest ..." -ForegroundColor DarkCyan
git clone --branch $Branch --depth 1 $RepoUrl $Dest
}
}
else {
Write-Host "No ZIP URL and git not available or RepoUrl empty. Nothing to fetch." -ForegroundColor Red
Write-Host "Edit bootstrap.ps1 to set $RepoUrl or $ZipUrl, or pass -Dest with files present." -ForegroundColor Yellow
}
Write-Host "Downloading ZIP from $ZipUrl ..." -ForegroundColor DarkCyan
iwr -useb $ZipUrl -OutFile $zip
# Optionally set env vars for this session (inherited by run.ps1 and pythonw)
if ($ApiKey) { $env:OPENAI_API_KEY = $ApiKey }
if ($BaseUrl) { $env:OPENAI_BASE_URL = $BaseUrl }
Write-Host "Expanding archive to $Dest ..." -ForegroundColor DarkCyan
Expand-Archive $zip -DestinationPath $Dest -Force
# If the ZIP contains a single top-level folder, use it as root
$sub = Get-ChildItem $Dest | Where-Object { $_.PSIsContainer } | Select-Object -First 1
if ($sub) { $root = $sub.FullName }
Set-Location $root
Write-Host "Invoking run.ps1 ..." -ForegroundColor Green
@@ -68,4 +40,5 @@ try {
powershell -NoProfile -ExecutionPolicy Bypass -File .\run.ps1
}
Write-Host "Bootstrap completed." -ForegroundColor Green
Write-Host "Bootstrap (lite) completed." -ForegroundColor Green