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