-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-latest-version
executable file
·63 lines (42 loc) · 2.04 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) 2020 cPanel, L.L.C.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
package ea_mod_security30_connector_nginx::find_latest_version;
use strict;
use warnings;
use lib "../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://api.github.com/repos/owasp-modsecurity/ModSecurity-nginx/releases");
if ( !$res->{success} ) {
die "Could not GET ModSecurity info from github ($res->{status} $res->{reason})\n\t Throttled? `curl -I https://api.github.com/rate_limit 2>&1 | grep ^X-RateLimit`\n";
}
my ($version) = sort { ea4_tool::util::numerical_only_version_compare( $a, $b ); } map { $_->{tag_name} } @{ ea4_tool::util::json2ref( $res->{content} ) };
die "Could not determine version from github\n" if !$version;
my $name = "$version.tar.gz";
my $url = "https://github.com/owasp-modsecurity/ModSecurity-nginx/archive/$name";
$version =~ s/^v//;
return ( $version, $url, $name );
}
sub _add_sum {
my ( $http, $hr ) = @_;
# Optional: Set $hr->{tarball}{sum}{hex} and $hr->{tarball}{sum}{type} (sha256, sha1, md5, anything Digest.pm can handle)
# die if there is a problem determining either of those values
# otherwise this is a no-op
return;
}
__END__
=encoding utf-8
=head1 README
We can add checksum support if github releases had that information which isn’t available via:
=over
=item API call L<https://developer.github.com/v3/repos/releases/#get-the-latest-release>
=item web view L<https://github.com/owasp-modsecurity/ModSecurity-nginx/releases>
=back