@@ -13,24 +13,35 @@ certificate is placed in the required local machine store, and then the script
1313generates SSL bindings for both Nexus and the Central Management website using the
1414certificate.
1515#>
16- [CmdletBinding ()]
16+ [CmdletBinding (DefaultParameterSetName = ' SelfSigned ' )]
1717[OutputType ([string ])]
1818param (
1919 # The certificate thumbprint that identifies the target SSL certificate in
2020 # the local machine certificate stores.
2121 # Ignored if supplied alongside -Subject.
22- [Parameter (ValueFromPipeline )]
22+ [Parameter (ValueFromPipeline , ParameterSetName = ' Thumbprint' )]
23+ [ArgumentCompleter ({
24+ Get-ChildItem Cert:\LocalMachine\My | ForEach-Object {
25+ [System.Management.Automation.CompletionResult ]::new(
26+ $_.Thumbprint ,
27+ $_.Thumbprint ,
28+ ' ParameterValue' ,
29+ $_.FriendlyName
30+ )
31+ }
32+ })]
2333 [string ]
2434 $Thumbprint = (Get-ChildItem Cert:\LocalMachine\TrustedPeople - Recurse | Select-Object - ExpandProperty Thumbprint),
2535
2636 # The certificate subject that identifies the target SSL certificate in
2737 # the local machine certificate stores.
28- [Parameter ()]
38+ [Parameter (ParameterSetName = ' Subject ' )]
2939 [string ]
3040 $Subject ,
3141
3242 # If using a wildcard certificate, provide a DNS name you want to use to access services secured by the certificate.
33- [Parameter ()]
43+ [Parameter (ParameterSetName = ' Subject' )]
44+ [Parameter (ParameterSetName = ' Thumbprint' )]
3445 [string ]
3546 $CertificateDnsName ,
3647
4455
4556 # The C4B server hostname for which to generate a new self-signed certificate.
4657 # Ignored/unused if a certificate thumbprint or subject is supplied.
47- [Parameter ()]
58+ [Parameter (ParameterSetName = ' SelfSigned ' )]
4859 [string ]
4960 $Hostname = [System.Net.Dns ]::GetHostName(),
5061
@@ -91,8 +102,8 @@ process {
91102 }
92103 }
93104
94- # Nexus
95- # Stop Services/Processes/Websites required
105+ <# Nexus #>
106+ # Stop Services/Processes/Websites required
96107 Stop-Service nexus
97108
98109 # Put certificate in TrustedPeople
@@ -113,41 +124,37 @@ process {
113124 $response = try {
114125 Invoke-WebRequest " https://${SubjectWithoutCn} :8443" - UseBasicParsing - ErrorAction Stop
115126 Start-Sleep - Seconds 3
116- }
117- catch {
118-
119- }
120-
127+ } catch {}
121128 } until ($response.StatusCode -eq ' 200' )
122129 Write-Host " Nexus is ready!"
123130
124131 choco source remove -- name= " 'ChocolateyInternal'"
125132 $RepositoryUrl = " https://${SubjectWithoutCn} :8443/repository/ChocolateyInternal/index.json"
126133
127- # Build Credential Object, Connect to Nexus
134+ # Build Credential Object, Connect to Nexus
128135 $securePw = (Get-Content ' C:\programdata\sonatype-work\nexus3\admin.password' ) | ConvertTo-SecureString - AsPlainText - Force
129136 $Credential = [System.Management.Automation.PSCredential ]::new(' admin' , $securePw )
130-
137+
131138 # Connect to Nexus
132139 Connect-NexusServer - Hostname $SubjectWithoutCn - Credential $Credential - UseSSL
133140
134141 # Add updated scripts to raw repo in Nexus
135142
136- # Push ChocolateyInstall.ps1 to raw repo
143+ # Push ChocolateyInstall.ps1 to raw repo
137144 $ScriptDir = " $env: SystemDrive \choco-setup\files\scripts"
138145 $ChocoInstallScript = " $ScriptDir \ChocolateyInstall.ps1"
139146 (Get-Content - Path $ChocoInstallScript ) -replace " {{hostname}}" , $SubjectWithoutCn | Set-Content - Path $ChocoInstallScript
140147 New-NexusRawComponent - RepositoryName ' choco-install' - File " $ChocoInstallScript "
141148
142- # Push ClientSetup.ps1 to raw repo
149+ # Push ClientSetup.ps1 to raw repo
143150 $ClientScript = " $ScriptDir \ClientSetup.ps1"
144151 (Get-Content - Path $ClientScript ) -replace " {{hostname}}" , $SubjectWithoutCn | Set-Content - Path $ClientScript
145152 New-NexusRawComponent - RepositoryName ' choco-install' - File $ClientScript
146153
147154 if ($Hardened ) {
148155 # Disable anonymous authentication
149156 Set-NexusAnonymousAuth - Disabled
150-
157+
151158 if (-not (Get-NexusRole - Role ' chocorole' - ErrorAction SilentlyContinue)) {
152159 # Create Nexus role
153160 $RoleParams = @ {
@@ -202,6 +209,34 @@ process {
202209 $chocoArgs = @ (' apikey' , " --source='$RepositoryUrl '" , " --api-key='$NuGetApiKey '" )
203210 & choco @chocoArgs
204211
212+ Update-JsonFile - Path " $env: SystemDrive \choco-setup\logs\nexus.json" - Properties @ {
213+ NexusUri = " https://$ ( $SubjectWithoutCn ) :8443"
214+ NexusRepo = $RepositoryUrl
215+ ChocoUserPassword = $NexusPw
216+ }
217+
218+ <# Jenkins #>
219+ $JenkinsHome = " C:\ProgramData\Jenkins\.jenkins"
220+
221+ # Update Jenkins Jobs with Nexus URL
222+ Get-ChildItem - Path " $JenkinsHome \jobs" - Recurse - File - Filter ' config.xml' | Invoke-TextReplacementInFile - Replacement @ {
223+ ' (?<=https:\/\/)(?<HostName>.+)(?=:8443\/repository\/)' = $SubjectWithoutCn
224+ }
225+
226+ # Generate Jenkins keystore
227+ Set-JenkinsCertificate - Thumbprint $Certificate.Thumbprint
228+
229+ # Add firewall rule for Jenkins
230+ netsh advfirewall firewall add rule name= " Jenkins-7443" dir= in action= allow protocol= tcp localport= 7443
231+
232+ Update-JsonFile - Path " $env: SystemDrive \choco-setup\logs\jenkins.json" - Properties @ {
233+ JenkinsUri = " https://$ ( $SubjectWithoutCn ) :7443"
234+ }
235+
236+ <# CCM #>
237+ # Update the service certificate
238+ Set-CcmCertificate - CertificateThumbprint $Certificate.Thumbprint
239+
205240 # Remove old CCM web binding, and add new CCM web binding
206241 Stop-CcmService
207242 Remove-CcmBinding
@@ -282,7 +317,13 @@ Invoke-Expression (`$downloader.DownloadString("http://`$(`$HostName):80/Import-
282317 (Get-Content - Path $EndpointScript ) -replace " # placeholder if using a self-signed cert" , $ScriptBlock | Set-Content - Path $EndpointScript
283318 }
284319 }
285-
320+
321+ Update-JsonFile - Path " $env: SystemDrive \choco-setup\logs\ccm.json" - Properties @ {
322+ CCMWebPortal = " https://$ ( $SubjectWithoutCn ) /Account/Login"
323+ CCMServiceURL = " https://$ ( $SubjectWithoutCn ) :24020/ChocolateyManagementService"
324+ ServiceSalt = $ServiceSaltValue
325+ ClientSalt = $ClientSaltValue
326+ }
286327
287328 # Save useful params to JSON
288329 $SslJson = @ {
@@ -299,6 +340,47 @@ end {
299340 # Hand back the created/found certificate to the caller.
300341 $Certificate
301342
343+ Write-Host ' Writing README to Desktop; this file contains login information for all C4B services.'
344+ New-QuickstartReadme
345+
346+ Write-Host ' Cleaning up temporary data'
347+ Remove-JsonFiles
348+
349+ $Message = ' The CCM, Nexus & Jenkins sites will open in your browser in 10 seconds. Press any key to skip this.'
350+ $Timeout = New-TimeSpan - Seconds 10
351+ $Stopwatch = [System.Diagnostics.Stopwatch ]::new()
352+ $Stopwatch.Start ()
353+ Write-Host $Message - NoNewline - ForegroundColor Green
354+ do {
355+ # wait for a key to be available:
356+ if ([Console ]::KeyAvailable) {
357+ # read the key, and consume it so it won't
358+ # be echoed to the console:
359+ $keyInfo = [Console ]::ReadKey($true )
360+ Write-Host " `n Skipping the Opening of sites in your browser." - ForegroundColor Green
361+ # exit loop
362+ break
363+ }
364+ # write a dot and wait a second
365+ Write-Host ' .' - NoNewline - ForegroundColor Green
366+ Start-Sleep - Seconds 1
367+ }
368+ while ($Stopwatch.Elapsed -lt $Timeout )
369+ $Stopwatch.Stop ()
370+
371+ if (-not ($keyInfo )) {
372+ Write-Host " `n Opening CCM, Nexus & Jenkins sites in your browser." - ForegroundColor Green
373+ $Readme = ' file:///C:/Users/Public/Desktop/README.html'
374+ $Ccm = " https://$ ( $SubjectWithoutCn ) /Account/Login"
375+ $Nexus = " https://$ ( $SubjectWithoutCn ) :8443"
376+ $Jenkins = " https://$ ( $SubjectWithoutCn ) :7443"
377+ try {
378+ Start-Process msedge.exe " $Readme " , " $Ccm " , " $Nexus " , " $Jenkins "
379+ } catch {
380+ Start-Process chrome.exe " $Readme " , " $Ccm " , " $Nexus " , " $Jenkins "
381+ }
382+ }
383+
302384 $ErrorActionPreference = $DefaultEap
303385 Stop-Transcript
304386}
0 commit comments