Add mirror scripts and config
[grml-mirrors.git] / bin / generate_mirror_map
diff --git a/bin/generate_mirror_map b/bin/generate_mirror_map
new file mode 100755 (executable)
index 0000000..224cbcd
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use lib '/usr/share/perl5/';
+
+use Mirmon::Mirmon ;
+
+$m = Mirmon -> new ( '/etc/mirmon.conf' ); 
+
+$conf  = $m->conf  ; # a Mirmon::Conf object
+$state = $m->state ; # the mirmon state
+
+use Data::Dumper;
+my $mirrors;
+foreach my $url ( keys %{$state} ) { 
+       next unless $url =~ /^http/;
+       $mirror = $state -> { $url } ; # a Mirmon::Mirror object
+       my ($time, $history) = split('-', $mirror->{state_history});
+       my $last_state = substr($history,-1,1);
+       next if $last_state eq 'f';
+       my $region = $mirror->region;
+       $mirrors->{ $region } ||= [];
+       $url =~ s/^http:\/\///;
+       push @{$mirrors->{ $region }}, $url;
+}
+
+foreach my $region (keys %{$mirrors}) {
+       printf ("%s %s\n", lc($region), join('|', @{$mirrors->{$region}}));
+}