2011-06-03 18:31:04 -04:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# poll-mirrors.pl
|
|
|
|
#
|
|
|
|
# This script is designed to poll download sites after posting a release
|
|
|
|
# and print out notice as each becomes available. The RM can use this
|
|
|
|
# script to delay the release announcement until the release can be
|
|
|
|
# downloaded.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Getopt::Long;
|
2011-06-03 18:36:20 -04:00
|
|
|
use POSIX qw/strftime/;
|
2011-06-04 00:47:43 -04:00
|
|
|
use LWP::UserAgent;
|
2011-06-03 18:31:04 -04:00
|
|
|
|
2013-07-12 14:37:12 -04:00
|
|
|
my $rel_path;
|
2011-06-03 18:31:04 -04:00
|
|
|
my $version;
|
|
|
|
my $interval = 300;
|
2013-07-12 14:37:12 -04:00
|
|
|
my $details = 0;
|
2011-06-03 18:31:04 -04:00
|
|
|
|
2013-07-12 14:37:12 -04:00
|
|
|
my $result = GetOptions ("version=s" => \$version,
|
|
|
|
"details!" => \$details,
|
|
|
|
"path=s" => \$rel_path,
|
|
|
|
"interval=i" => \$interval);
|
2011-06-03 18:31:04 -04:00
|
|
|
|
2013-07-12 14:37:12 -04:00
|
|
|
my $usage = ""
|
|
|
|
. "$0 -v version [ -i interval (seconds; default: 300) ] [ -details ]\n"
|
|
|
|
. "$0 -p some/explicit/path [ -i interval (seconds; default: 300) ] [ -details ]\n"
|
|
|
|
;
|
2011-06-03 18:31:04 -04:00
|
|
|
|
|
|
|
unless ($result) {
|
|
|
|
print STDERR $usage;
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-07-12 14:37:12 -04:00
|
|
|
|
|
|
|
unless (defined($version) xor defined($rel_path)) {
|
|
|
|
print STDERR "You must specify either -version or -path but not both\n$usage";
|
2011-06-03 18:31:04 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:37:12 -04:00
|
|
|
my $label;
|
|
|
|
my $apache_url_suffix;
|
|
|
|
my $maven_url;
|
|
|
|
|
|
|
|
if (defined($version)) {
|
|
|
|
if ($version !~ /^\d+(?:\.\d+)+/) {
|
|
|
|
print STDERR "You must specify the release version as a number.\n$usage";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
$label = $version;
|
|
|
|
$apache_url_suffix = "lucene/java/$version/changes/Changes.html";
|
|
|
|
$maven_url = "http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc";
|
|
|
|
} else {
|
|
|
|
# path based
|
|
|
|
$apache_url_suffix = $label = $rel_path;
|
|
|
|
}
|
2011-06-03 18:31:04 -04:00
|
|
|
my $previously_selected = select STDOUT;
|
|
|
|
$| = 1; # turn off buffering of STDOUT, so status is printed immediately
|
|
|
|
select $previously_selected;
|
|
|
|
|
|
|
|
my $apache_mirrors_list_url = "http://www.apache.org/mirrors/";
|
|
|
|
|
2011-06-04 00:47:43 -04:00
|
|
|
my $agent = LWP::UserAgent->new();
|
|
|
|
$agent->timeout(2);
|
|
|
|
|
2013-07-12 14:37:12 -04:00
|
|
|
my $maven_available = defined($maven_url) ? 0 : -999;
|
2011-06-03 18:31:04 -04:00
|
|
|
|
|
|
|
my @apache_mirrors = ();
|
|
|
|
|
2011-06-04 00:47:43 -04:00
|
|
|
my $apache_mirrors_list_page = $agent->get($apache_mirrors_list_url)->decoded_content;
|
2011-06-03 18:31:04 -04:00
|
|
|
if (defined($apache_mirrors_list_page)) {
|
|
|
|
#<TR>
|
|
|
|
# <TD ALIGN=RIGHT><A HREF="http://apache.dattatec.com/">apache.dattatec.com</A> <A HREF="http://apache.dattatec.com/">@</A></TD>
|
|
|
|
#
|
|
|
|
# <TD>http</TD>
|
|
|
|
# <TD ALIGN=RIGHT>8 hours<BR><IMG BORDER=1 SRC="icons/mms14.gif" ALT=""></TD>
|
|
|
|
# <TD ALIGN=RIGHT>5 hours<BR><IMG BORDER=1 SRC="icons/mms14.gif" ALT=""></TD>
|
|
|
|
# <TD>ok</TD>
|
|
|
|
#</TR>
|
|
|
|
while ($apache_mirrors_list_page =~ m~<TR>(.*?)</TR>~gis) {
|
|
|
|
my $mirror_entry = $1;
|
|
|
|
next unless ($mirror_entry =~ m~<TD>\s*ok\s*</TD>\s*$~i); # skip mirrors with problems
|
|
|
|
if ($mirror_entry =~ m~<A\s+HREF\s*=\s*"([^"]+)"\s*>~i) {
|
|
|
|
my $mirror_url = $1;
|
2013-07-12 14:37:12 -04:00
|
|
|
push @apache_mirrors, "${mirror_url}${apache_url_suffix}";
|
2011-06-03 18:31:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print STDERR "Error fetching Apache mirrors list $apache_mirrors_list_url";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $num_apache_mirrors = $#apache_mirrors;
|
|
|
|
|
2011-06-04 00:47:43 -04:00
|
|
|
my $sleep_interval = 0;
|
2011-06-03 18:31:04 -04:00
|
|
|
while (1) {
|
2011-06-04 00:47:43 -04:00
|
|
|
print "\n", strftime('%d-%b-%Y %H:%M:%S', localtime);
|
2011-06-03 18:36:20 -04:00
|
|
|
print "\nPolling $#apache_mirrors Apache Mirrors";
|
|
|
|
print " and Maven Central" unless ($maven_available);
|
|
|
|
print "...\n";
|
|
|
|
|
2011-06-04 00:47:43 -04:00
|
|
|
my $start = time();
|
2013-07-12 14:37:12 -04:00
|
|
|
$maven_available = (200 == $agent->head($maven_url)->code)
|
2011-06-04 00:47:43 -04:00
|
|
|
unless ($maven_available);
|
2011-06-03 18:31:04 -04:00
|
|
|
@apache_mirrors = &check_mirrors;
|
2011-06-04 00:47:43 -04:00
|
|
|
my $stop = time();
|
|
|
|
$sleep_interval = $interval - ($stop - $start);
|
2011-06-03 18:36:20 -04:00
|
|
|
|
2011-06-04 00:47:43 -04:00
|
|
|
my $num_downloadable_apache_mirrors = $num_apache_mirrors - $#apache_mirrors;
|
2013-07-12 14:37:12 -04:00
|
|
|
print "$label is ", ($maven_available ? "" : "not "),
|
|
|
|
"downloadable from Maven Central.\n" if defined($maven_url);
|
|
|
|
printf "$label is downloadable from %d/%d Apache Mirrors (%0.1f%%)\n",
|
2011-06-03 18:36:20 -04:00
|
|
|
$num_downloadable_apache_mirrors, $num_apache_mirrors,
|
|
|
|
($num_downloadable_apache_mirrors*100/$num_apache_mirrors);
|
|
|
|
|
|
|
|
last if ($maven_available && 0 == $#apache_mirrors);
|
2011-06-03 18:31:04 -04:00
|
|
|
|
2011-06-04 00:47:43 -04:00
|
|
|
if ($sleep_interval > 0) {
|
|
|
|
print "Sleeping for $sleep_interval seconds...\n";
|
|
|
|
sleep($sleep_interval)
|
|
|
|
}
|
2011-06-03 18:31:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub check_mirrors {
|
|
|
|
my @not_yet_downloadable_apache_mirrors;
|
2011-06-04 00:47:43 -04:00
|
|
|
for my $mirror (@apache_mirrors) {
|
2013-07-12 14:37:12 -04:00
|
|
|
|
|
|
|
### print "\n$mirror\n";
|
|
|
|
if (200 != $agent->head($mirror)->code) {
|
|
|
|
push @not_yet_downloadable_apache_mirrors, $mirror;
|
|
|
|
print $details ? "\nFAIL: $mirror\n" : "X";
|
|
|
|
} else {
|
|
|
|
print ".";
|
|
|
|
}
|
2011-06-03 18:31:04 -04:00
|
|
|
}
|
2011-06-04 00:47:43 -04:00
|
|
|
print "\n";
|
2011-06-03 18:31:04 -04:00
|
|
|
return @not_yet_downloadable_apache_mirrors;
|
|
|
|
}
|