Add mirror scripts and config
[grml-mirrors.git] / bin / masterlist2mirmon
diff --git a/bin/masterlist2mirmon b/bin/masterlist2mirmon
new file mode 100755 (executable)
index 0000000..0195492
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $file = shift;
+
+die "no file $file" unless -f $file;
+
+open (my $fh, '<', $file) or die "Could not open $file: $!";
+
+my @mirrors;
+my $data;
+while (my $line = <$fh>) {
+    chomp $line;
+    if ($line =~ /([^:]+): (.*)/) {
+        my $key = lc($1);
+        my $value = $2;
+        $data->{$key} = $value;
+    } elsif ($line eq '') {
+        push @mirrors, $data;
+        $data = undef;
+    } else {
+        print "Malformed line: $line\n";
+    }
+}
+
+push @mirrors, $data if $data;
+
+foreach my $mirror (@mirrors) {
+    my ($c, $r) = split (/ +/, $mirror->{'country'});
+    printf ("%s http://%s%s\n", $c, $mirror->{'site'}, $mirror->{'grml-http'});
+    if ($mirror->{'grml-ftp'}) {
+        printf ("%s ftp://%s%s\n", $c, $mirror->{'site'}, $mirror->{'grml-ftp'});
+    }
+    if ($mirror->{'grml-rsync'}) {
+        printf ("%s rsync://%s/%s\n", $c, $mirror->{'site'}, $mirror->{'grml-rsync'});
+    }
+
+}