private/Get-ChocolateyDownloadUri.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function Get-ChocolateyDownloadUri() {

    $uri = $null;
    $chocolateyVersion = $Env:ChocolateyVersion
    $chocolateyDownloadUrl = $Env:ChocolateyDownloadUrl

    if (![string]::IsNullOrEmpty($chocolateyVersion)){
        Write-Debug "Downloading specific version of Chocolatey: $chocolateyVersion"
        $uri = "https://chocolatey.org/api/v2/package/chocolatey/$chocolateyVersion"
        return $uri;
    }
      
      
    if (![string]::IsNullOrEmpty($chocolateyDownloadUrl)){
        Write-Debug "Downloading Chocolatey from : $chocolateyDownloadUrl"
        $uri = "$chocolateyDownloadUrl"

        return $uri;
    }

    if ([string]::IsNullOrWhiteSpace($uri)) {
        Write-Debug "Getting latest version of the Chocolatey package for download."
        $uri = 'https://chocolatey.org/api/v2/Packages()?$filter=((Id%20eq%20%27chocolatey%27)%20and%20(not%20IsPrerelease))%20and%20IsLatestVersion'
        [xml]$result = Get-WebRequestContentAsString $uri
        $uri = $result.feed.entry.content.src
    }

    return $uri;
}