-
Notifications
You must be signed in to change notification settings - Fork 11
/
updater.ps1
45 lines (37 loc) · 1.75 KB
/
updater.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
function Get-RemoteSHA256 {
param(
[Parameter(Mandatory = $true)]
[string]$Url
)
(Get-FileHash -Algorithm SHA256 -InputStream ([System.Net.WebClient]::new().OpenRead($url))).Hash.ToLower()
}
$channel = "https://pkgs.tailscale.com/stable/"
$meta = Invoke-WebRequest ($channel + "?mode=json&os=windows") | ConvertFrom-Json
$version = $meta.Version
# Update the nuspec
$nuspec = New-Object xml
$nuspec.Load("$PSScriptRoot/tailscale.nuspec")
$nuspec.package.metadata.version = $version
$nuspec.Save("$PSScriptRoot/tailscale.nuspec")
# Update the installer script
$installer = Get-Content "./tools/chocolateyinstall.ps1"
$url = $channel + $meta.MSIs.arm64
$installer[19] = $installer[19] -replace "https:\/\/pkgs.tailscale.com\/.*\.msi", $url
$installer[20] = $installer[20] -replace "[0-9a-f]{64}", (Get-RemoteSHA256 $url)
$url = $channel + $meta.MSIs.x86
$installer[27] = $installer[27] -replace "https:\/\/pkgs.tailscale.com\/.*\.msi", $url
$installer[28] = $installer[28] -replace "[0-9a-f]{64}", (Get-RemoteSHA256 $url)
$url = $channel + $meta.MSIs.amd64
$installer[31] = $installer[31] -replace "https:\/\/pkgs.tailscale.com\/.*\.msi", $url
$installer[32] = $installer[32] -replace "[0-9a-f]{64}", (Get-RemoteSHA256 $url)
$installer | Out-File "./tools/chocolateyinstall.ps1"
# Check and see if files have been updated
$files_modified = $(git diff --name-only HEAD) -split '\n'
if ($files_modified.length -gt 0) {
git commit -a -m "Update to version $version"
Write-Host "Package files have been updated to version $version. Update has been committed and is ready to push. Displaying diff..."
git diff HEAD~1 HEAD
}
else {
Write-Host "No files have been updated. No commit has been made."
}