Files

67 lines
2.4 KiB
PowerShell

<#
LXS - platform dispatcher (Windows side)
NOTE: this file must stay BOM-less and pure ASCII. It is the one script
fetched with `irm ... | iex`, and Invoke-Expression fails on a leading
U+FEFF. Being ASCII keeps it parseable when Windows PowerShell 5.1 falls
back to the ANSI codepage for a BOM-less file. Everything under windows\
carries a UTF-8 BOM instead, because 5.1 reads those from disk.
Thin shim kept at the repo root so the documented one-liner stays short and
stable while the real implementation lives in windows\lxs.ps1:
irm https://git.hyko.cx/hykocx/lxs/raw/branch/main/lxs.ps1 | iex
& ([scriptblock]::Create((irm https://git.hyko.cx/hykocx/lxs/raw/branch/main/lxs.ps1))) setup
Repo: https://git.hyko.cx/hykocx/lxs
License: MIT
#>
$LxsShimArgs = @($args)
$LxsRepoUrl = 'https://git.hyko.cx/hykocx/lxs'
$LxsBranch = if ($env:LXS_BRANCH) { $env:LXS_BRANCH } else { 'main' }
$LxsRawBase = if ($env:LXS_RAW_BASE) { $env:LXS_RAW_BASE } else { "$LxsRepoUrl/raw/branch/$LxsBranch" }
$LxsPlatformDir = 'windows'
# Running this shim under pwsh on Linux/macOS is a mistake worth catching.
if ($PSVersionTable.PSVersion.Major -ge 6 -and
-not [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform(
[System.Runtime.InteropServices.OSPlatform]::Windows)) {
Write-Error 'lxs.ps1 is the Windows entrypoint. On Linux or macOS, use lxs.sh instead.'
exit 1
}
# Locate a sibling windows\lxs.ps1 (repo checkout or installed layout).
$LxsSelfDir = $PSScriptRoot
if (-not $LxsSelfDir -and $MyInvocation.MyCommand.Path) {
$LxsSelfDir = Split-Path -Parent $MyInvocation.MyCommand.Path
}
if ($LxsSelfDir) {
$local = Join-Path $LxsSelfDir "$LxsPlatformDir\lxs.ps1"
if (Test-Path $local) {
& $local @LxsShimArgs
exit $LASTEXITCODE
}
}
# No files on disk - we were piped from irm. Fetch the platform entrypoint.
$temp = Join-Path $env:TEMP ("lxs.entrypoint.{0}.ps1" -f [guid]::NewGuid().ToString('N').Substring(0, 8))
try {
Invoke-WebRequest -Uri "$LxsRawBase/$LxsPlatformDir/lxs.ps1" -OutFile $temp `
-UseBasicParsing -Headers @{ 'Cache-Control' = 'no-cache' } -ErrorAction Stop
} catch {
Write-Error "lxs: failed to fetch $LxsRawBase/$LxsPlatformDir/lxs.ps1"
exit 1
}
try {
$global:LASTEXITCODE = 0
& $temp @LxsShimArgs
$code = $LASTEXITCODE
} finally {
Remove-Item $temp -Force -ErrorAction SilentlyContinue
}
exit $code