Skip to content

Instantly share code, notes, and snippets.

@piaoger
Last active August 16, 2016 06:33
Show Gist options
  • Save piaoger/da7b6973dd145681890e38026e288809 to your computer and use it in GitHub Desktop.
Save piaoger/da7b6973dd145681890e38026e288809 to your computer and use it in GitHub Desktop.
md5 checksum
#md5 generation
# linux: md5sum file >md5file
# mac: md5 -r file >md5file
#Md5 comparison
# linux: md5sum -c md5file
# mac: manual check ?
function find_md5sum() {
OS=$(uname)
# brew install md5sha1sum
if [ "Darwin" == "$OS" ]; then
echo "md5 -r"
elif [ "Linux" == "$OS" ]; then
echo "md5sum"
else
echo "Unsupported os: $OS"
exit 1
fi
}
md5sum=`find_md5sum`
#create md5 file
#${md5sum} update-modules-update.sh | awk {'print $1'} >digest.md5
NEWVAL=`${md5sum} update-modules-update.sh | awk {'print $1'}`
OLDVAL=`cat ./digest.md5`
if [ "$NEWVAL" != "$OLDVAL" ] ; then
echo "not equal"
#do something...
else
echo "equal"
#do something...
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment