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 ]
1919 $Credential ,
2020
@@ -41,19 +41,43 @@ param(
4141
4242 # Client salt value used to populate the centralManagementClientCommunicationSaltAdditivePassword
4343 # value in the Chocolatey config file
44- [Parameter ()]
44+ [Parameter (Mandatory )]
4545 [string ]
4646 $ClientSalt ,
4747
4848 # Server salt value used to populate the centralManagementServiceCommunicationSaltAdditivePassword
4949 # value in the Chocolatey config file
50- [Parameter ()]
50+ [Parameter (Mandatory )]
5151 [string ]
5252 $ServiceSalt ,
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,11 +93,14 @@ $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
@@ -87,7 +114,8 @@ $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= " '$ ( $Credential.UserName ) '" -- password= " '$ ( $Credential.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,128 @@ if ($ServiceSalt) {
158187}
159188choco feature enable -- name= " 'useChocolateyCentralManagement'"
160189choco feature enable -- name= " 'useChocolateyCentralManagementDeployments'"
190+
191+
192+ Write-Host " Applying user supplied configuration" - ForegroundColor Cyan
193+ # How we call choco from here changes as we need to be more dynamic with thingsii .
194+ if ($AdditionalConfiguration ) {
195+ <#
196+ We expect to pass in a hashtable with configuration information with the following shape:
197+
198+ @{
199+ Name = BackgroundServiceAllowedCommands
200+ Value = 'install,upgrade,uninstall'
201+ }
202+ #>
203+
204+ $AdditionalConfiguration.GetEnumerator () | ForEach-Object {
205+ $c = [System.Collections.Generic.list [string ]]::new()
206+ $c.Add (' config' )
207+ $c.Add (' set' )
208+ $c.Add (" --name='$ ( $_.Key ) '" )
209+ $c.Add (" --value='$ ( $_.Value ) '" )
210+
211+ & choco @c
212+ }
213+ }
214+
215+ if ($AdditionalFeatures ) {
216+ <#
217+ We expect to pass in feature information as a hashtable with the following shape:
218+
219+ @{
220+ Name = useBackgroundservice
221+ State = 'Enabled'
222+ }
223+ #>
224+ $AdditionalFeatures.GetEnumerator () | ForEach-Object {
225+
226+ $c = [System.Collections.Generic.list [string ]]::new()
227+ $c.Add (' feature' )
228+
229+ $state = switch ($_.Value ) {
230+ ' Enabled' { ' enable' }
231+ ' Disabled' { ' disable' }
232+ default { Write-Error ' State must be either Enabled or Disabled' }
233+ }
234+
235+ $c.Add ($state )
236+ $c.add (" --name='$ ( $_.Key ) '" )
237+ & choco @c
238+ }
239+ }
240+
241+ if ($AdditionalSources ) {
242+
243+ <#
244+ We expect a user to pass in a hashtable with source information with the folllowing shape:
245+ @{
246+ Name = 'MySource'
247+ Source = 'https://nexus.fabrikam.com/repository/MyChocolateySource'
248+ #Optional items
249+ Credentials = $MySourceCredential
250+ AllowSelfService = $true
251+ AdminOnly = $true
252+ BypassProxy = $true
253+ Priority = 10
254+ Certificate = 'C:\cert.pfx'
255+ CertificatePassword = 's0mepa$$'
256+ }
257+ #>
258+ Foreach ($a in $AdditionalSources ) {
259+ $c = [System.Collections.Generic.List [string ]]::new()
260+ # Required items
261+ $c.Add (' source' )
262+ $c.Add (' add' )
263+ $c.Add (" --name='$ ( $a.Name ) '" )
264+ $c.Add (" --source='$ ( $a.Source ) '" )
265+
266+ # Add credentials if source has them
267+ if ($a.ContainsKey (' Credentials' )) {
268+ $c.Add (" --user='$ ( $a.Credentials.Username ) '" )
269+ $c.Add (" --password='$ ( $a.Credentials.GetNetworkCredential ().Password) '" )
270+ }
271+
272+ switch ($true ) {
273+ $a [' AllowSelfService' ] { $c.add (' --allow-self-service' ) }
274+ $a [' AdminOnly' ] { $c.Add (' --admin-only' ) }
275+ $a [' BypassProxy' ] { $c.Add (' --bypass-proxy' ) }
276+ $a.ContainsKey (' Priority' ) { $c.Add (" --priority='$ ( $a.Priority ) '" ) }
277+ $a.ContainsKey (' Certificate' ) { $c.Add (" --cert='$ ( $a.Certificate ) '" ) }
278+ $a.ContainsKey (' CerfificatePassword' ) { $c.Add (" --certpassword='$ ( $a.CertificatePassword ) '" ) }
279+ }
280+ }
281+
282+ & choco @c
283+ }
284+
285+ if ($AdditionalPackages ) {
286+
287+ <#
288+ We expect to pass in a hashtable with package information with the following shape:
289+
290+ @{
291+ Id = 'firefox'
292+ #Optional
293+ Version = 123.4.56
294+ Pin = $true
295+ }
296+ #>
297+ foreach ($package in $AdditionalPackages.GetEnumerator ()) {
298+
299+ $c = [System.Collections.Generic.list [string ]]::new()
300+ $c.add (' install' )
301+ $c.add ($package [' Id' ])
302+
303+ switch ($true ) {
304+ $package.ContainsKey (' Version' ) { $c.Add (" --version='$ ( $package.version ) '" ) }
305+ $package.ContainsKey (' Pin' ) { $c.Add (' --pin' ) }
306+ }
307+
308+ # Ensure packages install and they don't flood the console output
309+ $c.Add (' -y' )
310+ $c.Add (' --no-progress' )
311+
312+ & choco @c
313+ }
314+ }
0 commit comments