diff --git a/automatic/nexus-repository/tools/chocolateyinstall.ps1 b/automatic/nexus-repository/tools/chocolateyinstall.ps1 index 20b866b28b8..3a73c4a0d3f 100644 --- a/automatic/nexus-repository/tools/chocolateyinstall.ps1 +++ b/automatic/nexus-repository/tools/chocolateyinstall.ps1 @@ -1,4 +1,4 @@ -$ErrorActionPreference = 'Stop' +$ErrorActionPreference = 'Stop' $toolsDir = Split-Path $MyInvocation.MyCommand.Definition . $toolsDir\helpers.ps1 @@ -16,6 +16,7 @@ $ServiceName = 'nexus' # Handle Package Parameters $pp = Get-PackageParameters +$CurrentConfig = Get-NexusConfiguration -Path $NexusConfigFile -ErrorAction SilentlyContinue $Hostname = if ($pp.ContainsKey("Fqdn")) { $pp["Fqdn"] @@ -26,6 +27,12 @@ $Hostname = if ($pp.ContainsKey("Fqdn")) { $NexusPort = if ($pp.ContainsKey("Port")) { $pp["Port"] Write-Host "/Port was used, Nexus will listen on port $($PP['Port'])." +} elseif ($CurrentConfig.'application-port-ssl' -gt 0) { + $CurrentConfig.'application-port-ssl' + Write-Host "Nexus is configured to use application-port-ssl, Nexus will listen on port $($CurrentConfig.'application-port-ssl')" +} elseif ($CurrentConfig.'application-port' -gt 0) { + $CurrentConfig.'application-port' + Write-Host "Nexus is configured to use application-port, Nexus will listen on port $($CurrentConfig.'application-port')" } else { "8081" } @@ -40,7 +47,7 @@ if ((Get-Service $ServiceName -ErrorAction SilentlyContinue)) { Get-Service $ServiceName | Stop-Service -Force } -if ($pp.ContainsKey("BackupSslConfig")) { +if ($pp.ContainsKey("BackupSslConfig") -or $CurrentConfig.'application-port-ssl' -gt 0) { if ($pp.ContainsKey("BackupLocation")) { Backup-NexusSSL -BackupLocation $pp["BackupLocation"] } else { @@ -158,7 +165,7 @@ $processArgs = @{ $null = Start-ChocolateyProcessAsAdmin @processArgs -if ($pp.ContainsKey("BackupSslConfig")) { +if ($pp.ContainsKey("BackupSslConfig") -or $CurrentConfig.'application-port-ssl' -gt 0) { if ($pp.ContainsKey("BackupLocation")) { Restore-NexusSSL -BackupLocation $pp['BackupLocation'] } else { @@ -179,7 +186,7 @@ if ($NexusPort -ne '8081') { # Start the service, and wait for the site to become available if ((Start-Service $ServiceName -PassThru).Status -eq 'Running') { - Wait-NexusAvailability -Hostname $Hostname -Port $NexusPort -Config $NexusConfigFile -SSL:$pp.ContainsKey("BackupSslConfig") + Wait-NexusAvailability -Hostname $Hostname -Config $NexusConfigFile } else { Write-Warning "The Nexus Repository service ($ServiceName) did not start." } diff --git a/automatic/nexus-repository/tools/helpers.ps1 b/automatic/nexus-repository/tools/helpers.ps1 index 47515dafede..57066ec0292 100644 --- a/automatic/nexus-repository/tools/helpers.ps1 +++ b/automatic/nexus-repository/tools/helpers.ps1 @@ -49,24 +49,10 @@ function Wait-NexusAvailability { [Parameter(Mandatory = $true)] [string]$Hostname, - [Parameter(Mandatory = $true)] - [uint16]$Port, - - [Parameter(Mandatory = $true)] + [Parameter(Mandatory)] [Alias("Config")] - [string]$NexusConfigFile, - - [switch]$SSL + [string]$NexusConfigFile = (Join-Path $env:ProgramData "\sonatype-work\nexus3\etc\nexus.properties") ) - # Even though windows reports service is ready - web url will not respond until Nexus is actually ready to serve content - # We need to use this method to collect the port number so we can properly test the website has returned OK. - $nexusScheme, $portConfigLine = if ($SSL) { - # This is to combat Package Internalizer's over-enthusiastic URL matching - ('http' + 's'), 'application-port-ssl' - } else { - 'http', 'application-port' - } - # As the service is started, this should be present momentarily $Timer = [System.Diagnostics.Stopwatch]::StartNew() while (-not ($ConfigPresent = Test-Path $NexusConfigFile) -and $Timer.Elapsed.TotalSeconds -le 60) { @@ -74,20 +60,26 @@ function Wait-NexusAvailability { Start-Sleep -Seconds 5 } - if ($ConfigPresent) { - $nexusPort = (Get-Content $NexusConfigFile | Where-Object { - $_ -match $portConfigLine - }).Split('=')[-1] + $nexusScheme, $nexusPort, $nexusPath = if ($ConfigPresent) { + $Config = Get-NexusConfiguration -Path $NexusConfigFile - $nexusPath = (Get-Content $NexusConfigFile | Where-Object { - $_ -match "nexus-context-path" - }).Split("=")[-1] - } else { - Write-Warning "Expected Nexus Config file '$($NexusConfigFile)' is not present." - $nexusPath, $nexusPort = '/', $Port + if ($Config.'application-port-ssl' -gt 0) { + # This is to combat Package Internalizer's over-enthusiastic URL matching + ('http' + 's') + $Config.'application-port-ssl' + } elseif ($Config.'application-port' -gt 0) { + 'http' + $Config.'application-port' + } + + $Config.'nexus-context-path' } - $NexusUri = "$($nexusScheme)://$($hostname):$($nexusPort)$($nexusPath)" + # Set defaults if not present + if (-not $nexusScheme) {$nexusScheme = 'http'} + if (-not $nexusPort) {$nexusPort = '8081'} + + $NexusUri = "$($nexusScheme)://$($Hostname):$($nexusPort)$($nexusPath)" Write-Host "Waiting on Nexus Web UI to be available at '$($NexusUri)'" while ($Response.StatusCode -ne '200' -and $Timer.Elapsed.TotalMinutes -lt 3) {