Reflect Jessie upgrade. Module has been renamed
[grml-mirrors.git] / bin / generate_mirror_map
1 #!/usr/bin/perl
2
3 use lib '/usr/share/perl5/';
4
5 use Mirmon ;
6
7 $m = Mirmon -> new ( '/etc/mirmon.conf' ); 
8
9 $conf  = $m->conf  ; # a Mirmon::Conf object
10 $state = $m->state ; # the mirmon state
11
12 use Data::Dumper;
13 my $mirrors;
14 my $regions_hash;
15 foreach my $url ( keys %{$state} ) { 
16         next unless $url =~ /^http/;
17         $mirror = $state -> { $url } ; # a Mirmon::Mirror object
18         my ($time, $history) = split('-', $mirror->{state_history});
19         my $last_state = substr($history,-1,1);
20         my $region = $mirror->region;
21         $regions_hash->{$region} = 1;
22         next if $last_state eq 'f';
23         $mirrors->{ $region } ||= [];
24         $url =~ s/^http:\/\///;
25         push @{$mirrors->{ $region }}, $url;
26 }
27
28 my @regions = keys(%$regions_hash);
29
30 foreach my $region (@regions) {
31         if (scalar(@{$mirrors->{$region}}) == 0) {
32                 printf ("%s %s\n", lc($region), join('|', @{$mirrors->{'DE'}}));
33         } else {
34                 printf ("%s %s\n", lc($region), join('|', @{$mirrors->{$region}}));
35         }
36 }