#!/usr/bin/perl -w use MD5; my $mirror = shift || $ENV{'MIRROR'}; my $nonus = shift || $ENV{'NONUS'}; my ($p, $filename, $size, $md5sum, $file) = ('', '', 0, '', ''); my $ok = 1; my ($ctx, $digest); $/=''; # Browse paragraph by paragraph while (defined($_ = <>)) { # Get the infos about a package m/^Package: (\S+)/m and $p = $1; m/^Size: (\d+)/m and $size = $1; m/^Filename: (\S+)/mi and $filename = $1; m/^MD5sum: (\S+)/m and $md5sum = $1; next if not $p; $file = ( -e "$mirror/$filename" ) ? "$mirror/$filename" : "$nonus/$filename"; # Check if the file exists if (! -e $file) { print STDERR "File $filename can't be found ...\n"; $ok = 0; next; } # Check for the size if (-s _ != $size) { print STDERR "The size doesn't match for $file.\n"; print STDERR "It's `@{ [ -s _ ]}' instead of `$size'.\n"; $ok = 0; } # Compute the MD5sum open(FILE, "< $file") || die "Can't open $file : $!\n"; $ctx = MD5->new; $ctx->addfile(*FILE); $digest = $ctx->hexdigest; undef $ctx; close FILE; # Check the MD5sum if ($digest ne $md5sum) { print STDERR "MD5sum does not match for $file ...\n"; print STDERR "It's `$digest' instead of `$md5sum'.\n"; $ok = 0; } } if ($ok) { exit 0; } else { print STDERR <