use github release feature

This commit is contained in:
Oliver Gorwits
2017-04-14 20:38:21 +01:00
parent 7a2fa272b6
commit 79b1520126

View File

@@ -54,6 +54,7 @@ use File::Slurp ();
use HTTP::Tiny;
use Digest::MD5;
use Try::Tiny;
use File::Path ();
use Encode;
=head1 NAME
@@ -273,24 +274,43 @@ sub shorten {
}
sub deploy_mibs {
my $mibhome = dir(shift);
my $mibhome = dir(shift); # /path/to/netdisco-mibs
my $fail = 0;
my $url = 'http://downloads.sourceforge.net/project/netdisco/netdisco-mibs/latest-snapshot/netdisco-mibs-snapshot.tar.gz';
my $file = file($home, 'netdisco-mibs-snapshot.tar.gz');
my $resp = HTTP::Tiny->new->mirror($url, $file);
my $latest = 'https://github.com/netdisco/netdisco-mibs/releases/latest';
my $resp = HTTP::Tiny->new->get($latest);
if (exists $resp->{redirects} and $resp->{url} =~ m/([0-9.]+)$/) {
my $ver = $1;
my $url = 'https://codeload.github.com/netdisco/netdisco-mibs/tar.gz/'. $ver;
my $file = file($home, 'netdisco-mibs-latest.tar.gz');
$resp = HTTP::Tiny->new->mirror($url, $file);
if ($resp->{success}) {
my $ae = Archive::Extract->new(archive => $file, type => 'tgz');
$ae->extract(to => $mibhome->parent->stringify);
unlink $file;
print color 'bold blue';
say 'MIBs update complete.';
my $from = file($mibhome->parent->stringify, "netdisco-mibs-$ver");
my $to = file($mibhome->parent->stringify, 'netdisco-mibs');
if (-d $from) {
File::Path::remove_tree($to, { verbose => 0 });
File::Copy::move($from, $to);
}
else {
unlink $file;
}
else { ++$fail }
}
else { ++$fail }
if ($fail) {
print color 'bold red';
say 'MIB download failed!';
}
else {
print color 'bold blue';
say 'MIBs update complete.';
}
print color 'reset';
}