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
71 stars 16 forks source link

[New App Request] Workleap ShareGate (On Proposals list) #94

Open AScott-WWF opened 2 days ago

AScott-WWF commented 2 days ago

Script:

# Get-WorkleapShareGate.ps1

# Define AppName
$AppName = "Sharegate Desktop"

# The ShareGate Migration Tool Download page (https://sharegate.com/download-migration-tool) uses JavaScript (assumed to to prevent the webpage being scraped),
# So we can not use the normal method, but thanks to CoPilot I have discovered ShareGate provide a php url (JSON file) with all the information we require:
$ReleaseUrl = "https://sharegate.com/app/themes/one-sharegate/editor/blocks/desktop-download/fetch-migration-tool.php"
$InstallInstructionsUrl = "https://documentation.sharegate.com/hc/en-us/articles/115000597267-Install-ShareGate-s-migration-tool"

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

$Headers = @{
    "accept" = "*/*"
    "accept-language" = "en-GB,en;q=0.5"
    "User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0"
    "Host" = "sharegate.com"
}

# Fetch the JSON content
$jsonContent = Invoke-RestMethod -Uri $ReleaseUrl -Headers $Headers

# Main script to fetch and process links
$AppVersions = @(
    @{AppName = $($AppName); Type = 'msi'}
)

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

    #Build each link with File Type specific versions
    [version]$Version = Get-Version -String $($jsonContent.Version)
    $URL = $($jsonContent.DownloadUrl)
    #$URL = (Resolve-Uri -Uri $($jsonContent.DownloadUrl) -Headers $Headers).Uri
    $ReleaseNotesUrl = $($jsonContent.DescriptionLink)
    #$ReleaseNotesUrl = (Resolve-Uri -Uri $($jsonContent.DescriptionLink) -Headers $Headers).Uri

    do {
        if ($URL) {
            New-NevergreenApp -Name $($AppVersion.AppName) -Version $($Version) -Uri $($URL) -Architecture 'multi' -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)"