Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New App request] PostgreSQL #121

Open
AScott-WWF opened this issue Sep 30, 2024 · 2 comments
Open

[New App request] PostgreSQL #121

AScott-WWF opened this issue Sep 30, 2024 · 2 comments

Comments

@AScott-WWF
Copy link

Seen a request for PostgreSQL to be included with Evergreen (aaronparker/evergreen#747), but Aaron has been unable to find a source, so I have quickly knocked up this script which queries the downloads page: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
It's not the best code I'll admit (partly due to the webpage layout)- But I'm sure with time it could be improved!

# Get-PostgreSQL.ps1

$AppName = "PostgreSQL"

# Define the URL of the PostgreSQL Downloads page
$Releaseurl = "https://www.enterprisedb.com/downloads/postgres-postgresql-downloads"

Write-Verbose "Obtaining $($AppName) Release Versions from $($ReleaseUrl)...`n"

# Use Invoke-WebRequest to get the HTML content
$response = Invoke-WebRequest -Uri $Releaseurl

# Load the HTML content
$htmlContent = $response.Content

# Use regex to extract the links for Windows x86-64 and x86-32
$pattern = '<tr.*?>.*?<td.*?>(.*?)<\/td>.*?<td.*?>(.*?)<\/td>.*?<td.*?>(.*?)<\/td>.*?<td.*?>(.*?)<\/td>.*?<td.*?>(.*?)<\/td>.*?<td.*?>(.*?)<\/td>.*?<\/tr>'
$patternmatches = [regex]::Matches($htmlContent, $pattern)

# Initialize an array to hold the links
$links = @()

# Loop through each match
foreach ($match in $patternmatches) {
    # Extract the PostgreSQL Version from table (in case version can not be obtained from URL)
    $PostgreSQLVersion = $match.Groups[1].Value
    # Extract the href links for Windows x86-64 and x86-32
    $x64Link = $match.Groups[5].Value -replace '.*?href="(.*?)".*', '$1'
    $x32Link = $match.Groups[6].Value -replace '.*?href="(.*?)".*', '$1'
    
    # Add the links to the array if they exist
    if ($x64Link) {
		$Arch = "x64"
        $SearchCount = 1 # This may need increasing as future versions are released
        if ($x64Link -like "*getfile.jsp?fileid=*"){
            $URL = (Resolve-Uri -Uri $x64Link).Uri
			$Version = Get-Version -String $URL -ReplaceWithDot
        } elseif ($x64Link -like "/postgres-postgresql-downloads"){
			$URL = Set-UriPrefix -Uri $x64Link -Prefix 'https://www.enterprisedb.com'
		} else {
            $URL = $x64Link
			$Version = Get-Version -String $URL -ReplaceWithDot
        }
		if ($null -eq $Version) {
			$Version = $PostgreSQLVersion
		}
		Write-Verbose "Version $($Version) 64-bit download: $($x64Link)"
        do {
			if ($URL) {
				New-NevergreenApp -Name $($AppName) -Architecture $($Arch) -Version $Version -Uri $($URL) -Type "exe"
				break
			}

			$SearchCount--
		} until ($SearchCount -eq 0)

		if ($SearchCount -eq 0) {
			Write-Warning "Could not find release for $($AppName) $($Version) $($Arch)"
		}
    }
	$URL = $null
	$Version = $null
	$Arch = $null
	
    if ($x32Link) {
		$Arch = "x86"
        $SearchCount = 1 # This may need increasing as future versions are released
		if ($x32Link -ne "<span>Not supported</span>"){
            if ($x32Link -like "*getfile.jsp?fileid=*"){
                $URL = (Resolve-Uri -Uri $x32Link).Uri
				$Version = Get-Version -String $URL -ReplaceWithDot
            } elseif ($x32Link -like "/postgres-postgresql-downloads"){
				$URL = Set-UriPrefix -Uri $x32Link -Prefix 'https://www.enterprisedb.com'
			} else {
                $URL = $x32Link
                $Version = Get-Version -String $URL -ReplaceWithDot
            }
        }
		if ($null -eq $Version) {
			$Version = $PostgreSQLVersion
		}
		Write-Verbose "Version $($Version) 32-bit download: $($x32Link)"
        do {
			if ($URL) {
				New-NevergreenApp -Name $($AppName) -Architecture $($Arch) -Version $($Version) -Uri $($URL) -Type "exe"
				break
			}

			$SearchCount--
		} until ($SearchCount -eq 0)

		if ($SearchCount -eq 0) {
			Write-Warning "Could not find release for $($AppName) $($Version) $($Arch)"
		}
    }
	$URL = $null
	$Version = $null
	$Arch = $null
}
@bmitchell76
Copy link

@DanGough, will this be added to Nevergreen?

@DanGough
Copy link
Owner

Happy to add this eventually. However my plans are currently:

  • add some new functions that will allow a lot of apps to be scraped in a single command
  • refactor existing apps to use these, learn from them and improve said functions
  • then implement the backlog of app requests that has built up!

I should have some time to get on with this later in October.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants