Files
lxs/windows/apps/dev-pack.ps1
T

94 lines
3.4 KiB
PowerShell

<#
LXS - Dev Pack (Windows)
Description: The usual development toolchain, installed through winget.
Repo: https://git.hyko.cx/hykocx/lxs
#>
# Load LXS common library (colors, UI helpers, spinner, loggers, guards).
# Prefers the sibling ..\lib\common.ps1 (repo checkout or installed layout) and
# only hits the network when this script is run standalone.
$LxsRawBase = if ($env:LXS_RAW_BASE) { $env:LXS_RAW_BASE } else { 'https://git.hyko.cx/hykocx/lxs/raw/branch/main' }
if (-not $env:LXS_RAW_PLATFORM_BASE) { $env:LXS_RAW_PLATFORM_BASE = "$LxsRawBase/windows" }
$LxsLibPath = if ($PSScriptRoot) { Join-Path $PSScriptRoot '..\lib\common.ps1' } else { $null }
if ($LxsLibPath -and (Test-Path $LxsLibPath)) {
. $LxsLibPath
} else {
try {
$LxsLibSource = Invoke-RestMethod -Uri "$env:LXS_RAW_PLATFORM_BASE/lib/common.ps1" -UseBasicParsing -ErrorAction Stop
} catch {
Write-Error 'Failed to fetch lib/common.ps1'
exit 1
}
. ([scriptblock]::Create($LxsLibSource))
}
$env:LXS_LOG_FILE = Join-Path (Get-LxsTempDir) 'lxs_dev_pack.log'
if (-not (Assert-LxsWindows)) { exit 1 }
$LxsDevPackages = @(
@{ Name = 'Git'; Id = 'Git.Git' }
@{ Name = 'VS Code'; Id = 'Microsoft.VisualStudioCode' }
@{ Name = 'Node.js LTS'; Id = 'OpenJS.NodeJS.LTS' }
@{ Name = 'Python 3'; Id = 'Python.Python.3.12' }
@{ Name = 'PowerShell 7'; Id = 'Microsoft.PowerShell' }
@{ Name = 'Windows Terminal'; Id = 'Microsoft.WindowsTerminal' }
)
function Enable-LxsWsl {
Clear-Host
Show-LxsBoxTop -Title 'WSL 2'
Write-Host ''
Write-Host 'Installs the Windows Subsystem for Linux (WSL 2) and the default'
Write-Host 'Ubuntu distribution. Enables the Virtual Machine Platform feature,'
Write-Host "so a $($script:Bold)reboot is required$($script:NC) before WSL works."
Write-Host ''
if (-not (Confirm-LxsAction -Question 'Install WSL 2?')) {
Write-LxsInfo 'Cancelled.'
return
}
if (-not (Test-LxsAdmin)) {
Write-LxsErr 'Installing WSL requires administrator rights.'
Write-Host "$($script:Gray) Re-run lxs from an elevated terminal.$($script:NC)"
return
}
Write-Host ''
& wsl.exe --install
if ($LASTEXITCODE -eq 0) {
Write-LxsOk 'WSL install started'
Write-LxsWarn 'Reboot to finish, then run: wsl --install -d Ubuntu'
} else {
Write-LxsWarn "wsl --install exited with code $LASTEXITCODE"
}
}
function Show-LxsDevMenu {
while ($true) {
Clear-Host
Show-LxsBoxTop -Title 'DEV PACK'
Write-Host ''
Show-LxsMenuItem '1' 'Install dev tools' 'pick from the list'
Show-LxsMenuItem '2' 'Install WSL 2' 'needs admin + reboot'
Show-LxsMenuItem '0' 'Back' '' -Exit
Write-Host ''
Show-LxsBoxBottom
Write-Host ''
$choice = Read-LxsChoice
Write-Host ''
switch ($choice) {
'1' {
Invoke-LxsPackageMenu -Title 'DEV PACK' -Packages $LxsDevPackages `
-Note 'Everything here installs per-machine and lands on your PATH.' | Out-Null
Read-LxsEnter
}
'2' { Enable-LxsWsl; Read-LxsEnter }
'0' { return }
default { Write-LxsErr 'Invalid protocol. Select 0-2.'; Start-Sleep -Seconds 1 }
}
}
}
Show-LxsDevMenu
exit 75