Skip to content

Commit

Permalink
* Disables Verbose progress during install and upgrade (chocolatey#175).
Browse files Browse the repository at this point in the history
Assigns $env:ChocolateyInstall from the System environment variable if $env:ChocolateyInstal is $null (chocolatey#174)
  • Loading branch information
Carpenter, Richard committed Jul 7, 2023
1 parent 210c34a commit 601e2cf
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,22 @@ function InstallPackage
if ($cParams) {
$chocoParams += " $cParams"
}
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
if ((Get-ChocoVersion) -ge [System.Version]('0.10.4')){
$chocoParams += " --no-progress"
}

$cmd = "choco install $pName $chocoParams"
Write-Verbose -Message "Install command: '$cmd'"
$packageInstallOuput = Invoke-Expression -Command $cmd
Write-Verbose -Message "Package output $packageInstallOuput"

$currentProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'

$packageInstallOutput = Invoke-Expression -Command $cmd

$ProgressPreference = $currentProgressPreference

Write-Verbose -Message "Package output $packageInstallOutput"

# Clear Package Cache
Get-ChocoInstalledPackage -Purge
Expand Down Expand Up @@ -319,7 +326,7 @@ function UninstallPackage
if ($pVersion) {
$chocoParams += " --version=`"$pVersion`""
}
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
if ((Get-ChocoVersion) -ge [System.Version]('0.10.4')){
$chocoParams += " --no-progress"
}
Expand All @@ -344,10 +351,10 @@ function IsPackageInstalled
param(
[Parameter(Position=0, Mandatory)]
[string]$pName,

[Parameter(ParameterSetName = 'RequiredVersion')]
[string]$pVersion,

[Parameter(ParameterSetName = 'MinimumVersion')]
[string]$pMinimumVersion
)
Expand Down Expand Up @@ -470,7 +477,7 @@ Function Upgrade-Package {
if ($cParams) {
$chocoParams += " $cParams"
}
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
if ((Get-ChocoVersion) -ge [System.Version]('0.10.4')){
$chocoParams += " --no-progress"
}
Expand All @@ -483,9 +490,14 @@ Function Upgrade-Package {
throw "$pName is not installed, you cannot upgrade"
}

$currentProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'

$packageUpgradeOuput = Invoke-Expression -Command $cmd
$packageUpgradeOuput | ForEach-Object { Write-Verbose -Message $_ }

$ProgressPreference = $currentProgressPreference

# Clear Package Cache
Get-ChocoInstalledPackage -Purge
}
Expand All @@ -497,6 +509,11 @@ function Get-ChocoInstalledPackage {
[switch]$NoCache
)

if ([string]::IsNullOrEmpty($env:ChocolateyInstall))
{
$env:ChocolateyInstall = [environment]::GetEnvironmentVariable('ChocolateyInstall', 'Machine')
}

$ChocoInstallLP = Join-Path -Path $env:ChocolateyInstall -ChildPath 'cache'
if ( -not (Test-Path $ChocoInstallLP)){
New-Item -Name 'cache' -Path $env:ChocolateyInstall -ItemType Directory | Out-Null
Expand Down Expand Up @@ -528,6 +545,11 @@ function Get-ChocoVersion {
[switch]$NoCache
)

if ([string]::IsNullOrEmpty($env:ChocolateyInstall))
{
$env:ChocolateyInstall = [environment]::GetEnvironmentVariable('ChocolateyInstall', 'Machine')
}

$chocoInstallCache = Join-Path -Path $env:ChocolateyInstall -ChildPath 'cache'
if ( -not (Test-Path $chocoInstallCache)){
New-Item -Name 'cache' -Path $env:ChocolateyInstall -ItemType Directory | Out-Null
Expand Down

0 comments on commit 601e2cf

Please sign in to comment.