From 65772d9278d5fbea7a187f2d1e372dfc5dd0c56e Mon Sep 17 00:00:00 2001 From: Justin Davis Date: Wed, 15 Aug 2012 16:51:00 -0400 Subject: injectdigs will use md5/sha512sum or openssl. --- bin/injectdigs | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'bin') diff --git a/bin/injectdigs b/bin/injectdigs index 2414acd..da8b7a4 100755 --- a/bin/injectdigs +++ b/bin/injectdigs @@ -4,24 +4,55 @@ 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" } 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 = "" -- cgit v1.2.3-24-g4f1b