Skip to content

Commit

Permalink
The Source parameter is now correctly passed in to choco.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jark committed Jun 21, 2017
1 parent cad8c4d commit 3062507
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ function Set-TargetResource
Write-Verbose -Message "Uninstalling $Name due to version mis-match"
UninstallPackage -pName $Name -pParams $Params
Write-Verbose -Message "Re-Installing $Name with correct version $version"
InstallPackage -pName $Name -pParams $Params -pVersion $Version -cParams $chocoParams
InstallPackage -pName $Name -pParams $Params -pVersion $Version -pSource $Source -cParams $chocoParams
} elseif ($AutoUpgrade) {
Write-Verbose -Message "Upgrading $Name due to version mis-match"
Upgrade-Package -pName $Name -pParams $Params
Upgrade-Package -pName $Name -pParams $Params -pSource $Source
}
}
}
} else {
$whatIfShouldProcess = $pscmdlet.ShouldProcess("$Name", 'Install package from Chocolatey')
if ($whatIfShouldProcess) {
InstallPackage -pName $Name -pParams $Params -pVersion $Version -cParams $chocoParams
InstallPackage -pName $Name -pParams $Params -pVersion $Version -pSource $Source -cParams $chocoParams
}
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ function Test-TargetResource
Write-Verbose -Message "Checking if $Name is installed"

if ($AutoUpgrade -and $isInstalled) {
$result = Test-LatestVersionInstalled -pName $Name
$result = Test-LatestVersionInstalled -pName $Name -pSource $Source
} else {
$result = $isInstalled
}
Expand Down Expand Up @@ -204,6 +204,8 @@ function InstallPackage
[Parameter(Position=2)]
[string]$pVersion,
[Parameter(Position=3)]
[string]$pSource,
[Parameter(Position=4)]
[string]$cParams
)

Expand All @@ -216,6 +218,9 @@ function InstallPackage
if ($pVersion) {
$chocoinstallparams += " --version=`"$pVersion`""
}
if ($pSource) {
$chocoinstallparams += " --source=`"$pSource`""
}
if ($cParams) {
$chocoinstallparams += " $cParams"
}
Expand Down Expand Up @@ -251,14 +256,12 @@ function UninstallPackage
$packageUninstallOuput = choco uninstall $pName --params="$pParams" -y
}


Write-Verbose -Message "Package uninstall output $packageUninstallOuput "

#refresh path varaible in powershell, as choco doesn"t, to pull in git
$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine')
}


function IsPackageInstalled
{
param(
Expand Down Expand Up @@ -294,14 +297,23 @@ function IsPackageInstalled
Function Test-LatestVersionInstalled {
param(
[Parameter(Position=0,Mandatory)]
[string]$pName
[string]$pName,
[Parameter(Position=1,Mandatory)]
[string]$pSource
)
Write-Verbose -Message "Testing if $pName can be upgraded"

$queryres = choco upgrade $pName --noop | Select-String -Pattern $pName
$queryres | ForEach-Object {Write-Verbose -Message $_}
[string]$chocoupgradeparams = '--noop'
if ($pSource) {
$chocoupgradeparams += " --source=`"$pSource`""
}

Write-Verbose -Message "Testing if $pName can be upgraded: 'choco upgrade $pName $chocoupgradeparams'"

$packageUpgradeOuput = Invoke-Expression -Command "choco upgrade $pName $chocoupgradeparams"
$packageUpgradeOuput | ForEach-Object {Write-Verbose -Message $_}

if ($queryres -match "$pName.*is the latest version available based on your source") {
if ($packageUpgradeOuput -match "$pName.*is the latest version available based on your source") {
return $true
}
return $false
Expand Down Expand Up @@ -337,6 +349,8 @@ Function Upgrade-Package {
[Parameter(Position=1)]
[string]$pParams,
[Parameter(Position=2)]
[string]$pSource,
[Parameter(Position=3)]
[string]$cParams
)

Expand All @@ -347,10 +361,13 @@ Function Upgrade-Package {
if ($pParams) {
$chocoupgradeparams += " --params=`"$pParams`""
}
if ($pSource) {
$chocoupgradeparams += " --source=`"$pSource`""
}
if ($cParams) {
$chocoupgradeparams += " $cParams"
}
$cmd = "choco upgrade -dv -y $pName $chocoupgradeparams"
$cmd = "choco upgrade $pName $chocoupgradeparams"
Write-Verbose -Message "Upgrade command: '$cmd'"

if (-not (IsPackageInstalled -pName $pName))
Expand Down

0 comments on commit 3062507

Please sign in to comment.