From c90fa568f7b534d595c34c318d202cbaab625e70 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Wed, 3 Jun 2020 10:33:36 +0300 Subject: [PATCH 1/2] update mongodb and postgresql md --- .../scripts/Installers/Install-MongoDB.ps1 | 7 +-- .../scripts/Installers/Install-PostgreSQL.ps1 | 23 ++++------ .../scripts/Installers/Validate-MongoDB.ps1 | 22 ++------- .../Installers/Validate-PostgreSQL.ps1 | 46 ++++++------------- .../SoftwareReport.Databases.psm1 | 41 +++++++++++++++++ .../SoftwareReport.Generator.ps1 | 13 ++++-- 6 files changed, 82 insertions(+), 70 deletions(-) create mode 100644 images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 diff --git a/images/win/scripts/Installers/Install-MongoDB.ps1 b/images/win/scripts/Installers/Install-MongoDB.ps1 index d56382307b8e..245e5b98fd36 100644 --- a/images/win/scripts/Installers/Install-MongoDB.ps1 +++ b/images/win/scripts/Installers/Install-MongoDB.ps1 @@ -3,6 +3,7 @@ ## Desc: Install MongoDB #################################################################################### -choco install mongodb - -Add-MachinePathItem "$($env:SystemDrive)\Program Files\MongoDB\Server\4.2\bin" +Choco-Install -PackageName mongodb +$mongoPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'mongodb'").PathName +$mongoBin = Split-Path -Path $mongoPath.split('"')[1] +Add-MachinePathItem "$mongoBin" diff --git a/images/win/scripts/Installers/Install-PostgreSQL.ps1 b/images/win/scripts/Installers/Install-PostgreSQL.ps1 index 2e6bc373d78c..c0765c65412e 100644 --- a/images/win/scripts/Installers/Install-PostgreSQL.ps1 +++ b/images/win/scripts/Installers/Install-PostgreSQL.ps1 @@ -1,22 +1,19 @@ $ErrorActionPreference = "Stop" -Import-Module -Name ImageHelpers - #Define user and password for PostgreSQL database -$postgresusr="postgres" -$postgrespwd="root" +$pgUser = "postgres" +$pgPwd = "root" #Prepare environment variable for validation -Set-SystemVariable -SystemVariable PGUSER -Value $postgresusr -Set-SystemVariable -SystemVariable PGPASSWORD -Value $postgrespwd -#Install latest PostgreSQL +Set-SystemVariable -SystemVariable PGUSER -Value $pgUser +Set-SystemVariable -SystemVariable PGPASSWORD -Value $pgPwd -cinst postgresql --params "/Password:$postgrespwd" --params-global --debug --verbose +#Install latest PostgreSQL +Choco-Install -PackageName postgresql -ArgumentList "--params", "/Password:$pgPwd", "--params-global", "--debug", "--verbose" #Get Path to pg_ctl.exe -$paths = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName +$pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName #Parse output of command above to obtain pure path -$pgbin = $paths.split('"')[1].replace("\pg_ctl.exe", "") -#Added PostgreSQL bin path into PATH variable. -Add-MachinePathItem $pgbin - +$pgBin = Split-Path -Path $pgPath.split('"')[1] +#Added PostgreSQL bin path into PATH variable +Add-MachinePathItem $pgBin diff --git a/images/win/scripts/Installers/Validate-MongoDB.ps1 b/images/win/scripts/Installers/Validate-MongoDB.ps1 index e0580b543679..517f824cb283 100644 --- a/images/win/scripts/Installers/Validate-MongoDB.ps1 +++ b/images/win/scripts/Installers/Validate-MongoDB.ps1 @@ -3,10 +3,9 @@ ## Desc: Validate MongoDB ################################################################################ -$command = Get-Command -Name 'mongod' -if($command) +if (Get-Command -Name 'mongod') { - Write-Host "mongod is on path" + Write-Host 'mongod is on path' } else { @@ -14,25 +13,12 @@ else exit 1 } -$command = Get-Command -Name 'mongo' -if($command) +if (Get-Command -Name 'mongo') { - Write-Host "mongo is on path" + Write-Host 'mongo is on path' } else { Write-Host 'mongo not on path' exit 1 } - -# Adding description of the software to Markdown -$SoftwareName = "MongoDB" -$version = $command.Version.ToString(); - -$Description = @" -_Version:_ $version
-_Environment:_ -* PATH: contains location of mongo.exe and mongod.exe -"@ - -Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description diff --git a/images/win/scripts/Installers/Validate-PostgreSQL.ps1 b/images/win/scripts/Installers/Validate-PostgreSQL.ps1 index bfd2f0f057dd..14cdc2981add 100644 --- a/images/win/scripts/Installers/Validate-PostgreSQL.ps1 +++ b/images/win/scripts/Installers/Validate-PostgreSQL.ps1 @@ -1,35 +1,17 @@ -$PGUSER="postgres" -function Validate-PostgreSQL { - $pgready = Start-Process -FilePath pg_isready -Wait -PassThru - $exitCode = $pgready.ExitCode - if ($exitCode -eq 0) - { - Write-Host -Object "PostgreSQL has been successfully installed." - } - else - { - Write-Host -Object "PostgreSQL is not ready. Exitcode: $exitCode" - exit $exitCode - } -} - -$paths = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName -$pgservice = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").Name -$pgroot = $paths.split('"')[1].replace("\bin\pg_ctl.exe", "") -$psqlVersion = pg_config --version | Out-String -Validate-PostgreSQL - -# Adding description of the software to Markdown -$SoftwareName = "PostgreSQL" -$Description = @" -_Version:_ $psqlVersion
-_Default Path:_ $pgroot
-_User:_ $env:PGUSER
-_Password:_ $env:PGPASSWORD -"@ +$pgReady = Start-Process -FilePath pg_isready -Wait -PassThru +$exitCode = $pgReady.ExitCode -Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description +if ($exitCode -eq 0) +{ + Write-Host -Object "PostgreSQL has been successfully installed." +} +else +{ + Write-Host -Object "PostgreSQL is not ready. Exitcode: $exitCode" + exit $exitCode +} #Stop and disable PostgreSQL service -Stop-Service -Name $pgservice -Set-Service $pgservice -StartupType Disabled +$pgService = Get-Service -Name postgresql* +Stop-Service -InputObject $pgService +Set-Service -InputObject $pgService -StartupType Disabled diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 new file mode 100644 index 000000000000..4f8de67f8b6d --- /dev/null +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 @@ -0,0 +1,41 @@ +function Get-PostgreSQLMarkdown +{ + $name = "PostgreSQL" + $pgService = Get-Service -Name postgresql* + $pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName + $pgRoot = $pgPath.split('"')[1].replace("\bin\pg_ctl.exe", "") + $pgVersion = (pg_config --version).split()[1].Trim() + $content = [PSCustomObject]@{ + Version = $pgVersion + UserName = $env:PGUSER + Password = $env:PGPASSWORD + Path = $pgRoot + ServiceName = $pgService.Name + ServiceStatus = $pgService.Status + ServiceStartType = $pgService.StartType + } | New-MDTable + + Build-MarkdownElement -Head $name -Content $content +} + +function Get-MongoDBMarkdown +{ + $name = "MongoDB" + $mongoService = Get-Service -Name $name + $mongoVersion = (Get-Command -Name 'mongo').Version.ToString() + $content = [PSCustomObject]@{ + Version = $mongoVersion + ServiceName = $name + ServiceStatus = $mongoService.Status + ServiceStartType = $mongoService.StartType + } | New-MDTable + Build-MarkdownElement -Head $name -Content $content +} + +function Build-DatabasesMarkdown +{ + $markdown = "" + $markdown += Get-PostgreSQLMarkdown + $markdown += Get-MongoDBMarkdown + $markdown +} \ No newline at end of file diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index a7617a4c4eed..903d394768f0 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -2,13 +2,14 @@ Install-Module MarkdownPS -Force -Scope AllUsers Import-Module MarkdownPS -Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Helpers.psm1") -DisableNameChecking -Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Common.psm1") -DisableNameChecking -Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Tools.psm1") -DisableNameChecking +Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Android.psm1") -DisableNameChecking Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Browsers.psm1") -DisableNameChecking Import-Module (Join-Path $PSScriptRoot "SoftwareReport.CachedTools.psm1") -DisableNameChecking +Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Common.psm1") -DisableNameChecking +Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Databases.psm1") -DisableNameChecking +Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Helpers.psm1") -DisableNameChecking +Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Tools.psm1") -DisableNameChecking Import-Module (Join-Path $PSScriptRoot "SoftwareReport.VisualStudio.psm1") -DisableNameChecking -Import-Module (Join-Path $PSScriptRoot "SoftwareReport.Android.psm1") -DisableNameChecking $markdown = "" @@ -127,6 +128,10 @@ $markdown += New-MDHeader "Cached Tools" -Level 3 $markdown += (Build-CachedToolsMarkdown) $markdown += New-MDNewLine +$markdown += New-MDHeader "Databases" -Level 3 +$markdown += Build-DatabasesMarkdown +$markdown += New-MDNewLine + $vs = Get-VisualStudioVersion $markdown += New-MDHeader "$($vs.Name)" -Level 3 $markdown += $vs | New-MDTable From ffb8a3b1e93121e16ef96cdfc5e9f5310c251148 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov Date: Wed, 3 Jun 2020 10:40:26 +0300 Subject: [PATCH 2/2] update pg service --- .../scripts/SoftwareReport/SoftwareReport.Databases.psm1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 index 4f8de67f8b6d..ed16fab42ef9 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Databases.psm1 @@ -1,8 +1,8 @@ function Get-PostgreSQLMarkdown { $name = "PostgreSQL" - $pgService = Get-Service -Name postgresql* - $pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").PathName + $pgService = Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'" + $pgPath = $pgService.PathName $pgRoot = $pgPath.split('"')[1].replace("\bin\pg_ctl.exe", "") $pgVersion = (pg_config --version).split()[1].Trim() $content = [PSCustomObject]@{ @@ -11,8 +11,8 @@ function Get-PostgreSQLMarkdown Password = $env:PGPASSWORD Path = $pgRoot ServiceName = $pgService.Name - ServiceStatus = $pgService.Status - ServiceStartType = $pgService.StartType + ServiceStatus = $pgService.State + ServiceStartType = $pgService.StartMode } | New-MDTable Build-MarkdownElement -Head $name -Content $content