-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.ps1
79 lines (64 loc) · 3.51 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
Import-Module au
Import-Module PowerShellForGitHub
Import-Module FXPSYaml
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition)
. $currentPath\helpers.ps1
$owner = 'LedgerHQ'
$repository = 'ledger-live'
function global:au_BeforeUpdate($Package) {
#Verify the integrity of the binary, following these instructions:
#https://www.ledger.com/ledger-live/lld-signatures
#Confirm integrity of the published checksums file
Update-OpenSSLPublicKey -TagName $Latest.TagName
Update-ChecksumFile -Version $Latest.SoftwareVersion
Update-SignatureFile -Version $Latest.SoftwareVersion
Confirm-Signature
#Confirm integrity of installer binary
$expectedChecksum = Get-ExpectedChecksum
if ($Latest.Checksum64 -ne $expectedChecksum) {
throw "Published checksums are not consistent!`n
Checksum File: $expectedChecksum
Latest Version Info: $($Latest.Checksum64)"
}
Set-DescriptionFromReadme -Package $Package -ReadmePath '.\DESCRIPTION.md'
}
function global:au_SearchReplace {
@{
'tools\chocolateyInstall.ps1' = @{
'(^[$]?\s*url64bit\s*=\s*)(''.*'')' = "`$1'$($Latest.Url64)'"
'(^[$]?\s*checksum64\s*=\s*)(''.*'')' = "`$1'$($Latest.Checksum64)'"
}
"$($Latest.PackageName).nuspec" = @{
'(<packageSourceUrl>)[^<]*(</packageSourceUrl>)' = "`$1https://github.com/brogers5/chocolatey-package-$($Latest.PackageName)/tree/v$($Latest.Version)`$2"
'(<projectSourceUrl>)[^<]*(</projectSourceUrl>)' = "`$1https://github.com/$owner/$repository/tree/$($Latest.TagName)`$2"
'(\*\*Release Notes:\*\* ).*$' = "`$1https://github.com/$owner/$repository/blob/$($Latest.TagName)/apps/ledger-live-desktop/RELEASE_NOTES.md"
'(\*\*Full Changelog:\*\* ).*$' = "`$1https://github.com/$owner/$repository/releases/tag/$($Latest.TagName)"
'(<copyright>)[^<]*(</copyright>)' = "`$1Copyright © $(Get-Date -Format yyyy) Ledger Live Team`$2"
}
}
}
function global:au_GetLatest {
$userAgent = 'Update checker of Chocolatey Community Package ''ledger-live'''
$latestVersionInfoUri = 'https://download.live.ledger.com/latest-win.yml'
$tempFilePath = New-TemporaryFile
Invoke-WebRequest -Uri $latestVersionInfoUri -UserAgent $userAgent -Method Get -OutFile $tempFilePath
$latestVersionInfo = ConvertFrom-Yaml -Path $tempFilePath
Remove-Item $tempFilePath -Force
$servedVersion = $latestVersionInfo.version
$checksumBytes = [System.Convert]::FromBase64String($latestVersionInfo.sha512)
$checksumString = ($checksumBytes | ForEach-Object ToString x2) -join ''
$releases = Get-GitHubRelease -OwnerName $owner -RepositoryName $repository
$latestRelease = $releases | Where-Object { $_.tag_name -match '@ledgerhq/live-desktop@\d\.(\d){1,2}\.\d' } | Select-Object -First 1
$actualLatestVersion = [version] $latestRelease.tag_name.Substring(23)
if ($servedVersion -lt $actualLatestVersion) {
Write-Warning "A newer tag for Ledger Live Desktop was found (v$actualLatestVersion), but this build has not been published yet!"
}
return @{
Checksum64 = $checksumString
SoftwareVersion = $servedVersion
TagName = "%40ledgerhq/live-desktop%40$servedVersion"
Url64 = "https://download.live.ledger.com/$($latestVersionInfo.path)"
Version = $servedVersion #This may change if building a package fix version
}
}
Update-Package -ChecksumFor None -NoReadme