Files
Medios-Macina/scripts/bootstrap.ps1
T

116 lines
3.7 KiB
PowerShell
Raw Normal View History

2026-07-10 21:17:41 -07:00
<#!
2025-12-23 16:36:39 -08:00
.SYNOPSIS
2026-07-10 21:17:41 -07:00
Bootstrap Medios-Macina on Windows.
2026-01-21 23:01:18 -08:00
.DESCRIPTION
2026-07-10 21:17:41 -07:00
When run from a checkout, this wrapper delegates to scripts/bootstrap.py. When
the script is piped from the web, it downloads the canonical Python bootstrap
to a temporary file so a checkout is not required first.
2026-01-21 23:01:18 -08:00
.EXAMPLE
2026-07-10 21:17:41 -07:00
irm "https://code.glowers.club/goyimnose/Medios-Macina/raw/branch/main/scripts/bootstrap.ps1" | iex
2026-01-21 23:01:18 -08:00
.EXAMPLE
2026-07-10 21:17:41 -07:00
.\scripts\bootstrap.ps1 -Editable -NoPlaywright
2026-01-21 23:01:18 -08:00
#>
param(
[switch]$Editable,
[switch]$CreateDesktopShortcut,
[switch]$CreateStartMenuShortcut,
2026-07-10 21:17:41 -07:00
[string]$VenvPath = "",
2026-01-21 23:01:18 -08:00
[string]$Python = "",
[switch]$Force,
[switch]$NoInstall,
2026-07-10 21:17:41 -07:00
[switch]$NoMpv,
[switch]$NoDeno,
2026-01-21 23:01:18 -08:00
[switch]$NoPlaywright,
[string]$PlaywrightBrowsers = "chromium",
[switch]$FixUrllib3,
[switch]$RemovePth,
2026-07-10 21:44:26 -07:00
[switch]$Quiet,
[switch]$NoPause
2026-01-21 23:01:18 -08:00
)
2026-07-10 21:17:41 -07:00
$ErrorActionPreference = "Stop"
$bootstrapUrl = "https://code.glowers.club/goyimnose/Medios-Macina/raw/branch/main/scripts/bootstrap.py"
$scriptPath = $MyInvocation.MyCommand.Path
$repoRoot = $null
$bootstrapPath = $null
$temporaryBootstrap = $false
2026-01-21 23:01:18 -08:00
2026-07-10 21:17:41 -07:00
if ($scriptPath) {
$scriptDir = Split-Path -Parent $scriptPath
$candidateRoot = (Resolve-Path (Join-Path $scriptDir "..")).Path
if ((Test-Path (Join-Path $candidateRoot "CLI.py")) -and (Test-Path (Join-Path $candidateRoot "scripts\bootstrap.py"))) {
$repoRoot = $candidateRoot
$bootstrapPath = Join-Path $repoRoot "scripts\bootstrap.py"
2026-01-21 23:01:18 -08:00
}
}
2026-07-10 21:17:41 -07:00
if (-not $bootstrapPath) {
$bootstrapPath = Join-Path ([IO.Path]::GetTempPath()) ("medios-macina-bootstrap-{0}.py" -f ([guid]::NewGuid()))
Invoke-WebRequest -Uri $bootstrapUrl -OutFile $bootstrapPath -UseBasicParsing
$temporaryBootstrap = $true
2025-12-24 23:31:05 -08:00
}
2026-07-10 21:17:41 -07:00
$pythonArgs = @()
if ($Editable) { $pythonArgs += "--install-editable" }
if ($NoInstall) { $pythonArgs += "--skip-deps" }
if ($NoMpv) { $pythonArgs += "--no-mpv" }
if ($NoDeno) { $pythonArgs += "--no-deno" }
if ($NoPlaywright) { $pythonArgs += "--no-playwright" }
if ($PlaywrightBrowsers) { $pythonArgs += @("--browsers", $PlaywrightBrowsers) }
if ($Quiet) { $pythonArgs += "--quiet" }
if ($Force) { $pythonArgs += "--yes" }
if ($VenvPath) {
Write-Warning "-VenvPath is handled by the Python bootstrap's repository-local .venv setting."
}
if ($CreateDesktopShortcut -or $CreateStartMenuShortcut -or $FixUrllib3 -or $RemovePth) {
Write-Warning "One or more legacy PowerShell-only options were ignored by the canonical Python bootstrap."
2025-12-24 23:31:05 -08:00
}
2025-12-23 16:36:39 -08:00
try {
2026-07-10 21:44:26 -07:00
$exitCode = 1
2026-07-10 21:17:41 -07:00
$pythonCommand = $null
if ($Python) {
$pythonCommand = $Python
} elseif (Get-Command py -ErrorAction SilentlyContinue) {
$pythonCommand = "py"
} elseif (Get-Command python -ErrorAction SilentlyContinue) {
$pythonCommand = "python"
}
2025-12-23 16:36:39 -08:00
2026-07-10 21:17:41 -07:00
if (-not $pythonCommand) {
throw "No Python 3 interpreter found. Install Python 3 and run the bootstrap again."
}
2025-12-23 16:36:39 -08:00
2026-07-10 21:17:41 -07:00
if ($pythonCommand -eq "py") {
& py -3 $bootstrapPath @pythonArgs
} else {
& $pythonCommand $bootstrapPath @pythonArgs
}
$exitCode = $LASTEXITCODE
2026-07-10 21:44:26 -07:00
if (-not $Quiet) {
if ($exitCode -eq 0) {
Write-Host "Installation finished successfully." -ForegroundColor Green
} else {
Write-Host "Installation exited with code $exitCode." -ForegroundColor Red
}
}
2026-07-10 21:17:41 -07:00
} finally {
if ($temporaryBootstrap -and (Test-Path $bootstrapPath)) {
Remove-Item -LiteralPath $bootstrapPath -Force -ErrorAction SilentlyContinue
}
2025-12-31 16:10:35 -08:00
}
2026-07-10 21:44:26 -07:00
if (-not $NoPause -and -not $Quiet -and [Environment]::UserInteractive) {
try {
[void](Read-Host "Press Enter to close installer")
} catch {
# Ignore host/input edge cases and continue to exit.
}
}
2026-07-10 21:17:41 -07:00
exit $exitCode