From 34d6ced7761e78024b5c709cccc7b04066aec041 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 7 Aug 2024 13:22:12 +0200 Subject: [PATCH] Add functions for installing `choco` and `winget` packages --- scripts/Windows/Scripts/Software.ps1 | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/scripts/Windows/Scripts/Software.ps1 b/scripts/Windows/Scripts/Software.ps1 index d90e99b6..f270c70d 100644 --- a/scripts/Windows/Scripts/Software.ps1 +++ b/scripts/Windows/Scripts/Software.ps1 @@ -4,8 +4,60 @@ . "$PSScriptRoot/../Types/InstallerAction.ps1"; $null = New-Module { + . "$PSScriptRoot/SoftwareManagement.ps1"; + . "$PSScriptRoot/../Types/InstallerAction.ps1"; $userArgument = "name"; + <# + .SYNOPSIS + Installs the specified packages using chocolatey. + + .PARAMETER Names + The names of the packages to install. + #> + function Install-ChocoPackage { + param( + [switch] $Force, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $Names + ) + + [System.Collections.ArrayList] $Names = $Names; + + if (-not ($Force.IsPresent)) { + for ($i = $Names.Count - 1; $i -ge 0; $i--) { + if (Test-ChocoPackage $Names[$i]) { + $Names.RemoveAt($i); + } + } + } + + if ($Names.Count -ge 1) { + choco install -y $Names; + } + } + + <# + .SYNOPSIS + Installs the specified packages using `winget`. + + .PARAMETER Names + The names of the packages to install. + #> + function Install-WingetPackage { + param( + [switch] $Force, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $Names + ) + + foreach ($name in $Names) { + if ($Force.IsPresent -and -not (Test-WingetPackage $name)) { + winget install --accept-source-agreements --accept-package-agreements -e --id $name; + } + } + } + function Start-SoftwareInstaller { param( [string] $Name,