[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: md5sum



According to White Mage:
> So far as I know there isn't any nice automated way to check the sums in 
> 'Packages' against the actual md5sums of the packages one has.

I use this Perl script.  Run it in your local equivalent of the
"binaries" directory.  By default it reports only problems; if you
want progress messages for files that are okay, use the "-v" option.

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1996-02-21 09:30 EST by <chip@fin>.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    898 -r-xr-xr-x list-cksums
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  echo 'WARNING: not restoring timestamps.  Consider getting and'
  echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
# ============= list-cksums ==============
if test -f 'list-cksums' && test X"$1" != X"-c"; then
  echo 'x - skipping list-cksums (file already exists)'
else
  echo 'x - extracting list-cksums (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'list-cksums' &&
#!/usr/bin/perl -w
X
$VERBOSE = 0;
while (@ARGV) {
X    $_ = $ARGV[0];
X    last unless s/^-//;
X    shift;
X    last if $_ eq "-";
X    $VERBOSE = 1 if s/v//g;
}
X
open(P, "Packages");
while (<P>) {
X    chop;
X    if (/^Package/) {
X	undef $pack;
X	undef $sum;
X    }
X    if (m#^filename:\s*development/binary-\w+/(\S+)#) {
X	$pack = $1;
X    }
X    elsif (m#^md5sum:\s*(\S+)#) {
X	$sum = $1;
X    }
X
X    if (defined $pack && defined $sum) {
X	$SUM{$pack} = $sum;
X	undef $pack;
X	undef $sum;
X    }
}
X
$pid = open(SUMPROG, "-|");
defined $pid or die "Can't fork: $!\n";
if ($pid == 0) {
X    exec "md5sum", grep {-f} sort keys %SUM;
X    die "Can't execute md5sum: $!\n";
}
while (<SUMPROG>) {
X    ($sum, $file) = split;
X    print STDERR "$file: $sum\n" if $VERBOSE;
X    if (! exists $SUM{$file}) {
X	print "$file: Obsolete\n";
X    }
X    elsif ($sum ne $SUM{$file}) {
X	print "$file: Corrupt\n";
X    }
}
close(SUMPROG);
SHAR_EOF
  $shar_touch -am 0221092896 'list-cksums' &&
  chmod 0555 'list-cksums' ||
  echo 'restore of list-cksums failed'
  shar_count="`wc -c < 'list-cksums'`"
  test 898 -eq "$shar_count" ||
    echo "list-cksums: original size 898, current size $shar_count"
fi
exit 0


-- 
Chip Salzenberg     a.k.a.      <chip@atlantic.net>
      "Men of lofty genius are most active
       when they are doing the least work."
                          -- Leonardo da Vinci


Reply to: