Skip to content

Commit

Permalink
(#86) Improve Script Output
Browse files Browse the repository at this point in the history
As some of the changes have resulted in a lot less noise during the script(s) running, this adds a few more bits of output to show folk that progress is being made.

Conversely, this also removes a few of the block-outputs at the end of scripts that tell the user to login - as we don't want them to login until they've completed the guide (see #161).
  • Loading branch information
JPRuskin committed Apr 19, 2024
1 parent ae54cf4 commit b6d1fe4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Set-SslSecurity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ process {
Write-Verbose "Starting up Nexus"
Start-Service nexus

Write-Warning "Waiting to give Nexus time to start up"
Write-Warning "Waiting to give Nexus time to start up on 'https://${SubjectWithoutCn}:8443'"
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::tls12
do {
$response = try {
Expand Down
35 changes: 18 additions & 17 deletions Start-C4bCcmSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ process {
& choco @chocoArgs

# https://docs.microsoft.com/en-us/sql/tools/configuration-manager/tcp-ip-properties-ip-addresses-tab
Write-Output 'SQL Server: Configuring Remote Acess on SQL Server Express.'
Write-Verbose 'SQL Server: Configuring Remote Access on SQL Server Express.'
$assemblyList = 'Microsoft.SqlServer.Management.Common', 'Microsoft.SqlServer.Smo', 'Microsoft.SqlServer.SqlWmiManagement', 'Microsoft.SqlServer.SmoExtended'

foreach ($assembly in $assemblyList) {
Expand Down Expand Up @@ -79,25 +79,26 @@ process {
$SqlString = (Get-ChildItem -Path 'HKLM:\Software\Microsoft\Microsoft SQL Server').Name |
Where-Object { $_ -like "HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\MSSQL*.SQLEXPRESS" }
$SqlVersion = $SqlString.Split("\") | Where-Object { $_ -like "MSSQL*.SQLEXPRESS" }
Write-Output 'SQL Server: Setting Mixed Mode Authentication.'
New-ItemProperty "HKLM:\Software\Microsoft\Microsoft SQL Server\$SqlVersion\MSSQLServer\" -Name 'LoginMode' -Value 2 -Force
Write-Verbose 'SQL Server: Setting Mixed Mode Authentication.'
$null = New-ItemProperty "HKLM:\Software\Microsoft\Microsoft SQL Server\$SqlVersion\MSSQLServer\" -Name 'LoginMode' -Value 2 -Force

Write-Output "SQL Server: Forcing Restart of Instance."
Write-Verbose "SQL Server: Forcing Restart of Instance."
Restart-Service -Force 'MSSQL$SQLEXPRESS'

Write-Output "SQL Server: Setting up SQL Server Browser and starting the service."
Write-Verbose "SQL Server: Setting up SQL Server Browser and starting the service."
Set-Service 'SQLBrowser' -StartupType Automatic
Start-Service 'SQLBrowser'

Write-Output "Firewall: Enabling SQLServer TCP port 1433."
netsh advfirewall firewall add rule name="SQL Server 1433" dir=in action=allow protocol=TCP localport=1433 profile=any enable=yes service=any
Write-Verbose "Firewall: Enabling SQLServer TCP port 1433."
$null = netsh advfirewall firewall add rule name="SQL Server 1433" dir=in action=allow protocol=TCP localport=1433 profile=any enable=yes service=any
#New-NetFirewallRule -DisplayName "Allow inbound TCP Port 1433" –Direction inbound –LocalPort 1433 -Protocol TCP -Action Allow

Write-Output "Firewall: Enabling SQL Server browser UDP port 1434."
netsh advfirewall firewall add rule name="SQL Server Browser 1434" dir=in action=allow protocol=UDP localport=1434 profile=any enable=yes service=any
Write-Verbose "Firewall: Enabling SQL Server browser UDP port 1434."
$null = netsh advfirewall firewall add rule name="SQL Server Browser 1434" dir=in action=allow protocol=UDP localport=1434 profile=any enable=yes service=any
#New-NetFirewallRule -DisplayName "Allow inbound UDP Port 1434" –Direction inbound –LocalPort 1434 -Protocol UDP -Action Allow

# Install prerequisites for CCM
Write-Host "Installing Chocolatey Central Management Prerequisites"
$chocoArgs = @('install', 'IIS-WebServer', "--source='windowsfeatures'", '--no-progress', '-y')
& choco @chocoArgs

Expand All @@ -113,8 +114,8 @@ process {
$chocoArgs = @('install', 'dotnet-6.0-aspnetruntime', "--version=$($Packages.Where{$_.Name -eq 'dotnet-6.0-aspnetruntime'}.Version)", '--no-progress', '--pin', '--pin-reason="Latest version compatible with chocolatey-management-database V 0.12.0"', '-y')
& choco @chocoArgs

# Install CCM DB package using Local SQL Express
choco install chocolatey-management-database -y -s $PkgSrc --package-parameters="'/ConnectionString=Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;Trusted_Connection=true;'" --no-progress
Write-Host "Creating Chocolatey Central Management Database"
choco install chocolatey-management-database -y --package-parameters="'/ConnectionString=Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;Trusted_Connection=true;'" --no-progress

# Add Local Windows User:
$DatabaseUser = $DatabaseCredential.UserName
Expand All @@ -129,7 +130,7 @@ process {
$hostName += "." + $domainName
}

#Install CCM Service
Write-Host "Installing Chocolatey Central Management Service"
if($CertificateThumbprint){
Write-Verbose "Validating certificate is in LocalMachine\TrustedPeople Store"
if($CertificateThumbprint -notin (Get-ChildItem Cert:\LocalMachine\TrustedPeople | Select-Object -Expand Thumbprint)){
Expand All @@ -139,20 +140,20 @@ process {
}
else {
Write-Verbose "Certificate has been successfully found in correct store"
$chocoArgs = @('install','chocolatey-management-service','-y',"--source='$PkgSrc'","--package-parameters-sensitive='/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User Id=$DatabaseUser;Password=$DatabaseUserPw'")
$chocoArgs = @('install', 'chocolatey-management-service', '-y', "--package-parameters-sensitive='/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User Id=$DatabaseUser;Password=$DatabaseUserPw'")
& choco @chocoArgs

Set-CcmCertificate -CertificateThumbprint $CertificateThumbprint
}
}

else {
$chocoArgs = @('install', 'chocolatey-management-service', '-y', "--source='$PkgSrc'", "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress')
$chocoArgs = @('install', 'chocolatey-management-service', '-y', "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress')
& choco @chocoArgs
}

#Install CCM Web package
$chocoArgs = @('install', 'chocolatey-management-web', '-y', "--source='$PkgSrc'", "--package-parameters-sensitive=""'/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'""", '--no-progress')
Write-Host "Installing Chocolatey Central Management Website"
$chocoArgs = @('install', 'chocolatey-management-web', '-y', "--package-parameters-sensitive=""'/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'""", '--no-progress')
& choco @chocoArgs

$CcmSvcUrl = choco config get centralManagementServiceUrl -r
Expand All @@ -165,7 +166,7 @@ process {
}
$CcmJson | ConvertTo-Json | Out-File "$env:SystemDrive\choco-setup\logs\ccm.json"

Write-Host "CCM Setup has now completed" -ForegroundColor Green
Write-Host "Chocolatey Central Management Setup has now completed" -ForegroundColor Green

$ErrorActionPreference = $DefaultEap
Stop-Transcript
Expand Down
13 changes: 5 additions & 8 deletions Start-C4bJenkinsSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ C4B Quick-Start Guide Jenkins setup script
param(
# Hostname of your C4B Server
[string]$HostName = $env:ComputerName,
# Repo where you're installing Jenkins from, usually CCR
[string]$Source = 'https://community.chocolatey.org/api/v2/',

# API key of your Nexus repo, for Chocolatey Jenkins jobs to use
[string]$NuGetApiKey = $(Get-Content "$env:SystemDrive\choco-setup\logs\nexus.json" | ConvertFrom-Json).NuGetApiKey
)
Expand All @@ -36,14 +35,15 @@ process {
. .\scripts\Get-Helpers.ps1

# Install temurin21jre to meet JRE>11 dependency of Jenkins
$chocoArgs = @('install', 'temurin21jre', '-y', "--source='$Source'", '--no-progress', "--params='/ADDLOCAL=FeatureJavaHome'")
$chocoArgs = @('install', 'temurin21jre', '-y', '--no-progress', "--params='/ADDLOCAL=FeatureJavaHome'")
& choco @chocoArgs

# Enviornment variable used to disbale jenkins instal login prompts
# Environment variable used to disable jenkins install login prompts
[Environment]::SetEnvironmentVariable('JAVA_OPTS', '-Djenkins.install.runSetupWizard=false', 'Machine')

# Install Jenkins
$chocoArgs = @('install', 'jenkins', '-y', "--source='$Source'", '--no-progress')
Write-Host "Installing Jenkins"
$chocoArgs = @('install', 'jenkins', '-y', '--no-progress')
& choco @chocoArgs

Write-Host "Giving Jenkins 30 seconds to complete background setup..." -ForegroundColor Green
Expand Down Expand Up @@ -133,9 +133,6 @@ process {
$JenkinsJson | ConvertTo-Json | Out-File "$env:SystemDrive\choco-setup\logs\jenkins.json"

Write-Host 'Jenkins setup complete' -ForegroundColor Green
Write-Host "Login to Jenkins at: $($JenkinsJson.JenkinsUri)" -ForegroundColor Green
Write-Host 'Initial default Jenkins admin user password:' -ForegroundColor Green
Write-Host "Admin Password is '$($JenkinsJson.JenkinsPw)'" -ForegroundColor Green

$ErrorActionPreference = $DefaultEap
Stop-Transcript
Expand Down
50 changes: 16 additions & 34 deletions Start-C4bNexusSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ process {
. .\scripts\Get-Helpers.ps1

# Install base nexus-repository package
$chocoArgs = @('install','nexus-repository','-y',"--source='https://community.chocolatey.org/api/v2/'",'--no-progress',"--package-parameters='/Fqdn:localhost'")
Write-Host "Installing Sonatype Nexus Repository"
$chocoArgs = @('install', 'nexus-repository', '-y' ,'--no-progress', "--package-parameters='/Fqdn:localhost'")
& choco @chocoArgs

#Build Credential Object, Connect to Nexus
Write-Host "Configuring Sonatype Nexus Repository"
$securePw = (Get-Content 'C:\programdata\sonatype-work\nexus3\admin.password') | ConvertTo-SecureString -AsPlainText -Force
$Credential = [System.Management.Automation.PSCredential]::new('admin',$securePw)

Expand Down Expand Up @@ -90,26 +92,22 @@ process {
choco source add -n 'ChocolateyInternal' -s "$((Get-NexusRepository -Name 'ChocolateyInternal').url)/index.json" --priority 1

# Install a non-IE browser for browsing the Nexus web portal.
# Edge sometimes fails install due to latest Windows Updates not being installed.
# In that scenario, Google Chrome is installed instead.
$null = choco install microsoft-edge -y --source="'https://community.chocolatey.org/api/v2/'"
if ($LASTEXITCODE -eq 0) {
if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Edge') {
$RegArgs = @{
Path = 'HKLM:\SOFTWARE\Microsoft\Edge\'
Name = 'HideFirstRunExperience'
Type = 'Dword'
Value = 1
Force = $true
if (-not (Test-Path 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')) {
Write-Host "Installing Microsoft Edge, to allow viewing the Nexus site"
choco install microsoft-edge -y
if ($LASTEXITCODE -eq 0) {
if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Edge') {
$RegArgs = @{
Path = 'HKLM:\SOFTWARE\Microsoft\Edge\'
Name = 'HideFirstRunExperience'
Type = 'Dword'
Value = 1
Force = $true
}
$null = Set-ItemProperty @RegArgs
}
Set-ItemProperty @RegArgs
}
}
else {
Write-Warning "Microsoft Edge install was not succesful."
Write-Host "Installing Google Chrome as an alternative."
choco install googlechrome -y --source="'https://community.chocolatey.org/api/v2/'"
}

# Add Nexus port 8081 access via firewall
$FwRuleParams = @{
Expand All @@ -131,22 +129,6 @@ process {
}
$NexusJson | ConvertTo-Json | Out-File "$env:SystemDrive\choco-setup\logs\nexus.json"

$finishOutput = @"
##############################################################
Nexus Repository Setup Completed
Please login to the following URL to complete admin account setup:
Server Url: 'http://localhost:8081' (this will change once you add a certificate)
Chocolatey Repo: "$((Get-NexusRepository -Name 'ChocolateyInternal').url)/"
NuGet ApiKey: $NugetApiKey
Nexus 'admin' user password: $($Credential.GetNetworkCredential().Password)
##############################################################
"@

Write-Host "$finishOutput" -ForegroundColor Green

$ErrorActionPreference = $DefaultEap
Stop-Transcript
}
9 changes: 8 additions & 1 deletion Start-C4bSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ param(
# Only used in Unattend mode for the SSL setup script.
[Parameter(ParameterSetName='Unattended')]
[string]
$Thumbprint
$Thumbprint,

# If provided, shows all Chocolatey output. Otherwise, blissful quiet.
[switch]$ShowChocoOutput
)

if ($host.name -ne 'ConsoleHost') {
Expand All @@ -73,6 +76,10 @@ if ($host.name -ne 'ConsoleHost') {
break
}

if ($ShowChocoOutput) {
$global:PSDefaultParameterValues["Invoke-Choco:InformationAction"] = "Continue"
}

if ($env:CHOCO_QSG_DEVELOP){
$QsRepo = "https://github.com/chocolatey/choco-quickstart-scripts/archive/refs/heads/develop.zip"
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/Get-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ function New-NexusNugetHostedRepository {
}

Write-Verbose $($Body | ConvertTo-Json)
Invoke-Nexus -UriSlug $FullUrlSlug -Body $Body -Method POST
$null = Invoke-Nexus -UriSlug $FullUrlSlug -Body $Body -Method POST

}
}
Expand Down Expand Up @@ -745,7 +745,7 @@ function New-NexusRawHostedRepository {
}

Write-Verbose $($Body | ConvertTo-Json)
Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST
$null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST


}
Expand Down Expand Up @@ -882,7 +882,7 @@ function Enable-NexusRealm {
$body = $collection

Write-Verbose $($Body | ConvertTo-Json)
Invoke-Nexus -UriSlug $urislug -BodyAsArray $Body -Method PUT
$null = Invoke-Nexus -UriSlug $urislug -BodyAsArray $Body -Method PUT

}
}
Expand Down Expand Up @@ -1599,15 +1599,15 @@ ALTER ROLE [$DatabaseRole] ADD MEMBER [$Username]
"@
}

Write-Output "Adding $UserName to $DatabaseName with the following permissions: $($DatabaseRoles -Join ', ')"
Write-Host "Adding $UserName to $DatabaseName with the following permissions: $($DatabaseRoles -Join ', ')"
Write-Debug "running the following: \n $addUserSQLCommand"
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "server='$DatabaseServer';database='master';$DatabaseServerPermissionsOptions"
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.CommandText = $addUserSQLCommand
$Command.Connection = $Connection
$Command.ExecuteNonQuery()
$null = $Command.ExecuteNonQuery()
$Connection.Close()
}

Expand Down

0 comments on commit b6d1fe4

Please sign in to comment.