Skip to content

Instantly share code, notes, and snippets.

@inflation
Created October 30, 2016 23:01
Show Gist options
  • Save inflation/120998bfa304830421365fa9a894907a to your computer and use it in GitHub Desktop.
Save inflation/120998bfa304830421365fa9a894907a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
METHOD='md5'
usage() {
echo "Usage: cpsm [-m METHOD] filename [CHECKSUM]"
exit 1
}
[ $# -eq 0 ] && usage
while getopts :m: OPTION
do
case $OPTION in
m)
METHOD=$OPTARG
;;
\?)
usage
;;
esac
done
shift $(($OPTIND - 1))
if [[ $# -eq 0 ]]; then
usage
fi
CKSM=$(openssl $METHOD $1 | awk '{print $2}')
if [[ -z $2 ]];
then
echo $CKSM
exit 0;
fi
if [[ $CKSM == $2 ]];
then
echo 'Match!'
else
echo 'Not Match!'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment