php-devops/scripts/install-core.ps1
unknown 86a80ec2e1
fix: Windows compatibility for install scripts
- Use Join-Path for reliable path handling in PowerShell
- Replace fragile New-TemporaryFile with GetTempPath + GUID
- Enable delayed expansion in batch for reliable errorlevel checks
- Add call statements for proper subprocess error propagation
- Verify core.exe exists before running commands
- Update repo reference and build path

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 00:00:23 +11:00

100 lines
3 KiB
PowerShell

# Install the Core CLI (Windows)
# Run: .\scripts\install-core.ps1
$ErrorActionPreference = "Stop"
$Repo = "host-uk/core"
$InstallDir = "$env:LOCALAPPDATA\Programs\core"
function Write-Info { Write-Host "[INFO] $args" -ForegroundColor Green }
function Write-Warn { Write-Host "[WARN] $args" -ForegroundColor Yellow }
function Write-Err { Write-Host "[ERROR] $args" -ForegroundColor Red; exit 1 }
function Test-Command($cmd) {
return [bool](Get-Command $cmd -ErrorAction SilentlyContinue)
}
# Download pre-built binary
function Download-Binary {
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
$url = "https://github.com/$Repo/releases/download/dev/core-windows-$arch.exe"
Write-Info "Attempting to download pre-built binary..."
Write-Info "URL: $url"
try {
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
Invoke-WebRequest -Uri $url -OutFile "$InstallDir\core.exe" -UseBasicParsing
Write-Info "Downloaded to $InstallDir\core.exe"
return $true
} catch {
Write-Warn "No pre-built binary available, will build from source"
return $false
}
}
# Build from source
function Build-FromSource {
if (-not (Test-Command go)) {
Write-Err "Go is required to build from source. Run '.\scripts\install-deps.ps1' first"
}
$tmpdir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Force -Path $tmpdir | Out-Null
Write-Info "Cloning $Repo..."
$cloneDir = Join-Path $tmpdir "Core"
git clone --depth 1 "https://github.com/$Repo.git" $cloneDir
Write-Info "Building core CLI..."
Push-Location $cloneDir
go build -o core.exe .
Pop-Location
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
Move-Item (Join-Path $cloneDir "core.exe") (Join-Path $InstallDir "core.exe") -Force
Remove-Item -Recurse -Force $tmpdir
Write-Info "Built and installed to $InstallDir\core.exe"
}
# Add to PATH
function Setup-Path {
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -notlike "*$InstallDir*") {
Write-Info "Adding $InstallDir to PATH..."
[Environment]::SetEnvironmentVariable("PATH", "$userPath;$InstallDir", "User")
$env:PATH = "$env:PATH;$InstallDir"
}
}
# Verify installation
function Verify {
Setup-Path
if (Test-Command core) {
Write-Info "Verifying installation..."
& core --help | Select-Object -First 5
Write-Host ""
Write-Info "core CLI installed successfully!"
} elseif (Test-Path "$InstallDir\core.exe") {
Write-Info "core CLI installed to $InstallDir\core.exe"
Write-Info "Restart your terminal to use 'core' command"
} else {
Write-Err "Installation failed"
}
}
# Main
function Main {
Write-Info "Installing Core CLI..."
# Try download first, fallback to build
if (-not (Download-Binary)) {
Build-FromSource
}
Verify
}
Main