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 18, 2024
1 parent c6876d3 commit 015b91f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 49 deletions.
2 changes: 1 addition & 1 deletion OfflineInstallPreparation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ foreach ($Package in (Get-Content $PSScriptRoot\files\chocolatey.json | ConvertF

try {
if (-not (Test-Path "$($PackageWorkingDirectory)\$($Package.Name)*.nupkg") -and -not (Test-Path "$PSScriptRoot\files\$($Package.Name)*.nupkg")) {
Write-Verbose "Downloading '$($Package.Name)'"
Write-Host "Downloading '$($Package.Name)'"
$Output = choco @ChocoArgs
if ($LASTEXITCODE -ne 0) {
$Output
Expand Down
28 changes: 15 additions & 13 deletions Start-C4bCcmSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ process {
$PkgSrc = "$env:SystemDrive\choco-setup\packages"
$Ccr = 'https://community.chocolatey.org/api/v2/'

Write-Host "Installing SQL Server Express"
$chocoArgs = @('upgrade', 'sql-server-express', 'sql-server-management-studio', '-y', "--source='$Ccr'", '--no-progress')
& 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 @@ -81,25 +82,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 @@ -115,7 +117,7 @@ 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
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:
Expand All @@ -131,7 +133,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 @@ -153,7 +155,7 @@ process {
& choco @chocoArgs
}

#Install CCM Web package
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

Expand All @@ -167,7 +169,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
6 changes: 2 additions & 4 deletions Start-C4bJenkinsSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ process {
$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
Write-Host "Installing Jenkins"
$chocoArgs = @('install', 'jenkins', '-y', '--no-progress')
& choco @chocoArgs

Expand Down Expand Up @@ -132,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
45 changes: 16 additions & 29 deletions Start-C4bNexusSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ process {
. .\scripts\Get-Helpers.ps1

# Install base nexus-repository package
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)

Connect-NexusServer -Hostname localhost -Credential $Credential

#Drain default repositories
Get-NexusRepository | Remove-NexusRepository -Force
$null = Get-NexusRepository | Remove-NexusRepository -Force

#Enable NuGet Auth Realm
Enable-NexusRealm -Realm 'NuGet API-Key Realm'
Expand Down Expand Up @@ -91,19 +93,20 @@ 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.
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
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
}
}

Expand All @@ -127,22 +130,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
}
4 changes: 2 additions & 2 deletions scripts/Get-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1600,15 +1600,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 015b91f

Please sign in to comment.