[Windows] Apply code style rules to Windows scripts (#8957)

* Apply code style rules to Windows scripts

* Fix typo

* Fix configure-toolset script

* Fix parameters in Msys2 installation script

* Improve log readability

* Remove broken exit code validation
This commit is contained in:
Vasilii Polikarpov
2023-12-11 22:23:36 +01:00
committed by GitHub
parent 76d6f0f574
commit 7fe65a2204
54 changed files with 544 additions and 418 deletions

View File

@@ -1,3 +1,8 @@
################################################################################
## File: Install-PostgreSQL.ps1
## Desc: Install PostgreSQL
################################################################################
# Define user and password for PostgreSQL database
$pgUser = "postgres"
$pgPwd = "root"
@@ -10,47 +15,47 @@ $pgPwd = "root"
$toolsetVersion = (Get-ToolsetContent).postgresql.version
$getPostgreReleases = Invoke-WebRequest -Uri "https://git.postgresql.org/gitweb/?p=postgresql.git;a=tags" -UseBasicParsing
# Getting all links matched to the pattern (e.g.a=log;h=refs/tags/REL_14)
$TargetReleases = $getPostgreReleases.Links.href | Where-Object { $_ -match "a=log;h=refs/tags/REL_$toolsetVersion" }
[Int32] $OutNumber = $null
$MinorVersions = @()
foreach ($release in $TargetReleases) {
$targetReleases = $getPostgreReleases.Links.href | Where-Object { $_ -match "a=log;h=refs/tags/REL_$toolsetVersion" }
[Int32] $outNumber = $null
$minorVersions = @()
foreach ($release in $targetReleases) {
$version = $release.split('/')[-1]
# Checking if the latest symbol of the release version is actually a number. If yes, add to $MinorVersions array
if ([Int32]::TryParse($($version.Split('_')[-1]), [ref] $OutNumber)) {
$MinorVersions += $OutNumber
# Checking if the latest symbol of the release version is actually a number. If yes, add to $minorVersions array
if ([Int32]::TryParse($($version.Split('_')[-1]), [ref] $outNumber)) {
$minorVersions += $outNumber
}
}
# Sorting and getting the last one
$TargetMinorVersions = ($MinorVersions | Sort-Object)[-1]
$targetMinorVersions = ($minorVersions | Sort-Object)[-1]
# Install latest PostgreSQL
# In order to get rid of error messages (we know we will have them), force ErrorAction to SilentlyContinue
$ErrorActionOldValue = $ErrorActionPreference
$errorActionOldValue = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
# Starting from number 9 and going down, check if the installer is available. If yes, break the loop.
# If an installer with $TargetMinorVersions is not to be found, the $TargetMinorVersions will be decreased by 1
# If an installer with $targetMinorVersions is not to be found, the $targetMinorVersions will be decreased by 1
$increment = 9
do {
$url = "https://get.enterprisedb.com/postgresql/postgresql-$toolsetVersion.$TargetMinorVersions-$increment-windows-x64.exe"
$checkaccess = [System.Net.WebRequest]::Create($url)
$url = "https://get.enterprisedb.com/postgresql/postgresql-$toolsetVersion.$targetMinorVersions-$increment-windows-x64.exe"
$checkAccess = [System.Net.WebRequest]::Create($url)
$response = $null
$response = $checkaccess.GetResponse()
$response = $checkAccess.GetResponse()
if ($response) {
$InstallerUrl = $response.ResponseUri.OriginalString
$installerUrl = $response.ResponseUri.OriginalString
} elseif (!$response -and ($increment -eq 0)) {
$increment = 9
$TargetMinorVersions--
$targetMinorVersions--
} else {
$increment--
}
} while (!$response)
# 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")
$ErrorActionPreference = $errorActionOldValue
$installerArgs = @("--install_runtimes 0", "--superpassword root", "--enable_acledit 1", "--unattendedmodeui none", "--mode unattended")
Install-Binary `
-Url $InstallerUrl `
-InstallArgs $InstallerArgs `
-Url $installerUrl `
-InstallArgs $installerArgs `
-ExpectedSignature (Get-ToolsetContent).postgresql.signature
# Get Path to pg_ctl.exe