Skip to content

Commit

Permalink
Merge pull request #2301 from JPRuskin/fix-prey
Browse files Browse the repository at this point in the history
(prey) Fixes Update.ps1 (HTML parsing)
  • Loading branch information
pauby authored Dec 21, 2023
2 parents e06365b + e941fa6 commit 1fdcc44
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions automatic/prey/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
param($IncludeStream, [switch]$Force)
Import-Module AU

$releases = 'https://github.com/prey/prey-node-client/releases'

function global:au_BeforeUpdate { Get-RemoteFiles -Purge -NoSuffix }

function global:au_SearchReplace {
Expand All @@ -26,28 +24,26 @@ function global:au_SearchReplace {
function global:au_AfterUpdate { Update-Metadata -key 'releaseNotes' -value $Latest.ReleaseNotes }

function global:au_GetLatest {
$download_page = Invoke-WebRequest -Uri $releases -UseBasicParsing
$latestRelease = Get-GitHubRelease -Owner "Prey" -Name "Prey-Node-Client"

$re = 'x86\.msi$'
$urls32 = $download_page.Links | ? href -match $re | select -expand href | % { 'https://github.com' + $_ }
$urls32 = $latestRelease.assets.Where{$_.name -match $re}.browser_download_url

$re = 'x64\.msi$'
$urls64 = $download_page.links | ? href -match $re | select -expand href | % { 'https://github.com' + $_ }
$urls64 = $latestRelease.assets.Where{$_.name -match $re}.browser_download_url

$streams = @{}
$urls32 | % {
$verRe = '\/[v\.]{0,2}'
$version = $_ -split "$verRe" | select -last 1 -skip 1
$version = Get-Version $version
$url64 = $urls64 | ? { $_ -match "${verRe}$version" } | select -First 1
$urls32 | ForEach-Object {
$version = Get-Version $latestRelease.tag_name.TrimStart('v')
$url64 = $urls64 | Where-Object { $_ -match "\/[v\.]{0,2}$version" } | Select-Object -First 1
if (!($url64)) { throw "URL64 was not found for version $version" }

if (!($streams.ContainsKey($version.ToString(2)))) {
$streams.Add($version.ToString(2), @{
Version = $version.ToString()
URL32 = $_
URL64 = $url64
ReleaseNotes = "${releases}/tag/v${version}"
ReleaseNotes = $latestRelease.html_url
})
}
}
Expand Down

0 comments on commit 1fdcc44

Please sign in to comment.