This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathupdate.ps1
128 lines (98 loc) · 3.63 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
#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' {
$ext = $Download.file -match '\.exe$' ? 'exe' : 'zip'
crawl 'https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads' |
Where-Object { $_ -match "-win32\.$ext" } | # There is no 64-bit build for Windows currently
Select-Object -First 1
}
'CMake' {
$suffix = $Config.bitness -eq 64 ? 'x86_64' : 'i386'
$ext = $Download.file -match '\.msi$' ? "msi" : "zip"
# CMake does not mark prereleases as such, so we filter based on the tag
getGitHubReleaseAssetUrl 'Kitware/CMake' { $_.name -match "windows-$suffix\.$ext`$" } { $_.tag_name -match '^v([0-9]+\.)+[0-9]$' }
}
'Ninja' {
$newName = 'ninja-win.zip'
getGitHubReleaseAssetUrl 'ninja-build/ninja' { $_.name -eq 'ninja-win.zip' }
}
'Python 3.9' {
$suffix = ''
if ($Download.file -match '\.exe$') {
$suffix = $Config.bitness -eq 64 ? '-amd64\.exe' : '\.exe'
} else {
$suffix = $Config.bitness -eq 64 ? '-embed-amd64\.zip' : '-embed-win32\.zip'
}
crawl 'https://www.python.org/downloads/windows/' |
Where-Object { $_ -match "python-3\.9\.[0-9]+$suffix`$" } |
Select-Object -First 1
}
'Git for Windows' {
$prefix = ''
$ext = 'exe'
if ($Download.file -match '\.zip$') {
$prefix = 'Min'
$ext = 'zip'
}
getGitHubReleaseAssetUrl 'git-for-windows/git' { $_.name -match "^${prefix}Git-([0-9]+\.)+[0-9]+-$($Config.bitness)-bit\.$ext`$" }
}
'NSIS' {
$item = Invoke-RestMethod 'https://sourceforge.net/projects/nsis/rss' |
Where-Object { $_.link -match 'nsis-([0-9]+\.)+[0-9]+\.zip' } |
Select-Object -First 1
$newName = $Matches[0]
$item.link
}
'MSYS2' {
$newName = 'msys2.exe'
getGitHubReleaseAssetUrl 'msys2/msys2-installer' { $_.name -match "^msys2-base-x86_64-[0-9]+\.sfx\.exe`$" }
}
'pandoc' {
getGitHubReleaseAssetUrl 'jgm/pandoc' { $_.name -match "^pandoc-([0-9]+\.)+[0-9]+-windows-x86_64\.zip`$" }
}
}
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', 'x64-standalone.json')) {
$config = Get-Content ".\config\$arch" | ConvertFrom-Json
foreach ($i in $config.downloads) {
updateDownloadUrl $i $config
}
$config | ConvertTo-Json -Depth 3 | Set-Content ".\config\$arch"
}
$tools = Get-Content '.\config\tools.json' | ConvertFrom-Json
foreach ($i in $tools.tools) {
updateDownloadUrl $i $tools
}
$tools | ConvertTo-Json -Depth 3 | Set-Content '.\config\tools.json'