@@ -1839,6 +1839,22 @@ function Invoke-TextReplacementInFile {
18391839 }
18401840}
18411841
1842+ function Update-JsonFile {
1843+ [CmdletBinding ()]
1844+ param (
1845+ [Parameter (Mandatory )]
1846+ [string ]$Path ,
1847+
1848+ [Parameter (Mandatory )]
1849+ [hashtable ]$Properties
1850+ )
1851+ $Json = Get-Content - Path $Path | ConvertFrom-Json
1852+ $Properties.GetEnumerator ().ForEach {
1853+ Add-Member - InputObject $Json - MemberType NoteProperty - Name $_.Key - Value $_.Value - Force
1854+ }
1855+ $Json | ConvertTo-Json | Set-Content - Path $Path
1856+ }
1857+
18421858function Set-JenkinsCertificate {
18431859 <#
18441860 . Synopsis
@@ -1887,8 +1903,8 @@ function Set-JenkinsCertificate {
18871903 $CurrentAlias = ($ ($CertificatePassword.Password | & $KeyTool - list - v - storetype PKCS12 - keystore $CertificatePath ) -match " ^Alias.*" ).Split(' :' )[1 ].Trim()
18881904 Write-Host " " # Adds a newline, after this command has finished.
18891905
1890- $null = & $KeyTool - importkeystore - srckeystore $CertificatePath - srcstoretype PKCS12 - srcstorepass $CertificatePassword.Password - destkeystore $KeyStore - deststoretype JKS - alias $currentAlias - destalias jetty - deststorepass $Passkey * > & 1
1891- $null = & $KeyTool - keypasswd - keystore $KeyStore - alias jetty - storepass $Passkey - keypass $CertificatePassword.Password - new $Passkey * > & 1
1906+ $null = & $KeyTool - importkeystore - srckeystore $CertificatePath - srcstoretype PKCS12 - srcstorepass $CertificatePassword.Password - destkeystore $KeyStore - deststoretype JKS - alias $currentAlias - destalias jetty - deststorepass $Passkey
1907+ $null = & $KeyTool - keypasswd - keystore $KeyStore - alias jetty - storepass $Passkey - keypass $CertificatePassword.Password - new $Passkey
18921908 } finally {
18931909 # Clean up the exported certificate
18941910 Remove-Item $CertificatePath
@@ -1955,83 +1971,42 @@ The host name of the C4B instance.
19551971./New-QuickstartReadme.ps1 -HostName c4b.example.com
19561972#>
19571973 [CmdletBinding ()]
1958- Param (
1959- [Parameter ()]
1960- [string ]
1961- $HostName = $ (Get-Content " $env: SystemDrive \choco-setup\logs\ssl.json" | ConvertFrom-Json ).CertSubject
1962-
1963- )
1964-
1965-
1974+ param ()
19661975 process {
1967- $nexusPassword = if (Test-Path " $env: SystemDrive \choco-setup\logs\nexus.json" ) {
1968- (Get-Content " $env: SystemDrive \choco-setup\logs\nexus.json" | ConvertFrom-Json ).NexusPw
1969- } elseif (Test-Path ' C:\ProgramData\sonatype-work\nexus3\admin.password' ) {
1970- Get-Content ' C:\ProgramData\sonatype-work\nexus3\admin.password'
1976+ try {
1977+ $CCMData = Get-Content " $env: SystemDrive \choco-setup\logs\ccm.json" | ConvertFrom-Json
1978+ $NexusData = Get-Content " $env: SystemDrive \choco-setup\logs\nexus.json" | ConvertFrom-Json
1979+ $JenkinsData = Get-Content " $env: SystemDrive \choco-setup\logs\jenkins.json" | ConvertFrom-Json
1980+ } catch {
1981+ Write-Error " Unable to read JSON files. Ensure the Quickstart Guide has been completed."
19711982 }
1972- $jenkinsPassword = (Get-Content " $env: SystemDrive \choco-setup\logs\jenkins.json" | ConvertFrom-Json ).JenkinsPw
1973- $nexusApiKey = (Get-Content " $env: SystemDrive \choco-setup\logs\nexus.json" | ConvertFrom-Json ).NuGetApiKey
1974-
1975- $tableData = @ ([pscustomobject ]@ {
1976- Name = ' Nexus'
1977- Url = " https://${HostName} :8443"
1978- Username = " admin"
1979- Password = $nexusPassword
1980- ApiKey = $nexusApiKey
1981- },
1982- [pscustomobject ]@ {
1983- Name = ' Central Management'
1984- Url = " https://${HostName} "
1985- Username = " ccmadmin"
1986- Password = ' 123qwe'
1987- },
1988- [PSCustomObject ]@ {
1989- Name = ' Jenkins'
1990- Url = " https://${HostName} :7443"
1991- Username = " admin"
1992- Password = $jenkinsPassword
1993- }
1994- )
1995-
1996-
1997- $html = @"
1998- <html>
1999- <head>
2000- </head>
2001- <title>Chocolatey For Business Service Defaults</title>
2002- <style>
2003- table {
2004- border-collapse: collapse;
2005- }
2006- td,
2007- th {
2008- border: 0.1em solid rgba(0, 0, 0, 0.5);
2009- padding: 0.25em 0.5em;
2010- text-align: center;
2011- }
2012- blockquote {
2013- margin-left: 0.5em;
2014- padding-left: 0.5em;
2015- border-left: 0.1em solid rgba(0, 0, 0, 0.5);
2016- }</style>
2017- <body>
2018- <blockquote>
2019- <p><strong>Note</strong></p>
2020- <p>The following table provides the default credentials to login to each of the services made available as part of the Quickstart Guide setup process.</p>
2021- You'll be asked to change the credentials upon logging into each service for the first time.
2022- Document your new credentials in a password manager, or whatever system you use.
2023- </p>
2024- </blockquote>
2025- $ ( ($TableData | ConvertTo-Html - Fragment))
2026- </body>
2027- </html>
2028- "@
2029-
2030- $folder = Join-Path $env: Public ' Desktop'
2031- $file = Join-Path $folder ' README.html'
2032-
2033- $html | Set-Content $file
20341983
1984+ Copy-Item $PSScriptRoot \ReadmeTemplate.html.j2 - Destination $env: Public \Desktop\Readme.html - Force
1985+
1986+ # Working around the existing j2 template, so we can keep them roughly in sync
1987+ Invoke-TextReplacementInFile - Path $env: Public \Desktop\Readme.html - Replacement @ {
1988+ # CCM Values
1989+ " {{ ccm_fqdn .*?}}" = ([uri ]$CCMData.CCMWebPortal ).DnsSafeHost
1990+ " {{ ccm_port .*?}}" = ([uri ]$CCMData.CCMWebPortal ).Port
1991+ " {{ ccm_password .*?}}" = [System.Web.HttpUtility ]::HtmlEncode($CCMData.DefaultPwToBeChanged )
1992+
1993+ # Chocolatey Configuration Values
1994+ " {{ ccm_encryption_password .*?}}" = " Requested on first run."
1995+ " {{ ccm_client_salt .*?}}" = [System.Web.HttpUtility ]::HtmlEncode($CCMData.ClientSalt )
1996+ " {{ ccm_service_salt .*?}}" = [System.Web.HttpUtility ]::HtmlEncode($CCMData.ServiceSalt )
1997+ " {{ chocouser_password .*?}}" = [System.Web.HttpUtility ]::HtmlEncode($NexusData.ChocoUserPassword )
1998+
1999+ # Nexus Values
2000+ " {{ nexus_fqdn .*?}}" = ([uri ]$NexusData.NexusUri ).DnsSafeHost
2001+ " {{ nexus_port .*?}}" = ([uri ]$NexusData.NexusUri ).Port
2002+ " {{ nexus_password .*?}}" = [System.Web.HttpUtility ]::HtmlEncode($NexusData.NexusPw )
2003+ " {{ lookup\('file', 'credentials\/nexus_apikey'\) .*?}}" = $NexusJson.NuGetApiKey
2004+
2005+ # Jenkins Values
2006+ " {{ jenkins_fqdn .*?}}" = ([uri ]$JenkinsData.JenkinsUri ).DnsSafeHost
2007+ " {{ jenkins_port .*?}}" = ([uri ]$JenkinsData.JenkinsUri ).Port
2008+ " {{ jenkins_password .*?}}" = [System.Web.HttpUtility ]::HtmlEncode($JenkinsData.JenkinsPw )
2009+ }
20352010 }
20362011}
20372012# endregion
0 commit comments