DanGough / Nevergreen

This module is an alternative to Evergreen, and allows you to find the latest version and download URL for various Windows apps. Evergreen uses API queries to obtain its data whereas this module is more focussed on web scraping. This is more prone to breaking when websites are changed, hence the name.
The Unlicense
77 stars 18 forks source link

[New App Request] TortoiseSVN (On Proposals list) #97

Open AScott-WWF opened 4 months ago

AScott-WWF commented 4 months ago

N.B. As TortoiseSVN files are hosted on SourceForge, a certain amount of URL manipulation needs to be carried out. Also to ensure the files are served from different SourceForge mirrors, a list of Mirrors is contained in $SFMirrorList the mirror is randomly chosen into $SFMirror before generating the URLs - therefore each run of the script is likely to present different SourceForge domains to the file locations.

Script:

# Get-TortoiseSVN.ps1

# Define AppName
$AppName = "TortoiseSVN"

# Main script to fetch and process links
$ReleaseUrl = "https://tortoisesvn.net/downloads.html"
$InstallInstructionsUrl = "https://tortoisesvn.net/faq.html#uninstallfirst"

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

$AppVersions = @(
        @{Architecture = 'x86'; Type = 'msi'; Pattern = 'Download TortoiseSVN \d+\.\d+\.\d+ - 32-bit, linked to SVN'; VersionPattern = 'TortoiseSVN-(\d+\.\d+\.\d+\.\d+)-'}
        @{Architecture = 'x64'; Type = 'msi'; Pattern = 'Download TortoiseSVN \d+\.\d+\.\d+ - 64-bit, linked to SVN'; VersionPattern = 'TortoiseSVN-(\d+\.\d+\.\d+\.\d+)-'}
        @{Architecture = 'ARM64'; Type = 'msi'; Pattern = 'Download TortoiseSVN \d+\.\d+\.\d+ - ARM64, linked to SVN'; VersionPattern = 'TortoiseSVN-(\d+\.\d+\.\d+\.\d+)-'}
)

# As Tortoise SVN downloads are hosted on SourceForge, the download should be pulled from of their mirrors randomly
# List of SourceForge Mirrors
$SFMirrorList =@('netcologne','kumisystems','netix','unlimited','deac-riga','deac-fra','yer','psychz','pilotfiber','netactuate','icolo','altushost-swe','liquidtelecom',
'cfhcable','gigenet','webwerks','cytranet-dal','versaweb','phoenixnap','tenet','sinalbr','jaist','zenlayer','udomain','nchc','razaoinfo','sitsa','onboardcloud','freefr',
'excellmedia','ixpeering')

$SFMirror = Get-Random -InputObject $SFMirrorList # Select random mirror
#Write-Verbose "SourceForge Mirror :: $($SFMirror)`n" #N.B. Uris will likely be different on each run

foreach ($AppVersion in $AppVersions) {
    $SearchCount = 1 # This may need increasing as future versions are released

    #Build each link with File Type specific versions
    $SFURL = (Get-Link -Uri $ReleaseUrl -MatchProperty outerHTML -Pattern $($AppVersion.Pattern)) # Linked SourceForge URL
    # Manipulate address of returned URL to gain actual file download
        $StripendURL = ($($SFURL) -split "/download")[0] #if exists, remove trailing /download and everything subsequent
        $CarveURL = $($StripendURL) -replace "s/tortoisesvn/files","/tortoisesvn" # Carve up URL - to use with other SourceForge Mirrors
        $URL = ($($CarveURL) -replace "sourceforge.net","$($SFMirror).dl.sourceforge.net")+"?viasf=1" # Define SourceForge Mirror to download file from and append '?viasf=1'

    [version]$Version = (Get-Version -String $URL -Pattern $AppVersion.VersionPattern)
    $ReleaseNotesUrl = "https://tortoisesvn.net/tsvn_$($Version.Major).$($Version.Minor)_releasenotes.html"

    do {
        if ($URL) {
            New-NevergreenApp -Name $AppName -Version $Version -Uri $URL -Architecture $AppVersion.Architecture -Type $($AppVersion.Type)
            break
        }

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

    if ($SearchCount -eq 0) {
        Write-Warning "Could not find release for $($AppName) $($AppVersion.Type)"
    }
}

Write-Verbose "$($AppName) (Version: $($Version)) Release notes are available here: $($ReleaseNotesUrl)"
Write-Verbose "$($AppName) Install instructions are available here: $($InstallInstructionsUrl)"