aboutsummaryrefslogtreecommitdiff
path: root/dm
diff options
context:
space:
mode:
authorRyan Kavanagh <ryanakca@kubuntu.org>2011-08-18 08:22:04 -0400
committerRyan Kavanagh <ryanakca@kubuntu.org>2011-08-25 07:43:05 -0400
commitb807a91d97c0f4bc62c078ec6afb8f8d44ad694e (patch)
treedcddf84103637a11895941dfc611c0bc0feaf835 /dm
parentRename executable makefile to dm (diff)
Improved sha256sum checker
Diffstat (limited to 'dm')
-rwxr-xr-xdm25
1 files changed, 20 insertions, 5 deletions
diff --git a/dm b/dm
index 39633c6..f277d05 100755
--- a/dm
+++ b/dm
@@ -105,19 +105,34 @@ sha256sums.asc: sha256sums
verify:
# BSD sha256 sum command doesn't have a -c option.
# BSD and coreutils sha256 commands have different outputs, however, the
- # sum is always the last field.
- awk 'BEGIN {\
+ # file is always in field two. The sum's location varies.
+ awk --posix 'BEGIN {\
mismatch_count = 0; \
match_count = 0; \
} { \
+ # The file associated with the sum we`re checking \
+ # Appears to be field 2 in BSD and coreutils sum \
file = $$2; \
+ # We want `filename`, not `(filename)` \
sub(/^\(/, "", file); \
sub(/\)$$/, "", file); \
+ # Generate the sum to compare with \
cmd = "$(SHA256) " file; \
- cmd | getline sum; \
+ cmd | getline gensum; \
close(cmd); \
- sum = split(sum, fields); \
- if (fields[sum] == $$NF) { \
+ split(gensum, gensum_fields); \
+ gensum = ""; \
+ for (field in gensum_fields) { \
+ if (gensum_fields[field] ~ /[[:xdigit:]]{64}/) { \
+ gensum = gensum_fields[field]; \
+ } \
+ } \
+ for (i = 1; i <= NF; i++) { \
+ if ($$i ~ /[[:xdigit:]]{64}/) { \
+ filesum = $$i; \
+ } \
+ } \
+ if (filesum == gensum) { \
print "Match: " file; \
match_count += 1; \
} else { \