@@ -10,15 +10,14 @@ C4B Quick-Start Guide initial bootstrap script
1010 - Setup of local `choco-setup` directories
1111 - Download of Chocolatey packages required for setup
1212#>
13- [CmdletBinding (DefaultParameterSetName = " Attended " )]
13+ [CmdletBinding (DefaultParameterSetName = ' Prepare ' )]
1414param (
1515 # Full path to Chocolatey license file.
1616 # Accepts any file, and moves and renames it correctly.
1717 # You can either define this as a parameter, or
1818 # script will prompt you for it.
1919 # Script will also validate expiry.
20- [Parameter (ParameterSetName = ' Unattended' )]
21- [Parameter (ParameterSetName = ' Attended' )]
20+ [Parameter (ParameterSetName = ' Install' )]
2221 [string ]
2322 $LicenseFile = $ (
2423 if (Test-Path $PSScriptRoot \files\chocolatey.license.xml) {
@@ -41,40 +40,36 @@ param(
4140 }
4241 ),
4342
44- # Unattended mode. Allows you to skip running the other scripts individually.
45- [Parameter (Mandatory , ParameterSetName = ' Unattended' )]
46- [switch ]
47- $Unattend ,
48-
4943 # Specify a credential used for the ChocolateyManagement DB user.
50- # Only required in Unattend mode for the CCM setup script.
44+ # Only required in install mode for the CCM setup script.
5145 # If not populated, the script will prompt for credentials.
52- [Parameter (ParameterSetName = ' Unattended ' )]
46+ [Parameter (ParameterSetName = ' Install ' )]
5347 [System.Management.Automation.PSCredential ]
5448 $DatabaseCredential = $ (
5549 if ((Test-Path C:\choco- setup\clixml\chocolatey- for- business.xml) -and (Import-Clixml C:\choco- setup\clixml\chocolatey- for- business.xml).DatabaseUser) {
5650 (Import-Clixml C:\choco- setup\clixml\chocolatey- for- business.xml).DatabaseUser
57- } elseif ($PSCmdlet.ParameterSetName -eq ' Unattended' ) {
58- $Wshell = New-Object - ComObject Wscript.Shell
59- $null = $Wshell.Popup (' You will now create a credential for the ChocolateyManagement DB user, to be used by CCM (document this somewhere).' )
60- Get-Credential - UserName ChocoUser - Message ' Create a credential for the ChocolateyManagement DB user'
51+ } elseif ($PSCmdlet.ParameterSetName -eq ' Install' ) {
52+ [PSCredential ]::new(
53+ " chocodbuser" ,
54+ (ConvertTo-SecureString " $ ( New-Guid ) -$ ( New-Guid ) " - Force - AsPlainText)
55+ )
6156 }
6257 ),
6358
6459 # The certificate thumbprint that identifies the target SSL certificate in
6560 # the local machine certificate stores.
66- # Only used in Unattend mode for the SSL setup script.
67- [Parameter (ParameterSetName = ' Unattended ' )]
61+ # Only used in install mode for the SSL setup script.
62+ [Parameter (ParameterSetName = ' Install ' )]
6863 [ArgumentCompleter ({
69- Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
70- [System.Management.Automation.CompletionResult ]::new(
71- $_.Thumbprint ,
72- $_.Thumbprint ,
73- " ParameterValue" ,
74- ($_.Subject -replace " ^CN=(?<FQDN>.+),?.*$" , ' ${FQDN}' )
75- )
76- }
77- })]
64+ Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
65+ [System.Management.Automation.CompletionResult ]::new(
66+ $_.Thumbprint ,
67+ $_.Thumbprint ,
68+ " ParameterValue" ,
69+ ($_.Subject -replace " ^CN=(?<FQDN>.+),?.*$" , ' ${FQDN}' )
70+ )
71+ }
72+ })]
7873 [string ]
7974 $Thumbprint = $ (
8075 if ((Test-Path C:\choco- setup\clixml\chocolatey- for- business.xml) -and (Import-Clixml C:\choco- setup\clixml\chocolatey- for- business.xml).CertThumbprint) {
@@ -87,21 +82,27 @@ param(
8782 ),
8883
8984 # If using a wildcard certificate, provide a DNS name you want to use to access services secured by the certificate.\
90- [string ]$CertificateDnsName = $ (
91- if (-not (Get-Command Get-ChocoEnvironmentProperty - ErrorAction SilentlyContinue)) {. $PSScriptRoot \scripts\Get-Helpers.ps1 }
92- Get-ChocoEnvironmentProperty CertSubject
85+ [Parameter (ParameterSetName = ' Install' )]
86+ [Alias (" FQDN" )]
87+ [string ]
88+ $CertificateDnsName = $ (
89+ if ((Test-Path C:\choco- setup\clixml\chocolatey- for- business.xml) -and (Import-Clixml C:\choco- setup\clixml\chocolatey- for- business.xml).CertSubject) {
90+ (Import-Clixml C:\choco- setup\clixml\chocolatey- for- business.xml).CertSubject
91+ }
9392 ),
9493
9594 # If provided, shows all Chocolatey output. Otherwise, blissful quiet.
96- [switch ]$ShowChocoOutput ,
95+ [switch ]
96+ $ShowChocoOutput ,
9797
9898 # The branch or Pull Request to download the C4B setup scripts from.
9999 # Defaults to main.
100- [string ]
101100 [Alias (' PR' )]
101+ [string ]
102102 $Branch = $env: CHOCO_QSG_BRANCH ,
103103
104- # If provided, will skip launching the browser
104+ # If provided, will skip launching the browser at the end of setup.
105+ [Parameter (ParameterSetName = ' Install' )]
105106 [switch ]$SkipBrowserLaunch
106107)
107108if ($ShowChocoOutput ) {
@@ -133,7 +134,7 @@ try {
133134 $TestDir = Join-Path $ChocoPath " tests"
134135 $xmlDir = Join-Path $ChocoPath " clixml"
135136
136- @ ($ChocoPath , $FilesDir , $PkgsDir , $TempDir , $TestDir , $xmlDir ) | ForEach-Object {
137+ @ ($ChocoPath , $FilesDir , $PkgsDir , $TempDir , $TestDir , $xmlDir ) | ForEach-Object {
137138 $null = New-Item - Path $_ - ItemType Directory - Force - ErrorAction Stop
138139 }
139140
@@ -151,57 +152,78 @@ try {
151152 # Add the Module Path and Import Helper Functions
152153 if (-not (Get-Module C4B- Environment - ListAvailable)) {
153154 if ($env: PSModulePath.Split (' ;' ) -notcontains " $FilesDir \modules" ) {
154- [Environment ]::SetEnvironmentVariable(" PSModulePath" , " $env: PSModulePath ;$FilesDir \modules" , " Machine" )
155+ [Environment ]::SetEnvironmentVariable(" PSModulePath" , " $env: PSModulePath ;$FilesDir \modules" , " Machine" )
155156 $env: PSModulePath = [Environment ]::GetEnvironmentVariables(" Machine" ).PSModulePath
156157 }
157158 }
158159 Import-Module C4B- Environment - Verbose:$false
159160
160- Update-Clixml - Properties @ {
161- InitialDeployment = Get-Date
162- }
163-
164- if ($Thumbprint ) {
165- Set-ChocoEnvironmentProperty CertThumbprint $Thumbprint
166-
167- # Collect current certificate configuration
168- $Certificate = Get-Certificate - Thumbprint $Thumbprint
169- Copy-CertToStore - Certificate $Certificate
170-
171- $null = Test-CertificateDomain - Thumbprint $Thumbprint
172- } elseif ($PSScriptRoot ) {
173- # We're going to be using a self-signed certificate
174- Set-ChocoEnvironmentProperty CertSubject $env: ComputerName
175- }
176-
177- if ($DatabaseCredential ) {
178- Set-ChocoEnvironmentProperty DatabaseUser $DatabaseCredential
179- }
180-
181161 # Downloading all CCM setup packages below
182162 Write-Host " Downloading missing nupkg files to $ ( $PkgsDir ) ." - ForegroundColor Green
183163 Write-Host " This will take some time. Feel free to get a tea or coffee." - ForegroundColor Green
184164
185165 & $FilesDir \OfflineInstallPreparation.ps1 - LicensePath $LicenseFile
186166
187- if (Test-Path $FilesDir \files\* .nupkg) {
188- Invoke-Choco source add -- name LocalChocolateySetup -- source $FilesDir \files\ -- Priority 1
189- }
167+ # Kick off unattended running of remaining setup scripts, if we're running from a saved-script.
168+ if ($PSScriptRoot -or $PSCmdlet.ParameterSetName -eq ' Install' ) {
169+ Update-Clixml - Properties @ {
170+ InitialDeployment = Get-Date
171+ }
172+
173+ if ($Thumbprint ) {
174+ Set-ChocoEnvironmentProperty CertThumbprint $Thumbprint
175+
176+ if ($CertificateDnsName ) {
177+ Set-ChocoEnvironmentProperty CertSubject $CertificateDnsName
178+ }
179+
180+ # Collect current certificate configuration
181+ $Certificate = Get-Certificate - Thumbprint $Thumbprint
182+ Copy-CertToStore - Certificate $Certificate
183+
184+ $null = Test-CertificateDomain - Thumbprint $Thumbprint
185+ } elseif ($PSScriptRoot ) {
186+ # We're going to be using a self-signed certificate
187+ if (-not $CertificateDnsName ) {
188+ $CertificateDnsName = $env: ComputerName
189+ }
190+
191+ $CertificateArgs = @ {
192+ CertStoreLocation = " Cert:\LocalMachine\My"
193+ KeyUsage = " KeyEncipherment" , " DigitalSignature"
194+ DnsName = $CertificateDnsName
195+ NotAfter = (Get-Date ).AddYears(10 )
196+ }
197+
198+ $Certificate = New-SelfSignedCertificate @CertificateArgs
199+ Copy-CertToStore - Certificate $Certificate
200+
201+ $Thumbprint = $Certificate.Thumbprint
202+
203+ Set-ChocoEnvironmentProperty CertThumbprint $Thumbprint
204+ Set-ChocoEnvironmentProperty CertSubject $CertificateDnsName
205+ }
190206
191- # Set Choco Server Chocolatey Configuration
192- Invoke-Choco feature enable -- name= " 'excludeChocolateyPackagesDuringUpgradeAll'"
193- Invoke-Choco feature enable -- name= " 'usePackageHashValidation'"
207+ if ($DatabaseCredential ) {
208+ Set-ChocoEnvironmentProperty DatabaseUser $DatabaseCredential
209+ }
210+
211+ if (Test-Path $FilesDir \files\* .nupkg) {
212+ Invoke-Choco source add -- name LocalChocolateySetup -- source $FilesDir \files\ -- Priority 1
213+ }
194214
195- # Convert license to a "choco-license" package, and install it locally to test
196- Write-Host " Creating a 'chocolatey-license' package, and testing install." - ForegroundColor Green
197- Set-Location $FilesDir
198- .\scripts\Create- ChocoLicensePkg.ps1
199- Remove-Item " $env: SystemDrive \choco-setup\packaging" - Recurse - Force
215+ # Set Choco Server Chocolatey Configuration
216+ Invoke-Choco feature enable -- name= " 'excludeChocolateyPackagesDuringUpgradeAll'"
217+ Invoke-Choco feature enable -- name= " 'usePackageHashValidation'"
218+
219+ # Convert license to a "choco-license" package, and install it locally to test
220+ Write-Host " Creating a 'chocolatey-license' package, and testing install." - ForegroundColor Green
221+ Set-Location $FilesDir
222+ .\scripts\Create- ChocoLicensePkg.ps1
223+ Remove-Item " $env: SystemDrive \choco-setup\packaging" - Recurse - Force
200224
201- # Kick off unattended running of remaining setup scripts.
202- if ($Unattend ) {
203225 $Certificate = @ {}
204- if ($Thumbprint ) {$Certificate.Thumbprint = $Thumbprint }
226+ if ($Thumbprint ) { $Certificate.Thumbprint = $Thumbprint }
205227
206228 Set-Location " $env: SystemDrive \choco-setup\files"
207229 .\Start-C4BNexusSetup.ps1 @Certificate
0 commit comments