diff options
author | Justin Davis <jrcd83@gmail.com> | 2012-08-15 22:51:00 +0200 |
---|---|---|
committer | Justin Davis <jrcd83@gmail.com> | 2012-08-15 22:51:00 +0200 |
commit | 65772d9278d5fbea7a187f2d1e372dfc5dd0c56e (patch) | |
tree | 9d1abc9e6c05d257616666b38508ec90811167ec /bin | |
parent | fa7a4392877b26fc8a24e7cb8adec4f263da4798 (diff) | |
download | genpkg-65772d9278d5fbea7a187f2d1e372dfc5dd0c56e.tar.gz genpkg-65772d9278d5fbea7a187f2d1e372dfc5dd0c56e.tar.xz |
injectdigs will use md5/sha512sum or openssl.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/injectdigs | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/bin/injectdigs b/bin/injectdigs index 2414acd..da8b7a4 100755 --- a/bin/injectdigs +++ b/bin/injectdigs @@ -4,18 +4,30 @@ PROG=injectdigs if [ $# -eq 0 ] then - digstr="md5 sha512" + digs="md5 sha512" else - digstr=$* + digs=$* fi -if ! which openssl > /dev/null -then - echo "$PROG: openssl needs to be installed to calculate digests" - exit 2 -fi +openssl=0 +for dig in $digs +do + if ! which "${dig}sum" >/dev/null 2>&1 + then + openssl=1 + break + fi +done -awk -v digstr="$digstr" -v prog="$PROG" ' +case $openssl in +1) if ! which openssl >/dev/null 2>&1 + then + echo "$PROG: [`echo $digs | tr ' ' /`]sum or openssl need to be installed" + exit 2 + fi +esac + +awk -v digstr="$digstr" -v openssl="$openssl" -v prog="$PROG" ' BEGIN { diglen = split(digstr, digalgs) FS = "\n"; RS = ""; ORS = "\n\n" @@ -23,6 +35,25 @@ BEGIN { function calcdigs(alg, files) { + if(0+openssl){ + return openssldigs(alg, files) + }else{ + return sumdigs(alg, files) + } +} + +function sumdigs(alg, files) +{ + cmd = alg "sum " files + digests = "" + while(cmd | getline > 0){ + digests = digests $1 "\n" + } + close(cmd) + return digests +} +function openssldigs(alg, files) +{ cmd = "openssl " alg " " files digests = "" while(cmd | getline > 0){ |