mirror of
https://github.com/SinTan1729/CheckIntegrity.git
synced 2024-12-26 00:28:36 -06:00
25 lines
736 B
Bash
25 lines
736 B
Bash
#!/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
|
|
[ $# -eq 1 ] & [ $1 = "-h" ] && error && exit 1
|
|
|
|
# check validity of input
|
|
[ $# -ne 3 ] && printf "${bold}Input is wrong!${normal}\n\n" && error && exit -1
|
|
|
|
# main code
|
|
f="$1sum $2 | cut -d ' ' -f1"
|
|
|
|
if [ $(eval $f) = "$3" ]; then
|
|
echo "$2 is ${bold}fine.${normal}"
|
|
else
|
|
echo "$2 is ${bold}corrupted!${normal}"
|
|
fi
|