##
## Copyright (C) 2003-2017 Mark Shelor, All Rights Reserved
##
- ## Version: 6.00
- ## Fri Dec 8 22:44:44 MST 2017
+ ## Version: 6.01
+ ## Mon Dec 25 00:08:08 MST 2017
## shasum SYNOPSIS adapted from GNU Coreutils sha1sum. Add
## "-a" option for algorithm selection,
use warnings;
use Fcntl;
use Getopt::Long;
-use Digest::SHA;
+use Digest::SHA qw($errmsg);
my $POD = <<'END_OF_POD';
ASCII '1' interpreted as 1-bit,
all other characters ignored
- The following three options are useful only when verifying checksums:
- -s, --status don't output anything, status code shows success
- -q, --quiet don't print OK for each successfully verified file
- -w, --warn warn about improperly formatted checksum lines
+ The following five options are useful only when verifying checksums:
+ --ignore-missing don't fail or report status for missing files
+ -q, --quiet don't print OK for each successfully verified file
+ -s, --status don't output anything, status code shows success
+ --strict exit non-zero for improperly formatted checksum lines
+ -w, --warn warn about improperly formatted checksum lines
-h, --help display this help and exit
-v, --version output version information and exit
END_OF_POD
-my $VERSION = "6.00";
+my $VERSION = "6.01";
sub usage {
my($err, $msg) = @_;
## Collect options from command line
my ($alg, $binary, $check, $text, $status, $quiet, $warn, $help);
-my ($version, $BITS, $UNIVERSAL, $tag);
+my ($version, $BITS, $UNIVERSAL, $tag, $strict, $ignore_missing);
eval { Getopt::Long::Configure ("bundling") };
GetOptions(
'0|01' => \$BITS,
'U|UNIVERSAL' => \$UNIVERSAL,
'tag' => \$tag,
+ 'strict' => \$strict,
+ 'ignore-missing' => \$ignore_missing,
) or usage(1, "");
if $status && !$check;
usage(1, "shasum: --quiet option used only when verifying checksums\n")
if $quiet && !$check;
+usage(1, "shasum: --ignore-missing option used only when verifying checksums\n")
+ if $ignore_missing && !$check;
+usage(1, "shasum: --strict option used only when verifying checksums\n")
+ if $strict && !$check;
usage(1, "shasum: --tag does not support --text mode\n")
if $tag && $text;
usage(1, "shasum: --tag does not support Universal Newlines mode\n")
my $mode = $binary ? 'b' : ($UNIVERSAL ? 'U' : ($BITS ? '0' : ''));
my $digest = eval { Digest::SHA->new($alg)->addfile($file, $mode) };
- if ($@) { warn "shasum: $file: $!\n"; return }
+ if ($@) { warn "shasum: $file: $errmsg\n"; return }
$digest->hexdigest;
}
sub verify {
my $checkfile = shift;
my ($err, $fmt_errs, $read_errs, $match_errs) = (0, 0, 0, 0);
- my ($num_lines, $num_files) = (0, 0);
+ my ($num_fmt_OK, $num_OK) = (0, 0);
my ($bslash, $sum, $fname, $rsp, $digest, $isOK);
local *FH;
or sysopen(FH, $checkfile, O_RDONLY)
or die "shasum: $checkfile: $!\n";
while (<FH>) {
- next if /^#/; $num_lines++;
+ next if /^#/;
if (/^[ \t]*\\?SHA/) {
$modesym = '*';
($bslash, $alg, $fname, $sum) =
warn("shasum: $checkfile: $.: improperly " .
"formatted SHA checksum line\n") if $warn;
$fmt_errs++;
+ $err = 1 if $strict;
next;
}
+ $num_fmt_OK++;
$fname = unescape($fname) if $bslash;
- $rsp = "$fname: "; $num_files++;
+ next if $ignore_missing && ! -e $fname;
+ $rsp = "$fname: ";
($binary, $text, $UNIVERSAL, $BITS) =
map { $_ eq $modesym } ('*', ' ', 'U', '^');
$isOK = 0;
$rsp .= "FAILED open or read\n";
$err = 1; $read_errs++;
}
- else {
- if (lc($sum) eq $digest) { $rsp .= "OK\n"; $isOK = 1 }
- else { $rsp .= "FAILED\n"; $err = 1; $match_errs++ }
+ elsif (lc($sum) eq $digest) {
+ $rsp .= "OK\n";
+ $isOK = 1;
+ $num_OK++;
}
+ else { $rsp .= "FAILED\n"; $err = 1; $match_errs++ }
print $rsp unless ($status || ($quiet && $isOK));
}
close(FH);
- unless ($num_files) {
- $alg = 1 unless defined $alg;
+ if (! $num_fmt_OK) {
warn("shasum: $checkfile: no properly formatted " .
- "SHA$alg checksum lines found\n");
+ "SHA checksum lines found\n");
$err = 1;
}
elsif (! $status) {
warn("shasum: WARNING: $match_errs computed checksum" .
($match_errs>1?'s':'') . " did NOT match\n") if $match_errs;
}
+ if ($ignore_missing && ! $num_OK && $num_fmt_OK) {
+ warn("shasum: $checkfile: no file was verified\n")
+ unless $status;
+ $err = 1;
+ }
return($err == 0);
}
}
else { $STATUS = 1 }
}
-exit($STATUS)
+exit($STATUS);
# ./perl -I../lib porting/customized.t --regen
Devel::PPPort dist/Devel-PPPort/parts/embed.fnc e030719d9c6921810554a8e2d398543348b4878c
Digest cpan/Digest/Digest.pm 43f7f544cb11842b2f55c73e28930da50774e081
-Digest::SHA cpan/Digest-SHA/t/allfcns.t 9ee294dc3f6a1c6b6c8e9bf7e17a3100ab7f98e3
-Digest::SHA cpan/Digest-SHA/t/base64.t 092e88b25f56ae01dce42c3c073603c648ba8f55
-Digest::SHA cpan/Digest-SHA/t/bitbuf.t 2bbc0d301391affadba59152ca6c85c0e0900f09
-Digest::SHA cpan/Digest-SHA/t/bitorder.t e46044e2915895044933579f11c4801341ab1fdc
-Digest::SHA cpan/Digest-SHA/t/fips180-4.t 9cd39dfedb5905a5693c9e97e00070db072a471e
-Digest::SHA cpan/Digest-SHA/t/fips198.t 1482029f8f7dd4f000bbb34e9cbc09e1b3ae0893
-Digest::SHA cpan/Digest-SHA/t/gg.t e3bfaf58efb1dcc5aa7e26a889b600213c766c00
-Digest::SHA cpan/Digest-SHA/t/gglong.t 0ce33514b02891957fef68de2909b642cc06868f
-Digest::SHA cpan/Digest-SHA/t/hmacsha.t d5f3f5ea89d63c4586fb7a22bbbf9e536e4fff99
-Digest::SHA cpan/Digest-SHA/t/inheritance.t 0b5953e9a2ef4aa9a1d6c09a828e806c5d39aa85
-Digest::SHA cpan/Digest-SHA/t/ireland.t 7c2c84aa8894022dc538b5d6dc86640d8ba75f4b
-Digest::SHA cpan/Digest-SHA/t/methods.t 85ab0c185c3a0444ab68ea41178f4c169624f7c3
-Digest::SHA cpan/Digest-SHA/t/nistbit.t 345a5a54b853b8633eec5e73190322c0856506d6
-Digest::SHA cpan/Digest-SHA/t/nistbyte.t b12f6c887888bb7454ad09fba2c191467b4c001c
-Digest::SHA cpan/Digest-SHA/t/rfc2202.t 521a1ab31f8ed2072d4d358c09670c016add1b99
-Digest::SHA cpan/Digest-SHA/t/sha1.t 608824b77e2a47ef8357d4b72ccc05990f89dc98
-Digest::SHA cpan/Digest-SHA/t/sha224.t 0b690d62c1b13610c57e87fe5d1c42d3919968dc
-Digest::SHA cpan/Digest-SHA/t/sha256.t 8219d5d2c1561114f063eeba42ca2738637b3f5c
-Digest::SHA cpan/Digest-SHA/t/sha384.t c21cd7de72060eb6f9ae4d9c30ae8d13d0a0b856
-Digest::SHA cpan/Digest-SHA/t/sha512.t bbe44c7cb600c29ef6763d0782b0aae0269ba5f3
-Digest::SHA cpan/Digest-SHA/t/state.t b7146b91d9dcc276c4e3c0c251794bf5f46c1dfa
-Digest::SHA cpan/Digest-SHA/t/unicode.t f62768510104cde42af8544e04af722ee2cbb85e
-Digest::SHA cpan/Digest-SHA/t/woodbury.t 1efec6fae3600f891d27f944d05d6e363444d9c8
Locale::Maketext::Simple cpan/Locale-Maketext-Simple/lib/Locale/Maketext/Simple.pm 57ed38905791a17c150210cd6f42ead22a7707b6
Math::Complex cpan/Math-Complex/lib/Math/Complex.pm 198ea6c6c584f5ea79a0fd7e9d411d0878f3b2af
Math::Complex cpan/Math-Complex/t/Complex.t 4f307ed6fc59f1e5fb0e6b11103fc631b6bdb335