Mercurial > ec-dotfiles
comparison 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 |
comparison
equal
deleted
inserted
replaced
123:173833e4ba35 | 124:5bafb912837e |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 use warnings; | |
4 use strict; | |
5 use String::CRC32; | |
6 use File::Basename; | |
7 | |
8 unless($#ARGV+1>0) { | |
9 print("Usage: ", basename($0), " file1 ... fileN\n"); | |
10 exit(1); | |
11 } | |
12 | |
13 my @files = @ARGV; | |
14 #or print("Usage: ", basename($0), " file1 ... fileN\n") && exit(1); | |
15 # print usage message if called without arguments | |
16 | |
17 foreach (@files) { | |
18 my $filename = $_; | |
19 my ($input, $name_checksum, $real_checksum, $checksum); | |
20 unless((-r $filename) && (-f $filename)) { | |
21 print(qq("$filename" is not a file or unreadable, skipping\n)); | |
22 next(); | |
23 } | |
24 #print(qq(Could not find file "$filename", skipping\n)) and next() unless -r $filename; | |
25 #print(qq("$filename" is not a file, skipping\n)) and next() unless -f $filename; | |
26 | |
27 open(FILE,$filename); | |
28 $real_checksum = sprintf("%08X",crc32(*FILE)); | |
29 close(FILE); | |
30 | |
31 if ( /(\[|\()([0-9A-F]{8})(\]|\))/i ) { # does it have a checksum? | |
32 $name_checksum = $2; | |
33 if (lc($real_checksum) eq lc($name_checksum)) { | |
34 print("${filename}: $real_checksum - OK!\n"); | |
35 next(); | |
36 } | |
37 else { | |
38 print("${filename}: $real_checksum - NOT OK! Should be ${name_checksum}!\n"); | |
39 next(); | |
40 } | |
41 } | |
42 else { # can't find checksum in filename, just print filename + generated checksum and let the user do the thinking | |
43 print("${filename}: $real_checksum\n"); | |
44 next(); | |
45 } | |
46 } | |
47 | |
48 exit(0); | |
49 |