| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# $Id: checksum.pl 91 2012-05-20 19:28:13Z ghangenit $ |
| 4 |
|
| 5 |
use Term::ANSIColor; |
| 6 |
use warnings; |
| 7 |
use strict; |
| 8 |
|
| 9 |
## |
| 10 |
## Variables |
| 11 |
## |
| 12 |
|
| 13 |
my $checksumregex = "[a-fA-F0-9]{32}"; |
| 14 |
my %checksums = ( |
| 15 |
SRCCHECKSUM => "mycv.dtx 8AACA8304D7F1F21480FDD12D7F53EC1", |
| 16 |
EXPCHECKSUM => "Examples/mycv-examples.dtx A745EADAE2358B66C6BFC3F55F3EA793", |
| 17 |
DOCCHECKSUM => "Doc/mycv.tex 83ECEA99562FE163FDF735FFC582AE3B" |
| 18 |
); |
| 19 |
|
| 20 |
my @externalcmds = ( 'pdftex', 'latexmk' ); |
| 21 |
|
| 22 |
## |
| 23 |
## Functions |
| 24 |
## |
| 25 |
|
| 26 |
sub exitWithError($$) |
| 27 |
{ |
| 28 |
my $stasus=shift; |
| 29 |
my $cmd=shift; |
| 30 |
|
| 31 |
printf STDERR ("Error: command <%s> exited with value %d.\n", $cmd, $stasus >> 8); |
| 32 |
exit $stasus; |
| 33 |
} |
| 34 |
|
| 35 |
sub checksum() |
| 36 |
{ |
| 37 |
# 'keys' returns the list of keys in an apparently random order |
| 38 |
for my $key ( keys %checksums ) |
| 39 |
{ |
| 40 |
my ($filename, $expectedmd5) = split " ", $checksums{$key}; |
| 41 |
|
| 42 |
print "\n------------------------------------------------------------\n"; |
| 43 |
print "<$filename>:\n<$expectedmd5> is the expected checksum.\n"; |
| 44 |
|
| 45 |
# gets some info among which the checksum of the file '$filename' |
| 46 |
my @result = `$externalcmds[0] "\\message{\\pdfmdfivesum file{$filename}}\\end"`; |
| 47 |
exitWithError( $?, $externalcmds[0] ) if ( $? != 0 ); |
| 48 |
|
| 49 |
foreach my $info (@result) |
| 50 |
{ |
| 51 |
if ( $info =~ /($checksumregex)/ ) # the checksum info |
| 52 |
{ |
| 53 |
chomp($info); |
| 54 |
print "<$info> is the found checksum."; |
| 55 |
if ( $info eq $expectedmd5 ) |
| 56 |
{ |
| 57 |
print color 'bold green'; |
| 58 |
print "\n[OK, they match!]\n"; print color 'reset'; |
| 59 |
} |
| 60 |
else |
| 61 |
{ |
| 62 |
print color 'bold red'; |
| 63 |
print "\n[OOPS, they do not match!]\n"; print color 'reset'; |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
print "------------------------------------------------------------\n"; |
| 68 |
} |
| 69 |
|
| 70 |
`$externalcmds[1] -c texput.log 2>&1`; # removes the log file produced by 'pdftex' |
| 71 |
exitWithError( $?, $externalcmds[1] ) if ( $? != 0 ); |
| 72 |
} |
| 73 |
|
| 74 |
## |
| 75 |
## Main |
| 76 |
## |
| 77 |
|
| 78 |
checksum(); |