Last active
August 29, 2015 14:00
-
-
Save darealshinji/11068706 to your computer and use it in GitHub Desktop.
A patch for GNU's coreutils v8.22 which adds an option to md5sum and sha*sum, that allows one to print only the checksum.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/src/md5sum.c | |
+++ b/src/md5sum.c | |
@@ -42,42 +42,42 @@ | |
/* The official name of this program (e.g., no 'g' prefix). */ | |
#if HASH_ALGO_MD5 | |
-# define PROGRAM_NAME "md5sum" | |
+# define PROGRAM_NAME "md5" | |
# define DIGEST_TYPE_STRING "MD5" | |
# define DIGEST_STREAM md5_stream | |
# define DIGEST_BITS 128 | |
# define DIGEST_REFERENCE "RFC 1321" | |
# define DIGEST_ALIGN 4 | |
#elif HASH_ALGO_SHA1 | |
-# define PROGRAM_NAME "sha1sum" | |
+# define PROGRAM_NAME "sha1" | |
# define DIGEST_TYPE_STRING "SHA1" | |
# define DIGEST_STREAM sha1_stream | |
# define DIGEST_BITS 160 | |
# define DIGEST_REFERENCE "FIPS-180-1" | |
# define DIGEST_ALIGN 4 | |
#elif HASH_ALGO_SHA256 | |
-# define PROGRAM_NAME "sha256sum" | |
+# define PROGRAM_NAME "sha256" | |
# define DIGEST_TYPE_STRING "SHA256" | |
# define DIGEST_STREAM sha256_stream | |
# define DIGEST_BITS 256 | |
# define DIGEST_REFERENCE "FIPS-180-2" | |
# define DIGEST_ALIGN 4 | |
#elif HASH_ALGO_SHA224 | |
-# define PROGRAM_NAME "sha224sum" | |
+# define PROGRAM_NAME "sha224" | |
# define DIGEST_TYPE_STRING "SHA224" | |
# define DIGEST_STREAM sha224_stream | |
# define DIGEST_BITS 224 | |
# define DIGEST_REFERENCE "RFC 3874" | |
# define DIGEST_ALIGN 4 | |
#elif HASH_ALGO_SHA512 | |
-# define PROGRAM_NAME "sha512sum" | |
+# define PROGRAM_NAME "sha512" | |
# define DIGEST_TYPE_STRING "SHA512" | |
# define DIGEST_STREAM sha512_stream | |
# define DIGEST_BITS 512 | |
# define DIGEST_REFERENCE "FIPS-180-2" | |
# define DIGEST_ALIGN 8 | |
#elif HASH_ALGO_SHA384 | |
-# define PROGRAM_NAME "sha384sum" | |
+# define PROGRAM_NAME "sha384" | |
# define DIGEST_TYPE_STRING "SHA384" | |
# define DIGEST_STREAM sha384_stream | |
# define DIGEST_BITS 384 | |
@@ -143,6 +143,7 @@ | |
{ | |
{ "binary", no_argument, NULL, 'b' }, | |
{ "check", no_argument, NULL, 'c' }, | |
+ { "full", no_argument, NULL, 'f' }, | |
{ "quiet", no_argument, NULL, QUIET_OPTION }, | |
{ "status", no_argument, NULL, STATUS_OPTION }, | |
{ "text", no_argument, NULL, 't' }, | |
@@ -184,6 +185,9 @@ | |
fputs (_("\ | |
--tag create a BSD-style checksum\n\ | |
"), stdout); | |
+ printf (_("\ | |
+ -f, --full prints the checksum and file name\n\ | |
+")); | |
if (O_BINARY) | |
fputs (_("\ | |
-t, --text read in text mode (default if reading tty stdin)\n\ | |
@@ -696,6 +700,7 @@ | |
int opt; | |
bool ok = true; | |
int binary = -1; | |
+ bool prefix_short = true; | |
bool prefix_tag = false; | |
/* Setting values of global variables. */ | |
@@ -711,7 +716,7 @@ | |
so that processes running in parallel do not intersperse their output. */ | |
setvbuf (stdout, NULL, _IOLBF, 0); | |
- while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1) | |
+ while ((opt = getopt_long (argc, argv, "bcftw", long_options, NULL)) != -1) | |
switch (opt) | |
{ | |
case 'b': | |
@@ -733,6 +738,9 @@ | |
warn = true; | |
quiet = false; | |
break; | |
+ case 'f': | |
+ prefix_short = false; | |
+ break; | |
case QUIET_OPTION: | |
status_only = false; | |
warn = false; | |
@@ -836,7 +844,7 @@ | |
output in this case. */ | |
bool needs_escape = strchr (file, '\\') || strchr (file, '\n'); | |
- if (prefix_tag) | |
+ if (prefix_tag && !prefix_short) | |
{ | |
if (needs_escape) | |
putchar ('\\'); | |
@@ -847,17 +855,23 @@ | |
fputs (") = ", stdout); | |
} | |
+ if (prefix_short && !prefix_tag) | |
+ { | |
+ if (needs_escape) | |
+ putchar ('\\'); | |
+ } | |
+ | |
size_t i; | |
/* Output a leading backslash if the file name contains | |
a newline or backslash. */ | |
- if (!prefix_tag && needs_escape) | |
+ if (!prefix_tag && !prefix_short && needs_escape) | |
putchar ('\\'); | |
for (i = 0; i < (digest_hex_bytes / 2); ++i) | |
printf ("%02x", bin_buffer[i]); | |
- if (!prefix_tag) | |
+ if (!prefix_tag && !prefix_short) | |
{ | |
putchar (' '); | |
--- a/man/md5sum.x | |
+++ b/man/md5sum.x | |
@@ -1,8 +1,8 @@ | |
[NAME] | |
-md5sum \- compute and check MD5 message digest | |
+md5 \- compute and check MD5 message digest | |
[DESCRIPTION] | |
.\" Add any additional description here | |
[BUGS] | |
The MD5 algorithm should not be used any more for security related purposes. | |
Instead, better use an SHA\-2 algorithm, implemented in the programs | |
-sha224sum(1), sha256sum(1), sha384sum(1), sha512sum(1) | |
+sha224(1), sha256(1), sha384(1), sha512(1) | |
--- a/man/sha1sum.x | |
+++ b/man/sha1sum.x | |
@@ -1,4 +1,4 @@ | |
[NAME] | |
-sha1sum \- compute and check SHA1 message digest | |
+sha1 \- compute and check SHA1 message digest | |
[DESCRIPTION] | |
.\" Add any additional description here | |
--- a/man/sha224sum.x | |
+++ b/man/sha224sum.x | |
@@ -1,4 +1,4 @@ | |
[NAME] | |
-sha224sum \- compute and check SHA224 message digest | |
+sha224 \- compute and check SHA224 message digest | |
[DESCRIPTION] | |
.\" Add any additional description here | |
--- a/man/sha256sum.x | |
+++ b/man/sha256sum.x | |
@@ -1,4 +1,4 @@ | |
[NAME] | |
-sha256sum \- compute and check SHA256 message digest | |
+sha256 \- compute and check SHA256 message digest | |
[DESCRIPTION] | |
.\" Add any additional description here | |
--- a/man/sha384sum.x | |
+++ b/man/sha384sum.x | |
@@ -1,4 +1,4 @@ | |
[NAME] | |
-sha384sum \- compute and check SHA384 message digest | |
+sha384 \- compute and check SHA384 message digest | |
[DESCRIPTION] | |
.\" Add any additional description here | |
--- a/man/sha512sum.x | |
+++ b/man/sha512sum.x | |
@@ -1,4 +1,4 @@ | |
[NAME] | |
-sha512sum \- compute and check SHA512 message digest | |
+sha512 \- compute and check SHA512 message digest | |
[DESCRIPTION] | |
.\" Add any additional description here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment