generate_mirror_map: output region in uppercase
[grml-mirrors.git] / bin / generate_mirror_map
index 224cbcd..ed5b90b 100755 (executable)
@@ -2,7 +2,7 @@
 
 use lib '/usr/share/perl5/';
 
-use Mirmon::Mirmon ;
+use Mirmon ;
 
 $m = Mirmon -> new ( '/etc/mirmon.conf' ); 
 
@@ -11,6 +11,7 @@ $state = $m->state ; # the mirmon state
 
 use Data::Dumper;
 my $mirrors;
+my $regions_hash;
 foreach my $url ( keys %{$state} ) { 
        next unless $url =~ /^http/;
        $mirror = $state -> { $url } ; # a Mirmon::Mirror object
@@ -18,11 +19,18 @@ foreach my $url ( keys %{$state} ) {
        my $last_state = substr($history,-1,1);
        next if $last_state eq 'f';
        my $region = $mirror->region;
+       $regions_hash->{$region} = 1;
        $mirrors->{ $region } ||= [];
        $url =~ s/^http:\/\///;
        push @{$mirrors->{ $region }}, $url;
 }
 
-foreach my $region (keys %{$mirrors}) {
-       printf ("%s %s\n", lc($region), join('|', @{$mirrors->{$region}}));
+my @regions = keys(%$regions_hash);
+
+foreach my $region (@regions) {
+       if (scalar(@{$mirrors->{$region}}) == 0) {
+               printf ("%s %s\n", uc($region), join('|', @{$mirrors->{'DE'}}));
+       } else {
+               printf ("%s %s\n", uc($region), join('|', @{$mirrors->{$region}}));
+       }
 }