diff --git a/images/windows/scripts/build/Install-PostgreSQL.ps1 b/images/windows/scripts/build/Install-PostgreSQL.ps1 index 920600f36..94d3a1f07 100644 --- a/images/windows/scripts/build/Install-PostgreSQL.ps1 +++ b/images/windows/scripts/build/Install-PostgreSQL.ps1 @@ -70,46 +70,12 @@ if ((Get-ToolsetContent).postgresql.installVcRedist) { # Return the previous value of ErrorAction and invoke Install-Binary function $ErrorActionPreference = $errorActionOldValue $installerArgs = @("--install_runtimes 0", "--superpassword root", "--enable_acledit 1", "--unattendedmodeui none", "--mode unattended") -try { - Install-Binary ` - -Url $installerUrl ` - -InstallArgs $installerArgs ` - -ExpectedSignature (Get-ToolsetContent).postgresql.signature -} catch { - # Recursively search for install-postgres.log - $installPostgresLog = Get-ChildItem -Path $env:TEMP -Recurse -Filter "install-postgresql.log" -ErrorAction SilentlyContinue | Select-Object -First 1 - if ($installPostgresLog) { - Write-Output "install-postgres.log found at: $($installPostgresLog.FullName)" - Write-Output "Content of install-postgres.log:" - Get-Content -Path $installPostgresLog.FullName | ForEach-Object { Write-Output $_ } - } else { - Write-Output "install-postgres.log not found." - - # Recursively search for bitrock_installer.log or bitrock_installer_*.log - $bitrockInstallerLogs = @( - Get-ChildItem -Path $tempPath -Recurse -Filter "bitrock_installer.log" -ErrorAction SilentlyContinue, - Get-ChildItem -Path $tempPath -Recurse -Filter "bitrock_installer_*.log" -ErrorAction SilentlyContinue - ) - - # Flatten the array to remove nested arrays - $bitrockInstallerLogs = $bitrockInstallerLogs | Where-Object { $_ } - - foreach ($log in $bitrockInstallerLogs) { - if ($log) { - Write-Output "Found log file: $($log.FullName)" - Write-Output "Content of bitrock_install*.log:" - Get-Content -Path $log.FullName | ForEach-Object { Write-Output $_ } - break - } - } - - # If no log files were found - if (-not $log) { - Write-Warning "No relevant log files found in the temporary directory." - } - } -} +Install-Binary ` + -Url $installerUrl ` + -InstallArgs $installerArgs ` + -ExpectedSignature (Get-ToolsetContent).postgresql.signature + -InstallerLogPath "$env:TEMP/**/postgresql-install.log" # Get Path to pg_ctl.exe $pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName diff --git a/images/windows/scripts/helpers/InstallHelpers.ps1 b/images/windows/scripts/helpers/InstallHelpers.ps1 index b491533e4..fa65a9dac 100644 --- a/images/windows/scripts/helpers/InstallHelpers.ps1 +++ b/images/windows/scripts/helpers/InstallHelpers.ps1 @@ -30,6 +30,10 @@ function Install-Binary { .PARAMETER ExpectedSHA512Sum The expected SHA512 sum of the binary. If specified, the binary's SHA512 sum is checked before installation. + .PARAMETER InstallerLogPath + The path to the log file which is produced when the installation fails. This can be used for debugging purposes. + This is only displayed when the installation fails. + .EXAMPLE Install-Binary -Url "https://go.microsoft.com/fwlink/p/?linkid=2083338" -Type EXE -InstallArgs ("/features", "+", "/quiet") -ExpectedSignature "A5C7D5B7C838D5F89DDBEDB85B2C566B4CDA881F" #> @@ -46,7 +50,8 @@ function Install-Binary { [String[]] $ExtraInstallArgs, [String[]] $ExpectedSignature, [String] $ExpectedSHA256Sum, - [String] $ExpectedSHA512Sum + [String] $ExpectedSHA512Sum, + [String] $InstallerLogPath ) if ($PSCmdlet.ParameterSetName -eq "LocalPath") { @@ -122,6 +127,14 @@ function Install-Binary { } else { Write-Host "Installation process returned unexpected exit code: $exitCode" Write-Host "Time elapsed: $installCompleteTime seconds" + + if ($InstallerLogPath -and (Test-Path -Path $InstallerLogPath)) { + Write-Host "Searching for logs maching $InstallerLogPath pattern" + Get-ChildItem -Path $InstallerLogPath | ForEach-Object { + Write-Output "Found Installer Log: $InstallerLogPath" + Get-Content -Path $InstallerLogPath + } + } exit $exitCode } } catch {