<?xml version="1.0" encoding="windows-1252"?>
<node id="130623" title="Verify Your FreeBSD CD" created="2001-12-10 09:36:34" updated="2005-08-13 08:20:07">
<type id="1748">
sourcecode</type>
<author id="10277">
crazyinsomniac</author>
<data>
<field name="doctext">
&lt;CODE&gt;#!/usr/bin/perl -w

=head1 NAME     Verify Your FreeBSD CD

=head1 AUTHOR   crazyinsomniac

When The Levee Breaks

=head1 LICENSE  the same as that of perl itself (`perl -v')

=head1 CHECKSUM.MD5

MD5 (compat21.aa) = c44af22b7cc1f19cccdaf7f49841f9de
MD5 (compat21.ab) = d7f1ff74b9ff7b7d21eda01f90ee04e0
...

=cut

use strict;
use Getopt::Std;
use Digest::MD5;
use File::Find;

$|= {on =&gt; 'nope'};

use vars qw/ %Opt %Dsp $Vv/;

getopts('?hvd:', \%Opt);

$Vv = 1 if exists $Opt{v}; # verbosity (errors and bad sums reported by default)

if( exists $Opt{h} or exists $Opt{'?'} )
{
    goto FIRST_HELP
}
elsif( exists $Opt{d} )
{
    die " Where is your cd !!??\n"
       unless defined $Opt{d}; # missing arg, you ape

    chdir $Opt{d}
        or die "Dang, does the directory '$Opt{d}' really exist?\n";

    die "hmm, can't read $Opt{d} for some reason \n"
        unless -d $Opt{d} and -r $Opt{d};

    find(\&amp;loop_it, $Opt{d});

    goto THEEND
}


FIRST_HELP:
{
    print&lt;&lt;"#||#";

    Hello and welcome to Verify Your Debian Potatoe.
    This tool relies on the md5sum.txt file
    being in the root "directory" of said cd,
    and the sums there being correct.
    
    Usage: perl $0 [-?hvd]
    -?      same as below
    -h      prints out this message
    -v      bees verbose (FAILED sums are reported by default)
    -d      /path/to/cd/a/must

#||#
}

sub loop_it
{
    return unless $_ eq 'CHECKSUM.MD5';
    # we only loop it if we got something to work with

    print "$File::Find::name\n----\n" if $Vv;

    open(FE,'CHECKSUM.MD5') or warn "Impossible!!! CHECKSUM.MD5! $!" and return;

    my %MD5Sums = map
                  { chomp;
                    /^MD5 \(([^()]+)\) = ([a-zA-Z0-9]{32})$/ # damn!!! i'm good
                  } &lt;FE&gt;;

    close(FE);

    for my $file(sort keys %MD5Sums)
    {
        print "processing $file \n", if $Vv;

        open(MDFH,$file) or warn "shit, couldn't open $file, neext\n" and next;

        binmode MDFH; # cause I don't know what kind of shit u runnin

        select undef, undef, undef, 0.45; # cause a lot of cdr(w)s choke up

        my $md5 = Digest::MD5-&gt;new()-&gt;addfile(*MDFH)-&gt;hexdigest();

        if ( $md5 ne $MD5Sums{$file} )
        {
            printf "Oh CRIKEY!! -- it's to the bakery.\n%s\n%s **\n%s\n\n",
                   $file, $MD5Sums{$file}, $md5
        }
        elsif($Vv)
        {
            printf "G.oo00OOD!! -- no problem here\n%s\n%s **\n%s\n\n",
                   $file, $MD5Sums{$file}, $md5
        }
    }
}

THEEND: die q{ I'll have no place to stay. }
__END__
&gt;perl -ne"$\=qq,\n,;print for m/^MD5 \(([^()]+)\) = (.{32})$"' CHECKSUM.MD5
&gt;perl -ne"print map {scalar &lt;&gt;} 1..3 if /^Oh CRIKEY!!/" verify&lt;/CODE&gt;</field>
<field name="codedescription">
If you just downloaded 4.4-install.iso also known as FreeBSD 4.4 ISO, and you "burned" it to a cd, and you wish to make sure that all the packages contained are as they should be (Debian has been really lame about this, I had at least 5 packages fail, even tough the "burn" was good, it turns out, just a shabby iso release)

&lt;CODE&gt;
perl verify_freebsd.pl -d D:/&gt;burnt
&lt;/CODE&gt;
&lt;B&gt;WHAT?!?!:&lt;/B&gt; For some reason, in &lt;TT&gt;\XF86336\CHECKSUM.MD5&lt;/TT&gt;
the line
&lt;TT&gt;MD5 (Servers) = edc0aef739c1907144838e6c18587e02&lt;/TT&gt;
which apparently is the md5 sum for the "directory" \XF86336\Servers which you might be able to do in *nix, but on on winblow.</field>
<field name="codecategory">
Utility Scripts</field>
<field name="codeauthor">
crazyinsomniac at the throne dot asterix</field>
</data>
</node>
