(Solved) How to check integrity of .deb files
Hi,
At 03:37 PM 7/17/97 -0400, Dale Scheetz wrote:
>You can use md5sums to verify their integrity. There is a list of the
>correct checksum values in the indices directory of the archive that you
>can use to compare with the values that md5sum gives for the packages.
As Dwarf suggested, I used the MD5 checksums to check for the integrity of
my .deb files, which I downloaded from ftp.debian.org but got corrupted
when they were written to bad sectors on disk.
I could not find a tool to do the whole integrity check automagically so I
wrote a small Perl script. Now, if I want to check the integrity of several
.deb files I run this script as this: "check_deb_integrity.pl --debian /mnt
--packages /mnt/Packages"
The --debian switch tells the program where the Debian distribution is
located. If the switch is not present, the current directory is used. The
--packages switch tells the program where to look for the Packages file. If
not specified, ./Packages is used.
The program is just a first try but it is working for me. I hope you find
it useful. Here it is:
-------
#!/usr/bin/perl -w
#
# Calculate the MD5 sum of the file passed in the command line and
# compares it to the MD5 value in the Packages file.
#
# By Eloy A. Paris <peloy@ven.ra.rockwell.com>
#
$PACKAGES_FILE = "Packages";
$DEBIAN_LOC = ".";
## get those options:
while ($arg = shift(@ARGV) ) {
# general options
if ($arg eq "--help") {
&usage();
exit(0);
} elsif ($arg eq "--packages") {
$PACKAGES_FILE = shift(@ARGV);
} elsif ($arg eq "--debian") {
$DEBIAN_LOC = shift(@ARGV);
} elsif ($arg =~ /^--/) { # bad argument!
&usage();
exit(1);
}
}
# Process the Packages file. We look for the file name and the MD5 checksum.
# Everything else is useless.
open(PACKAGES, $PACKAGES_FILE) || die("Can't open Packages file $PACKAGES\n");
while (<PACKAGES>) {
if ($_ =~ /^Filename/ || $_ =~ /^MD5sum/) {
chop;
push(@packages, $_);
}
}
close(PACKAGES);
# Now find all .deb files
open(DEB_FILES, "find $DEBIAN_LOC -type f -name '*.deb' |") || die;
while ($file = <DEB_FILES>) {
chop($file);
if (! -f $file) {
print STDERR ("File $file doesn't exist, can not calculate its MD5",
" checksum\n");
next;
}
# Calculate MD5 checksum of the file
($file_md5_checksum = `md5sum $file`) =~ s/ .*//;
chop($file_md5_checksum);
# Now get base file name
$base_fname = $file;
$base_fname =~ s/^.*\///;
# Escape '+' and '.'' in base file name
$base_fname =~ s/(\+|\.)/\\\1/g;
for ($i = 0; $packages[$i]; ++$i) {
if ($packages[$i] =~ /Filename/ && $packages[$i] =~ /$base_fname/) {
($correct_md5_checksum = $packages[$i + 1]) =~ s/.* //;
print("File $file has an incorrect MD5 checksum!!!\n") if
($correct_md5_checksum ne $file_md5_checksum);
last;
}
}
}
close(DEB_FILES);
-----------
Regards,
Eloy.-
--
Eloy A. Paris
Information Technology Department
Rockwell Automation de Venezuela
Telephone: +58-2-9432311 Fax: +58-2-9431645 Cel.: +58-16-234700
"Where does this path lead?" said Alice
"Depends on where you want to go." Said the cat
("Alice in Wonderland", by Lewis Carroll.)
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org .
Trouble? e-mail to templin@bucknell.edu .
Reply to: