Add functions for uninstalling packages
This commit is contained in:
parent
4292a3e847
commit
e806e0cb2a
1 changed files with 126 additions and 28 deletions
|
@ -9,6 +9,70 @@ $null = New-Module {
|
||||||
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
||||||
$userArgument = "name";
|
$userArgument = "name";
|
||||||
|
|
||||||
|
$chocoRunner = {
|
||||||
|
param(
|
||||||
|
[string] $Action = 'install',
|
||||||
|
[string[]] $ArgumentList,
|
||||||
|
[scriptblock] $Guard = { $true },
|
||||||
|
[Parameter(Position = 0)]
|
||||||
|
[string] $Name,
|
||||||
|
[Parameter(ValueFromRemainingArguments = $true)]
|
||||||
|
[string[]] $AdditionalNames = @()
|
||||||
|
)
|
||||||
|
|
||||||
|
[System.Collections.ArrayList] $Names = @();
|
||||||
|
$null = $Names.Add($Name);
|
||||||
|
$Names.AddRange($AdditionalNames);
|
||||||
|
|
||||||
|
if (-not ($Force.IsPresent)) {
|
||||||
|
for ($i = $Names.Count - 1; $i -ge 0; $i--) {
|
||||||
|
$name = $Names[$i];
|
||||||
|
|
||||||
|
if (-not (& $Guard $name)) {
|
||||||
|
$Names.RemoveAt($i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Names.Count -ge 1) {
|
||||||
|
choco $Action -y @ArgumentList @Names;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$wingetRunner = {
|
||||||
|
param(
|
||||||
|
[string] $Action = 'install',
|
||||||
|
[string[]] $ArgumentList,
|
||||||
|
[scriptblock] $Guard = { $true },
|
||||||
|
[Parameter(Position = 0)]
|
||||||
|
[string] $Name,
|
||||||
|
[Parameter(ValueFromRemainingArguments = $true)]
|
||||||
|
[string[]] $AdditionalNames = @()
|
||||||
|
)
|
||||||
|
|
||||||
|
[System.Collections.ArrayList] $Names = @();
|
||||||
|
$null = $Names.Add($Name);
|
||||||
|
$Names.AddRange($AdditionalNames);
|
||||||
|
|
||||||
|
[string[]] $arguments = $ArgumentList + (& {
|
||||||
|
if ($Action -eq 'install') {
|
||||||
|
@("--accept-package-agreements")
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach ($name in $Names) {
|
||||||
|
if ($Force.IsPresent -or (& $Guard $name $PSBoundParameters)) {
|
||||||
|
winget $Action `
|
||||||
|
--accept-source-agreements `
|
||||||
|
--source winget `
|
||||||
|
@arguments `
|
||||||
|
--exact --id $name ;
|
||||||
|
} else {
|
||||||
|
Write-Host "Package ``$name`` is already installed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Installs the specified packages using chocolatey.
|
Installs the specified packages using chocolatey.
|
||||||
|
@ -26,24 +90,39 @@ $null = New-Module {
|
||||||
[string[]] $AdditionalNames = @()
|
[string[]] $AdditionalNames = @()
|
||||||
)
|
)
|
||||||
|
|
||||||
[System.Collections.ArrayList] $Names = @();
|
& $chocoRunner @PSBoundParameters -Guard {
|
||||||
$null = $Names.Add($Name);
|
param($Name)
|
||||||
$Names.AddRange($AdditionalNames);
|
if (Test-ChocoPackage $Name) {
|
||||||
|
Write-Host "Package ``$Name`` is already installed"
|
||||||
if (-not ($Force.IsPresent)) {
|
$false;
|
||||||
for ($i = $Names.Count - 1; $i -ge 0; $i--) {
|
} else {
|
||||||
$name = $Names[$i];
|
$true;
|
||||||
|
|
||||||
if (Test-ChocoPackage $name) {
|
|
||||||
Write-Host "Package ``$name`` is already installed"
|
|
||||||
$Names.RemoveAt($i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if ($Names.Count -ge 1) {
|
<#
|
||||||
choco install -y @ArgumentList @Names;
|
.SYNOPSIS
|
||||||
}
|
Uninstalls the specified packages using chocolatey.
|
||||||
|
#>
|
||||||
|
function Uninstall-ChocoPackage {
|
||||||
|
param(
|
||||||
|
[string[]] $ArgumentList,
|
||||||
|
[Parameter(Position=0)]
|
||||||
|
[string] $Name,
|
||||||
|
[Parameter(ValueFromRemainingArguments = $true)]
|
||||||
|
[string[]] $AdditionalNames = @()
|
||||||
|
)
|
||||||
|
|
||||||
|
& $chocoRunner @PSBoundParameters -Action 'uninstall' -Guard {
|
||||||
|
param($Name)
|
||||||
|
if (Test-ChocoPackage $Name) {
|
||||||
|
$true;
|
||||||
|
} else {
|
||||||
|
Write-Host "Package ``$Name`` is not installed";
|
||||||
|
$false;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
<#
|
<#
|
||||||
|
@ -63,21 +142,40 @@ $null = New-Module {
|
||||||
[string[]] $AdditionalNames = @()
|
[string[]] $AdditionalNames = @()
|
||||||
)
|
)
|
||||||
|
|
||||||
[System.Collections.ArrayList] $Names = @();
|
& $wingetRunner @PSBoundParameters `
|
||||||
$null = $Names.Add($Name);
|
-Guard {
|
||||||
$Names.AddRange($AdditionalNames);
|
param($Name, $Parameters)
|
||||||
|
if (Test-WingetPackage -Name $Name @Parameters) {
|
||||||
|
Write-Host "Package ``$Name`` is already installed"
|
||||||
|
$false;
|
||||||
|
} else {
|
||||||
|
$true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($name in $Names) {
|
<#
|
||||||
if ($Force.IsPresent -or -not (Test-WingetPackage -Name $name @PSBoundParameters)) {
|
.SYNOPSIS
|
||||||
winget install `
|
Uninstalls the specified packages using `winget`.
|
||||||
--accept-source-agreements --accept-package-agreements `
|
#>
|
||||||
--source winget `
|
function Uninstall-WingetPackage {
|
||||||
$ArgumentList `
|
param(
|
||||||
--exact --id $name ;
|
[string[]] $ArgumentList,
|
||||||
|
[Parameter(Position=0)]
|
||||||
|
[string] $Name,
|
||||||
|
[Parameter(ValueFromRemainingArguments = $true)]
|
||||||
|
[string[]] $AdditionalNames = @()
|
||||||
|
)
|
||||||
|
|
||||||
|
& $wingetRunner @PSBoundParameters -Action 'uninstall' -Guard {
|
||||||
|
param($Name, $Parameters)
|
||||||
|
if (Test-WingetPackage -Name $Name @Parameters) {
|
||||||
|
$true;
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Package ``$name`` is already installed"
|
Write-Host "Package ``$Name`` is not installed"
|
||||||
|
$false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
<#
|
<#
|
||||||
|
|
Loading…
Reference in a new issue