mirror of
https://github.com/SinTan1729/CheckIntegrity.git
synced 2024-12-26 00:28:36 -06:00
Added some error management and "-h" for help
This commit is contained in:
parent
72ccd3e492
commit
d7bcc93a14
2 changed files with 27 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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**
|
||||
|
|
Loading…
Reference in a new issue