Skip to content

Instantly share code, notes, and snippets.

@jay
Last active June 16, 2017 17:35
Show Gist options
  • Save jay/8c402d72c78ac76d117d to your computer and use it in GitHub Desktop.
Save jay/8c402d72c78ac76d117d to your computer and use it in GitHub Desktop.
Extract the name of the last modified firefox archive from input.
#!/usr/bin/env perl
=begin comment
README
Extract the name of the last modified firefox archive from input.
Which archive is most recent is determined only by comparing 'last modified'
timestamps, the versions are not compared.
curl -fSs https://ftp.mozilla.org/pub/firefox/nightly/latest-mozilla-central/ | extract_last_modified.pl win64
https://bugzilla.mozilla.org/show_bug.cgi?id=1199039
https://gist.github.com/jay/8c402d72c78ac76d117d
=end comment
=cut
use strict;
use warnings;
my $showdate;
if(defined $ARGV[0] && $ARGV[0] eq "--showdate") {
shift;
$showdate = 1;
}
my $platform = shift;
my $accepted = "linux-i686|linux-x86_64|win32|win64";
if(!defined $platform || $platform !~ /^($accepted)$/i) {
die "Usage: extract_last_modified.pl [--showdate] <$accepted> < input\n";
}
my %months = (
jan => "01", feb => "02", mar => "03", apr => "04", may => "05", jun => "06",
jul => "07", aug => "08", sep => "09", oct => "10", nov => "11", dec => "12"
);
my %package = (name => '', datetime => '', datetime_orig => '');
my $input = do { local $/; <STDIN> };
while( $input =~
/ <tr>\s*?
<td>File<\/td>\s*?
<td><a\ href=\"[^\"]*\/?
(firefox-[^\"]+\.en-US\.$platform\.(?:zip|tar\.bz2))\">.*<\/td>\s*?
<td>[0-9a-z]+<\/td>\s*?
<td>(([0-9]{2})-([a-z]{3})-([0-9]{4})\ ([0-9]{2}):([0-9]{2}))<\/td>\s*?
<\/tr>
/gimx
) {
my $m = $months{lc($4)};
die "Fatal: Unrecognized month: $4\n" if(!$m);
my $datetime = "$5$m$3$6$7";
next if $datetime lt $package{datetime};
$package{name} = $1;
$package{datetime} = $datetime;
$package{datetime_orig} = $2;
}
die "Fatal: No match found\n" if(!$package{name});
print "$package{name}" . ($showdate ? "\t$package{datetime_orig}" : "") . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment