You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
3.8 KiB

use strict;
use Data::Dumper;
use POSIX;
use LWP;
# setup: as root: apt install libwww-perl
my $URL='';
my $ua=LWP::UserAgent->new;
my $resp=$ua->get($URL) or die "Could't get the mirror list: [$URL]\n";
my $data=$resp->content();
die "Got an empty $URL...\n" if $data eq "";
my @data;
my %entry;
my $line_num;
for (split /\n/,$data) {
if (/\S/) {
$entry{'LINE'}||="LINE $line_num";
$entry{$1}=$2 if /^([^:]+):\s+(.+)/ or die "Invalid syntax on line $line_num [$_]\n";
} else {
push @data,{%entry} if $entry{'LINE'};
push @data,{%entry} if $entry{'LINE'};
my %iso3166cc=(
my %check_fields=(FQDN=>'LINE',Active =>'FQDN',BaseURL=>'FQDN','CountryCode'=>'FQDN');
my %check_values=(Active=>'yes','CountryCode'=>'[a-z][a-z](\s*\|\s*[a-z][a-z])*');
for my $ent(@data) {
for(keys %check_fields) {
next if $ent->{$_};
next DATA;
for(keys %check_values) {
next if $ent->{$_}=~/^$check_values{$_}$/i;
next DATA;
next if $ent->{'FQDN'} eq '';
push @{$iso3166cc{$_}},"http://$ent->{BaseURL}" for split /\s*\|\s*/,$ent->{'CountryCode'};
#while(my($cc,$a)=each %iso3166cc) {
for my $cc (sort keys %iso3166cc) {
my $a=$iso3166cc{$cc};
my $cl=lc($cc);
print "#LOC:$cc\nhttp://$\n";
for my $u(values @$a) {
$u.='/' if $u!~/\/$/;
print "$u\n";