-
Notifications
You must be signed in to change notification settings - Fork 1
/
find-latest-version
executable file
·63 lines (44 loc) · 1.75 KB
/
find-latest-version
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
#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - find-latest-version Copyright(c) 2019 cPanel, L.L.C.
# All rights Reserved.
# [email protected] http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
package ea_sourceguardian::find_latest_version;
use strict;
use warnings;
use HTML::TreeBuilder::XPath ();
use FindBin;
use lib "$FindBin::Bin/../ea-tools/lib/ea4_tool"; # assumes ea-tools is checked out next to this repo
use ea4_tool::util ();
ea4_tool::util::find_latest_version( \&_get_required, \&_add_sum ) if !caller();
###############
#### helpers ##
###############
sub _get_required {
my ($http) = @_;
my $res = $http->get("https://www.sourceguardian.com/loaders.html");
if ( !$res->{success} ) {
die "Could not GET sourceguardian info ($res->{status} $res->{reason})\n";
}
my $version = _get_version_from_html( $res->{content} );
my $name = "loaders.linux-x86_64.tar.bz2";
my $url = "https://www.sourceguardian.com/loaders/download/loaders.linux-x86_64.tar.bz2";
return ( $version, $url, $name );
}
sub _add_sum {
my ( $http, $hr ) = @_;
# they don't provide this information
return;
}
sub _get_version_from_html {
my ($html) = @_;
my $dom = HTML::TreeBuilder::XPath->new_from_content($html);
ROW:
for my $row ( $dom->findnodes('//div[@class="tabrow"]'), $dom->findnodes('//div[@class="tabrow grey"]') ) {
my @cells = $row->findnodes_as_strings("span");
next ROW if !@cells || $cells[0] ne "Linux x86_64";
return $cells[4];
}
die "Could not find latest version from HTML\n";
return;
}