Apps/Get-Miniconda.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
30
31
32
33
34
35
36
37
38
39
40
41
42
try {

    #Get hashes of all releases
    $FileNames = @{}
    ((Invoke-Webrequest -Uri 'https://raw.githubusercontent.com/conda/conda-docs/master/docs/source/miniconda_hashes.rst' -DisableKeepAlive -UseBasicParsing).Content |
    Select-String -Pattern '(Miniconda\S+\.exe).+(\w{64})' -AllMatches).Matches | ForEach-Object {
        $FileNames.Add($_.Groups[2].Value, $_.Groups[1].Value)
    }

    #Get all links from main download page, swap URLs with 'latest' in filename for the proper versioned name via hash matching and extract properties from filename
    ((Invoke-Webrequest -Uri 'https://raw.githubusercontent.com/conda/conda-docs/master/docs/source/miniconda.rst' -DisableKeepAlive -UseBasicParsing).Content |
    Select-String -Pattern '(http\S+(Miniconda\d)-\S+-Windows-(x86(?:_64)?)\.exe).+(\w{64})' -AllMatches).Matches | ForEach-Object {

        $URL = $_.Groups[1].Value
        $Name = $_.Groups[2].Value

        $Architecture = $_.Groups[3].Value
        if ($Architecture -eq 'x86_64') {
            $Architecture = 'x64'
        }

        $Hash = $_.Groups[4].Value

        if ($URL -match 'latest' -and $Hash -in $FileNames.Keys) {
            $URL = $URL -replace '[^/]+$',$FileNames[$Hash]
        }

        $Version = $URL | Get-Version

        if ($URL -match 'py(\d+)') {
            $Channel = "Python $($matches[1].Insert(1,'.'))"
        }

        if (Resolve-Uri $URL) {
            New-NevergreenApp -Name $Name -Channel $Channel -Architecture $Architecture -Type 'Exe' -Version $Version -Uri $URL -SHA256 $Hash
        }

    }
}
catch {
    Write-Error "$($MyInvocation.MyCommand): $($_.Exception.Message)"
}