#! /usr/bin/perl -w use strict ; my $DEF_INP = 'mirrors.list' ; my %TYPS ; $TYPS { $_ } ++ for qw(ftp http https rsync) ; my $TYPS = join '|', sort keys %TYPS ; my $prog = substr($0,rindex($0,'/')+1) ; my $Usage = <$TMP" or Error "can't write $TMP" ; } my @res = qw() ; my @errors = qw() ; while ( ) { my @err ; chomp ; s/\s+$// ; next if /^\s*$/ ; next if /^#/ ; my ( $reg, $url, $mail ) = split ' ' ; unless ( defined $url ) { push @err, 'no url' ; } elsif ( $url !~ m!/$! ) { $url .= '/' ; push @err, "add missing trailing '/'" ; } elsif ( $url !~ m!^($TYPS)://! ) { push @err, 'bad url' ; } elsif ( ! exists $TYPS { typ $url } ) { push @err, 'unknown scheme in url' ; } elsif ( $url =~ /^rsync:/ and $url =~ /::/ ) { push @err, "rsync-urls shouldn't match '::'" ; } unless ( defined $mail ) { push @err, 'no mail' ; } elsif ( $mail !~ /@/ ) { push @err, 'no @ in mail' ; } if ( @err ) { my $line = $_ ; push @errors, map { "$_ :\n $line" ; } @err ; } else { push @res, sprintf "%s %s %s\n", $reg, $url, $mail ; } } # check sanity ; > 0 because 'Backup' may be special Error "not enough mirrors ; bailing out" unless @res > 10 ; my $res = join '', sort @res ; if ( $TMP ) { print TMP $res ; close TMP ; my $siz = -s $TMP ; my $len = length $res ; Error "bad size $TMP ($siz) ; should be $len" if $siz != $len ; rename $TMP, $OUT or Error "can't mv '$TMP' '$OUT' ($!)" ; } else { print $res if $opt{v} ; Error sprintf "\n%s", join "\n", @errors if @errors ; printf "mirrors : %d ; no errors found\n", scalar @res unless $opt{q} ; }