Mercurial > ec-dotfiles
diff bin/old-cek @ 124:5bafb912837e
Massive addition of old scripts collection.
author | Edho Prima Arief <edho@myconan.net> |
---|---|
date | Wed, 26 Oct 2011 15:22:00 +0700 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/old-cek Wed Oct 26 15:22:00 2011 +0700 @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use String::CRC32; +use File::Basename; + +unless($#ARGV+1>0) { + print("Usage: ", basename($0), " file1 ... fileN\n"); + exit(1); +} + +my @files = @ARGV; +#or print("Usage: ", basename($0), " file1 ... fileN\n") && exit(1); + # print usage message if called without arguments + +foreach (@files) { + my $filename = $_; + my ($input, $name_checksum, $real_checksum, $checksum); + unless((-r $filename) && (-f $filename)) { + print(qq("$filename" is not a file or unreadable, skipping\n)); + next(); + } + #print(qq(Could not find file "$filename", skipping\n)) and next() unless -r $filename; + #print(qq("$filename" is not a file, skipping\n)) and next() unless -f $filename; + + open(FILE,$filename); + $real_checksum = sprintf("%08X",crc32(*FILE)); + close(FILE); + + if ( /(\[|\()([0-9A-F]{8})(\]|\))/i ) { # does it have a checksum? + $name_checksum = $2; + if (lc($real_checksum) eq lc($name_checksum)) { + print("${filename}: $real_checksum - OK!\n"); + next(); + } + else { + print("${filename}: $real_checksum - NOT OK! Should be ${name_checksum}!\n"); + next(); + } + } + else { # can't find checksum in filename, just print filename + generated checksum and let the user do the thinking + print("${filename}: $real_checksum\n"); + next(); + } +} + +exit(0); +