From d7bcc93a14c1201f3de8e9eb4b07ab33cb8cfd80 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Fri, 26 Jun 2020 21:17:30 +0530 Subject: [PATCH] Added some error management and "-h" for help --- CheckIntegrity | 27 +++++++++++++++++++++++++-- README.md | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CheckIntegrity b/CheckIntegrity index 8aea056..d54e83c 100755 --- a/CheckIntegrity +++ b/CheckIntegrity @@ -1,10 +1,33 @@ #!/bin/sh +# formatting +bold=$(tput bold) +normal=$(tput sgr0) + +# error function +error(){ + printf "The syntax is as follows :\n\n\t${bold}CheckIntegrity algo filename hash${normal}\n\n${bold}algo${normal} is the algorithm to use (e.g. md5, sha1, sha256 etc.)\n${bold}filename${normal} is the relative/full path to file\n${bold}hash${normal} is the given hash to match with\n\n" +} + +# check if asking for help +if [ $# -eq 1 ] && [ $1 = "-h" ]; then + error + exit 1 +fi + +# check validity of input +if [ $# -ne 3 ]; then + printf "${bold}Input is wrong!${normal}\n\n" + error + exit -1 +fi + +# main code f=$1 f+="sum $2 | cut -d ' ' -f1" if [ $(eval $f) = "$3" ]; then - echo "$2 is fine." + echo "$2 is ${bold}fine.${normal}" else - echo "$2 is corrupted!" + echo "$2 is ${bold}corrupted!${normal}" fi diff --git a/README.md b/README.md index 2a3eb0d..47b20be 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ The syntax is as follows : `hash` is the given hash to match with +You can type `CheckIntegrity -h` for help. + ### _You might buy me a cup of coffee:_ **UPI (preferred) : sayantan.santra@paytm**