1414 # The credential necessary to access the internal Nexus repository. This can
1515 # be ignored if Anonymous authentication is enabled.
1616 # This parameter will be necessary if your C4B server is web-enabled.
17- [Parameter ()]
17+ [Parameter (Mandatory )]
1818 [pscredential ]
19- $Credential ,
19+ $RepositoryCredential ,
2020
2121 # Specifies a target version of Chocolatey to install. By default, the
2222 # latest stable version is installed.
@@ -43,17 +43,41 @@ param(
4343 # value in the Chocolatey config file
4444 [Parameter ()]
4545 [string ]
46- $ClientSalt ,
46+ $ClientCommunicationSalt ,
4747
4848 # Server salt value used to populate the centralManagementServiceCommunicationSaltAdditivePassword
4949 # value in the Chocolatey config file
5050 [Parameter ()]
5151 [string ]
52- $ServiceSalt ,
52+ $ServiceCommunicationSalt ,
5353
54+ # Install the Chocolatey Licensed Extension with right-click context menus available
5455 [Parameter ()]
5556 [Switch ]
56- $InternetEnabled
57+ $IncludePackageTools ,
58+
59+ # Allows for the application of user-defined configuration that is applied after the base configuration.
60+ # Can override base configuration with this parameter
61+ [Parameter ()]
62+ [Hashtable ]
63+ $AdditionalConfiguration ,
64+
65+ # Allows for the toggling of additonal features that is applied after the base configuration.
66+ # Can override base configuration with this parameter
67+ [Parameter ()]
68+ [Hashtable ]
69+ $AdditionalFeatures ,
70+
71+ # Allows for the installation of additional packages after the system base packages have been installed.
72+ [Parameter ()]
73+ [Hashtable []]
74+ $AdditionalPackages ,
75+
76+ # Allows for the addition of alternative sources after the base conifguration has been applied.
77+ # Can override base configuration with this parameter
78+ [Parameter ()]
79+ [Hashtable []]
80+ $AdditionalSources
5781)
5882
5983Set-ExecutionPolicy Bypass - Scope Process - Force
@@ -69,25 +93,29 @@ $params = @{
6993
7094if (-not $IgnoreProxy ) {
7195 if ($ProxyUrl ) {
96+ $proxy = [System.Net.WebProxy ]::new($ProxyUrl , $true <# bypass on local#> )
7297 $params.Add (' ProxyUrl' , $ProxyUrl )
7398 }
7499
75100 if ($ProxyCredential ) {
76101 $params.Add (' ProxyCredential' , $ProxyCredential )
102+ $proxy.Credentials = $ProxyCredential
103+
77104 }
78105}
79106
80107$webClient = New-Object System.Net.WebClient
81- if ($Credential ) {
82- $webClient.Credentials = $Credential .GetNetworkCredential ()
108+ if ($RepositoryCredential ) {
109+ $webClient.Credentials = $RepositoryCredential .GetNetworkCredential ()
83110}
84111
85112# Find the latest version of Chocolatey, if a version was not specified
86113$NupkgUrl = if (-not $ChocolateyVersion ) {
87114 $QueryUrl = ($RepositoryUrl.TrimEnd (' /index.json' ), " v3/registration/Chocolatey/index.json" ) -join ' /'
88115 $Result = $webClient.DownloadString ($QueryUrl ) | ConvertFrom-Json
89116 $Result.items.items [-1 ].packageContent
90- } else {
117+ }
118+ else {
91119 # Otherwise, assume the URL
92120 " $ ( $RepositoryUrl.TrimEnd (' /index.json' )) /v3/content/chocolatey/$ ( $ChocolateyVersion ) /chocolatey.$ ( $ChocolateyVersion ) .nupkg"
93121}
@@ -118,18 +146,19 @@ choco config set commandExecutionTimeoutSeconds 14400
118146# Nexus NuGet V3 Compatibility
119147choco feature disable -- name= " 'usePackageRepositoryOptimizations'"
120148
121- if ($InternetEnabled ) {
122- choco source add -- name= " 'ChocolateyInternal'" -- source= " '$RepositoryUrl '" -- allow- self- service -- user= " '$ ( $Credential.UserName ) '" -- password= " '$ ( $Credential.GetNetworkCredential ().Password) '" -- priority= 1
123- }
124- else {
125- choco source add -- name= " 'ChocolateyInternal'" -- source= " '$RepositoryUrl '" -- allow- self- service -- priority= 1
126- }
127-
149+ # Environment base Source configuration
150+ choco source add -- name= " 'ChocolateyInternal'" -- source= " '$RepositoryUrl '" -- allow- self- service -- user= " '$ ( $RepositoryCredential.UserName ) '" -- password= " '$ ( $RepositoryCredential.GetNetworkCredential ().Password) '" -- priority= 1
128151choco source disable -- name= " 'Chocolatey'"
129152choco source disable -- name= " 'chocolatey.licensed'"
130153
131154choco upgrade chocolatey- license - y -- source= " 'ChocolateyInternal'"
132- choco upgrade chocolatey.extension - y -- params= " '/NoContextMenu'" -- source= " 'ChocolateyInternal'" -- no- progress
155+ if (-not $IncludePackageTools ) {
156+ choco upgrade chocolatey.extension - y -- params= " '/NoContextMenu'" -- source= " 'ChocolateyInternal'" -- no- progress
157+ }
158+ else {
159+ Write-Warning " IncludePackageTools was passed. Right-Click context menus will be available for installers, .nupkg, and .nuspec file types!"
160+ choco upgrade chocolatey.extension - y -- source= " 'ChocolateyInternal'" -- no- progress
161+ }
133162choco upgrade chocolateygui - y -- source= " 'ChocolateyInternal'" -- no- progress
134163choco upgrade chocolateygui.extension - y -- source= " 'ChocolateyInternal'" -- no- progress
135164
@@ -158,3 +187,129 @@ if ($ServiceSalt) {
158187}
159188choco feature enable -- name= " 'useChocolateyCentralManagement'"
160189choco feature enable -- name= " 'useChocolateyCentralManagementDeployments'"
190+
191+
192+ if ($AdditionalConfiguration -or $AdditionalFeatures -or $AdditionalSources -or $AdditionalPackages ) {
193+ Write-Host " Applying user supplied configuration" - ForegroundColor Cyan
194+ }
195+ # How we call choco from here changes as we need to be more dynamic with thingsii .
196+ if ($AdditionalConfiguration ) {
197+ <#
198+ We expect to pass in a hashtable with configuration information with the following shape:
199+
200+ @{
201+ Name = BackgroundServiceAllowedCommands
202+ Value = 'install,upgrade,uninstall'
203+ }
204+ #>
205+
206+ $AdditionalConfiguration.GetEnumerator () | ForEach-Object {
207+ $c = [System.Collections.Generic.list [string ]]::new()
208+ $c.Add (' config' )
209+ $c.Add (' set' )
210+ $c.Add (" --name='$ ( $_.Key ) '" )
211+ $c.Add (" --value='$ ( $_.Value ) '" )
212+
213+ & choco @c
214+ }
215+ }
216+
217+ if ($AdditionalFeatures ) {
218+ <#
219+ We expect to pass in feature information as a hashtable with the following shape:
220+
221+ @{
222+ useBackgroundservice = 'Enabled'
223+ }
224+ #>
225+ $AdditionalFeatures.GetEnumerator () | ForEach-Object {
226+
227+ $c = [System.Collections.Generic.list [string ]]::new()
228+ $c.Add (' feature' )
229+
230+ $state = switch ($_.Value ) {
231+ ' Enabled' { ' enable' }
232+ ' Disabled' { ' disable' }
233+ default { Write-Error ' State must be either Enabled or Disabled' }
234+ }
235+
236+ $c.Add ($state )
237+ $c.add (" --name='$ ( $_.Key ) '" )
238+ & choco @c
239+ }
240+ }
241+
242+ if ($AdditionalSources ) {
243+
244+ <#
245+ We expect a user to pass in a hashtable with source information with the folllowing shape:
246+ @{
247+ Name = 'MySource'
248+ Source = 'https://nexus.fabrikam.com/repository/MyChocolateySource'
249+ #Optional items
250+ Credentials = $MySourceCredential
251+ AllowSelfService = $true
252+ AdminOnly = $true
253+ BypassProxy = $true
254+ Priority = 10
255+ Certificate = 'C:\cert.pfx'
256+ CertificatePassword = 's0mepa$$'
257+ }
258+ #>
259+ Foreach ($a in $AdditionalSources ) {
260+ $c = [System.Collections.Generic.List [string ]]::new()
261+ # Required items
262+ $c.Add (' source' )
263+ $c.Add (' add' )
264+ $c.Add (" --name='$ ( $a.Name ) '" )
265+ $c.Add (" --source='$ ( $a.Source ) '" )
266+
267+ # Add credentials if source has them
268+ if ($a.ContainsKey (' Credentials' )) {
269+ $c.Add (" --user='$ ( $a.Credentials.Username ) '" )
270+ $c.Add (" --password='$ ( $a.Credentials.GetNetworkCredential ().Password) '" )
271+ }
272+
273+ switch ($true ) {
274+ $a [' AllowSelfService' ] { $c.add (' --allow-self-service' ) }
275+ $a [' AdminOnly' ] { $c.Add (' --admin-only' ) }
276+ $a [' BypassProxy' ] { $c.Add (' --bypass-proxy' ) }
277+ $a.ContainsKey (' Priority' ) { $c.Add (" --priority='$ ( $a.Priority ) '" ) }
278+ $a.ContainsKey (' Certificate' ) { $c.Add (" --cert='$ ( $a.Certificate ) '" ) }
279+ $a.ContainsKey (' CerfificatePassword' ) { $c.Add (" --certpassword='$ ( $a.CertificatePassword ) '" ) }
280+ }
281+ }
282+
283+ & choco @c
284+ }
285+
286+ if ($AdditionalPackages ) {
287+
288+ <#
289+ We expect to pass in a hashtable with package information with the following shape:
290+
291+ @{
292+ Id = 'firefox'
293+ #Optional
294+ Version = 123.4.56
295+ Pin = $true
296+ }
297+ #>
298+ foreach ($package in $AdditionalPackages.GetEnumerator ()) {
299+
300+ $c = [System.Collections.Generic.list [string ]]::new()
301+ $c.add (' install' )
302+ $c.add ($package [' Id' ])
303+
304+ switch ($true ) {
305+ $package.ContainsKey (' Version' ) { $c.Add (" --version='$ ( $package.version ) '" ) }
306+ $package.ContainsKey (' Pin' ) { $c.Add (' --pin' ) }
307+ }
308+
309+ # Ensure packages install and they don't flood the console output
310+ $c.Add (' -y' )
311+ $c.Add (' --no-progress' )
312+
313+ & choco @c
314+ }
315+ }
0 commit comments