-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathupdate.ps1
131 lines (103 loc) · 3.75 KB
/
update.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#Requires -Version 7.0
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
. "$PSScriptRoot\common.ps1"
function getGitHubReleaseAssetUrl {
param (
[string] $Repo,
[scriptblock] $AssetFilter,
[scriptblock] $ReleaseFilter = { $_.prerelease -eq $false }
)
$rel = (Invoke-RestMethod "https://api.github.com/repos/$Repo/releases") |
Where-Object $ReleaseFilter |
Select-Object -First 1
$asset = $rel.assets |
Where-Object $AssetFilter
$asset.browser_download_url
}
function updateDownloadUrl {
param (
$Download,
$Config
)
Write-Host "Updating $($Download.name): " -NoNewline
$newName = $null # Override local filename if needed
[uri]$newUrl = switch ($Download.name) {
'GNU Arm Embedded Toolchain' {
crawl 'https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads' |
Where-Object { $_ -match "-win32\.exe" } | # There is no 64-bit build for Windows currently
Select-Object -First 1
}
'CMake' {
$suffix = $Config.bitness -eq 64 ? 'x86_64' : 'i386'
# CMake does not mark prereleases as such, so we filter based on the tag
getGitHubReleaseAssetUrl 'Kitware/CMake' { $_.name -match "windows-$suffix\.msi`$" } { $_.tag_name -match '^v([0-9]+\.)+[0-9]$' }
}
'Python 3.9' {
$suffix = $Config.bitness -eq 64 ? '-amd64' : ''
crawl 'https://www.python.org/downloads/windows/' |
Where-Object { $_ -match "python-3\.9\.[0-9]+$suffix\.exe`$" } |
Select-Object -First 1
}
'Git for Windows' {
getGitHubReleaseAssetUrl 'git-for-windows/git' { $_.name -match "^Git-([0-9]+\.)+[0-9]+-$($Config.bitness)-bit\.exe`$" }
}
'Doxygen' {
crawl 'https://www.doxygen.nl/download.html' |
Where-Object { $_ -match "-setup\.exe" } |
Select-Object -First 1
}
'Graphviz' {
$link = (Invoke-WebRequest 'https://graphviz.org/download/' -UseBasicParsing).Links |
Where-Object { $_.outerHTML -match "-win$($Config.bitness)\.exe" } |
Select-Object -First 1
if ($link.outerHTML -match '[a-zA-Z0-9_\-\.]+\.exe') {
$newName = $Matches[0]
$link.href
}
}
'NSIS' {
$newName = 'nsis.zip'
$item = Invoke-RestMethod 'https://sourceforge.net/projects/nsis/rss' |
Where-Object { $_.link -match 'nsis-([0-9]+\.)+[0-9]+\.zip' } |
Select-Object -First 1
$item.link
}
'NSIS with logging' {
$newName = 'nsis-log.zip'
$item = Invoke-RestMethod 'https://sourceforge.net/projects/nsis/rss' |
Where-Object { $_.link -match 'nsis-([0-9]+\.)+[0-9]+\-log.zip' } |
Select-Object -First 1
$item.link
}
'MSYS2' {
$newName = 'msys2.exe'
getGitHubReleaseAssetUrl 'msys2/msys2-installer' { $_.name -match "^msys2-base-x86_64-[0-9]+\.sfx\.exe`$" }
}
'vswhere' {
$newName = 'vswhere.exe'
getGitHubReleaseAssetUrl 'microsoft/vswhere' { $_.name -eq 'vswhere.exe' }
}
}
if ($newUrl) {
$newName ??= $newUrl.Segments[-1]
Write-Host $newName
$Download.file = $newName
$Download.href = $newUrl.AbsoluteUri
} else {
Write-Host "No update"
}
}
foreach ($arch in @('x86.json', 'x64.json')) {
$config = Get-Content $arch | ConvertFrom-Json
foreach ($i in $config.installers) {
updateDownloadUrl $i $config
}
$config | ConvertTo-Json -Depth 3 | Set-Content $arch
}
$tools = Get-Content '.\tools.json' | ConvertFrom-Json
foreach ($i in $tools.tools) {
updateDownloadUrl $i $tools
}
$tools | ConvertTo-Json -Depth 3 | Set-Content '.\tools.json'