dotfiles/util/winget.psm1

40 lines
1.3 KiB
PowerShell
Raw Normal View History

2024-11-24 20:14:10 +00:00
function InstallWinget
{
2024-11-25 10:35:19 +00:00
$progressPreference = 'silentlyContinue'
$download = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
$setup = "$env:TMP\winget_setup.msixbundle"
if (-not (Test-Path $setup))
{
$releases = Invoke-RestMethod $download
$assets = $releases | Select-Object -ExpandProperty "assets"
$installer = $assets | Where-Object "name" -Match "msixbundle"
$url = $installer | Select-Object -ExpandProperty "browser_download_url"
2024-11-25 10:35:19 +00:00
Write-Host "Downloading WinGet '.msixbundle' installer ..."
Invoke-WebRequest $url -OutFile $setup
}
2024-11-25 10:35:19 +00:00
Write-Host "Installing WinGet app package ..."
Add-AppxPackage -Path $setup
2024-11-24 20:14:10 +00:00
}
function WingetInstall
{
$update = Read-Host "Install/Update WinGet now? [Y/n]"
if ($update.ToLower() -ne 'n')
{
# Start admin process, import this script, run 'InstallPackages' function
Start-Process powershell.exe -Verb RunAs -Wait `
-ArgumentList "-ExecutionPolicy", "Bypass", `
"-C", "cd $pwd; ipmo ./util/winget.psm1; InstallWinget"
2024-11-24 20:14:10 +00:00
}
$install = Read-Host "Install WinGet Packages now? [Y/n]"
if ($install.ToLower() -eq 'n')
{ return
}
2024-11-24 20:14:10 +00:00
winget.exe install -s winget --accept-source-agreements (Get-Content ./util/winget.list)
}