Use a portable version of MD5.

This commit is contained in:
tlimoncelli@stackexchange.com
2014-09-01 18:59:22 +00:00
parent d6a20b049f
commit 01a9292d9d

View File

@@ -154,12 +154,12 @@ function decrypt_file_overwrite() {
unencrypted="$2" unencrypted="$2"
if [[ -f "$unencrypted" ]]; then if [[ -f "$unencrypted" ]]; then
old_hash=$(md5sum < "$unencrypted"| awk '{ print $1 }') old_hash=$(md5sum_file "$unencrypted")
else else
old_hash=unmatchable old_hash=unmatchable
fi fi
gpg --yes -q --decrypt -o "$unencrypted" "$encrypted" gpg --yes -q --decrypt -o "$unencrypted" "$encrypted"
new_hash=$(md5sum < "$unencrypted"| awk '{ print $1 }') new_hash=$(md5sum_file "$unencrypted")
if [[ $old_hash != $new_hash ]]; then if [[ $old_hash != $new_hash ]]; then
echo "========== EXTRACTED $unencrypted" echo "========== EXTRACTED $unencrypted"
fi fi
@@ -183,6 +183,22 @@ function shred_file() {
$CMD $OPT "$name" $CMD $OPT "$name"
} }
function md5sum_file() {
# Portably generate the MD5 hash of file $1.
case $(uname -s) in
Darwin )
md5 -r "$1" | awk '{ print $1 }'
;;
Linux )
md5sum "$1" | awk '{ print $1 }'
;;
* )
echo 'ERROR: Unknown OS. Exiting.'
exit 1
;;
esac
}
# $1 is the name of a file that contains a list of files. # $1 is the name of a file that contains a list of files.
# For each filename, output the individual subdirectories # For each filename, output the individual subdirectories
# leading up to that file. i.e. one one/two one/two/three # leading up to that file. i.e. one one/two one/two/three