mirror of
https://github.com/fscotto/infra.git
synced 2026-05-30 15:39:58 +00:00
Support user-scoped winget installs on Windows
This commit is contained in:
@@ -124,13 +124,28 @@
|
||||
script: |
|
||||
$packageId = '{{ item.id }}'
|
||||
$packageName = '{{ item.name | default(item.id) }}'
|
||||
$packageScope = '{{ item.scope | default('' ) }}'
|
||||
$installArgs = @(
|
||||
'install'
|
||||
'--id', $packageId
|
||||
'--exact'
|
||||
'--silent'
|
||||
'--accept-package-agreements'
|
||||
'--accept-source-agreements'
|
||||
'--disable-interactivity'
|
||||
)
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace($packageScope)) {
|
||||
$installArgs += @('--scope', $packageScope)
|
||||
}
|
||||
|
||||
$installed = & winget list --id $packageId --exact --accept-source-agreements --disable-interactivity 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $installed -match [regex]::Escape($packageId)) {
|
||||
$Ansible.Changed = $false
|
||||
return
|
||||
}
|
||||
|
||||
& winget install --id $packageId --exact --silent --accept-package-agreements --accept-source-agreements --disable-interactivity
|
||||
& winget @installArgs
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Failed to install $packageName with winget"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user