This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.ps1
94 lines (75 loc) · 3.73 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
[CmdletBinding()]
param($IncludeStream)
Import-Module AU
Import-Module Microsoft.PowerShell.SecretManagement
$sparkleUri = 'https://www.facebook.com/messenger/desktop/zeratul/update.xml?target=zeratul&platform=win'
$userAgent = 'Update checker of Chocolatey Community Package ''messenger'''
function global:au_BeforeUpdate($Package) {
#Archive this version for future development, since the vendor does not guarantee perpetual availability
$filePath = ".\Messenger.$($Latest.Version).exe"
Invoke-WebRequest -Uri $Latest.Url64 -OutFile $filePath
$Latest.Checksum64 = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash.ToLower()
if ((Get-Command -Name 'vt' -CommandType Application -ErrorAction SilentlyContinue)) {
vt.exe scan file "$filePath" --silent
}
else {
Write-Warning 'VirusTotal CLI is not available - skipping VirusTotal submission'
}
Set-DescriptionFromReadme -Package $Package -ReadmePath '.\DESCRIPTION.md'
}
function global:au_SearchReplace {
@{
"$($Latest.PackageName).nuspec" = @{
'(<packageSourceUrl>)[^<]*(</packageSourceUrl>)' = "`$1https://github.com/brogers5/chocolatey-package-$($Latest.PackageName)/tree/v$($Latest.Version)`$2"
'(\<copyright\>).*?(\<\/copyright\>)' = "`${1}© Meta $(Get-Date -Format yyyy)`$2"
}
'tools\chocolateyinstall.ps1' = @{
'(^[$]?\s*url64bit\s*=\s*)(''.*'')' = "`$1'$($Latest.Url64)'"
'(^[$]?\s*checksum64\s*=\s*)(''.*'')' = "`$1'$($Latest.Checksum64)'"
}
}
}
function Get-VersionInfo($ReleaseItem) {
$sparkleVersion = $ReleaseItem.enclosure.version
$shortVersionString = $releaseItem.enclosure.shortVersionString
$splitVersionString = $shortVersionString.Split('.')
$productVersion = "$($splitVersionString[0]).$($splitVersionString[1]).$sparkleVersion"
return @{
Url64 = "https://www.facebook.com/zeratul/desktop/update/$sparkleVersion.exe"
Version = $productVersion
}
}
function Get-LatestBetaVersionInfo {
$webSession = New-Object -TypeName 'Microsoft.PowerShell.Commands.WebRequestSession'
$cookieUri = 'https://www.facebook.com/'
$facebookUserID = Get-Secret -Name 'Facebook User ID' -AsPlainText
$c_userCookie = New-Object -TypeName 'System.Net.Cookie' -ArgumentList ('c_user', $facebookUserID)
$c_userCookie.Secure = $true
$webSession.Cookies.Add($cookieUri, $c_userCookie)
$facebookSessionID = Get-Secret -Name 'Facebook Session ID' -AsPlainText
$xsCookie = New-Object -TypeName 'System.Net.Cookie' -ArgumentList ('xs', $facebookSessionID)
$xsCookie.Secure = $true
$xsCookie.HttpOnly = $true
$webSession.Cookies.Add($cookieUri, $xsCookie)
$releaseItem = Invoke-RestMethod -Uri $sparkleUri -UserAgent $userAgent -WebSession $webSession -UseBasicParsing
$versionInfo = Get-VersionInfo -ReleaseItem $releaseItem
$versionInfo.Version += '-beta'
return $versionInfo
}
function Get-LatestStableVersionInfo {
$releaseItem = Invoke-RestMethod -Uri $sparkleUri -UserAgent $userAgent -UseBasicParsing
return Get-VersionInfo -ReleaseItem $releaseItem
}
function global:au_GetLatest {
$streams = [Ordered] @{
Beta = Get-LatestBetaVersionInfo
Stable = Get-LatestStableVersionInfo
}
if ($streams.Beta.Version -eq "$($streams.Stable.Version)-beta") {
Write-Warning 'The queried Beta version is identical to the Stable version!'
Write-Warning 'Your account may not have joined Messenger''s beta testing, or the secrets improperly configured.'
Write-Warning 'The session ID secret may have also expired and requires a refresh.'
}
return @{ Streams = $streams }
}
Update-Package -ChecksumFor None -IncludeStream $IncludeStream -NoReadme