Skip to content

Commit

Permalink
Updated package installer to handle params and versions. Testing now.
Browse files Browse the repository at this point in the history
lawrencegripper committed May 27, 2015
1 parent 7fa5efa commit 80e7253
Showing 4 changed files with 62 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitIgnore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.mof
!*.schema.mof
59 changes: 52 additions & 7 deletions DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1
Original file line number Diff line number Diff line change
@@ -7,7 +7,15 @@ function Get-TargetResource
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name
$Name,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.String]
$Params,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.String]
$Version

)

@@ -19,6 +27,8 @@ function Get-TargetResource
#status of the configuration component
$Configuration = @{
Name = $Name
Params = $Params
Version = $Version
}

return $Configuration
@@ -32,15 +42,24 @@ function Set-TargetResource
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name
$Name,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.String]
$Params,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.String]
$Version

)
Write-Verbose "Start Set-TargetResource"

CheckChocoInstalled

if (-not (IsPackageInstalled $Name))
{
InstallPackage $Name
InstallPackage -pName $Name -pParams $Params -pVersion $Version
}
}

@@ -53,7 +72,15 @@ function Test-TargetResource
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name
$Name,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.String]
$Params,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.String]
$Version
)

Write-Verbose "Start Test-TargetResource"
@@ -80,12 +107,30 @@ function CheckChocoInstalled
function InstallPackage
{
param(
[Parameter(Position=0,Mandatory=1)][string]$pName
[Parameter(Position=0,Mandatory=1)][string]$pName,
[Parameter(Position=1,Mandatory=0)][string]$pParams,
[Parameter(Position=2,Mandatory=0)][string]$pVersion
)

$env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine')

$packageInstallOuput = choco install $pName -y

#Todo: Refactor
if ((-not ($pParams)) -and (-not $pVersion))
{
$packageInstallOuput = choco install $pName -y
}
elseif ($pParams -and $pVersion)
{
$packageInstallOuput = choco install $pName --params="$pParams" --version=$pVersion -y
}
elseif ($pParams)
{
$packageInstallOuput = choco install $pName --params="$pParams" -y
}
elseif ($pVersion)
{
$packageInstallOuput = choco install $pName --version=$pVersion -y
}

Write-Verbose "package output $packageInstallOuput "

Binary file modified DSCResources/cChocoPackageInstall/cChocoPackageInstall.schema.mof
Binary file not shown.
10 changes: 8 additions & 2 deletions ExampleConfig.ps1
Original file line number Diff line number Diff line change
@@ -14,7 +14,13 @@
}
cChocoPackageInstaller installChrome
{
Name = "google-chrome-x64"
Name = "googlechrome"
DependsOn = "[cChocoInstaller]installChoco"
}
cChocoPackageInstaller installAtomSpecificVersion
{
Name = "atom"
Version = "0.155.0"
DependsOn = "[cChocoInstaller]installChoco"
}

@@ -23,4 +29,4 @@

myChocoConfig

Start-DscConfiguration .\myChocoConfig -wait -Verbose
Start-DscConfiguration .\myChocoConfig -wait -Verbose -force

0 comments on commit 80e7253

Please sign in to comment.