14
14
# The credential necessary to access the internal Nexus repository. This can
15
15
# be ignored if Anonymous authentication is enabled.
16
16
# This parameter will be necessary if your C4B server is web-enabled.
17
- [Parameter ()]
17
+ [Parameter (Mandatory )]
18
18
[pscredential ]
19
- $Credential ,
19
+ $RepositoryCredential ,
20
20
21
21
# Specifies a target version of Chocolatey to install. By default, the
22
22
# latest stable version is installed.
@@ -41,19 +41,43 @@ param(
41
41
42
42
# Client salt value used to populate the centralManagementClientCommunicationSaltAdditivePassword
43
43
# value in the Chocolatey config file
44
- [Parameter ()]
44
+ [Parameter (Mandatory )]
45
45
[string ]
46
- $ClientSalt ,
46
+ $ClientCommunicationSalt ,
47
47
48
48
# Server salt value used to populate the centralManagementServiceCommunicationSaltAdditivePassword
49
49
# value in the Chocolatey config file
50
- [Parameter ()]
50
+ [Parameter (Mandatory )]
51
51
[string ]
52
- $ServiceSalt ,
52
+ $ServiceCommunicationSalt ,
53
53
54
+ # Install the Chocolatey Licensed Extension with right-click context menus available
54
55
[Parameter ()]
55
56
[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
57
81
)
58
82
59
83
Set-ExecutionPolicy Bypass - Scope Process - Force
@@ -69,25 +93,29 @@ $params = @{
69
93
70
94
if (-not $IgnoreProxy ) {
71
95
if ($ProxyUrl ) {
96
+ $proxy = [System.Net.WebProxy ]::new($ProxyUrl , $true <# bypass on local#> )
72
97
$params.Add (' ProxyUrl' , $ProxyUrl )
73
98
}
74
99
75
100
if ($ProxyCredential ) {
76
101
$params.Add (' ProxyCredential' , $ProxyCredential )
102
+ $proxy.Credentials = $ProxyCredential
103
+
77
104
}
78
105
}
79
106
80
107
$webClient = New-Object System.Net.WebClient
81
- if ($Credential ) {
82
- $webClient.Credentials = $Credential .GetNetworkCredential ()
108
+ if ($RepositoryCredential ) {
109
+ $webClient.Credentials = $RepositoryCredential .GetNetworkCredential ()
83
110
}
84
111
85
112
# Find the latest version of Chocolatey, if a version was not specified
86
113
$NupkgUrl = if (-not $ChocolateyVersion ) {
87
114
$QueryUrl = ($RepositoryUrl.TrimEnd (' /index.json' ), " v3/registration/Chocolatey/index.json" ) -join ' /'
88
115
$Result = $webClient.DownloadString ($QueryUrl ) | ConvertFrom-Json
89
116
$Result.items.items [-1 ].packageContent
90
- } else {
117
+ }
118
+ else {
91
119
# Otherwise, assume the URL
92
120
" $ ( $RepositoryUrl.TrimEnd (' /index.json' )) /v3/content/chocolatey/$ ( $ChocolateyVersion ) /chocolatey.$ ( $ChocolateyVersion ) .nupkg"
93
121
}
@@ -118,18 +146,19 @@ choco config set commandExecutionTimeoutSeconds 14400
118
146
# Nexus NuGet V3 Compatibility
119
147
choco feature disable -- name= " 'usePackageRepositoryOptimizations'"
120
148
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
128
151
choco source disable -- name= " 'Chocolatey'"
129
152
choco source disable -- name= " 'chocolatey.licensed'"
130
153
131
154
choco 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
+ }
133
162
choco upgrade chocolateygui - y -- source= " 'ChocolateyInternal'" -- no- progress
134
163
choco upgrade chocolateygui.extension - y -- source= " 'ChocolateyInternal'" -- no- progress
135
164
@@ -158,3 +187,129 @@ if ($ServiceSalt) {
158
187
}
159
188
choco feature enable -- name= " 'useChocolateyCentralManagement'"
160
189
choco 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