Skip to content

Instantly share code, notes, and snippets.

@Sulter
Created October 30, 2017 15:40
Show Gist options
  • Save Sulter/0a36f7aac6ff623fca91960bc930c252 to your computer and use it in GitHub Desktop.
Save Sulter/0a36f7aac6ff623fca91960bc930c252 to your computer and use it in GitHub Desktop.
checks if there were no errors doing dd to a block device
#!/bin/sh
usage="$(basename "$0") [-h] [-i path] [-o path]
md5sum comparison of .img and a block device.
where:
-h show this help text
-i path to .img (i.e. /home/debian.img)
-o path to blk device (i.e. /dev/sda etc.)
"
while getopts ':hi:o:' option; do
case "${option}" in
h)
echo "$usage"
exit
;;
i)
inPath=$OPTARG
;;
o)
outPath=$OPTARG
;;
:)
printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?)
printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
if [ "$#" -lt 4 ]
then
echo "Not enough argumnets" >&2
echo "$usage" >&2
exit 1
fi
#status=none
md5blk=$(sudo -k dd status=none if=$outPath bs=512 count=$((`stat -c%s $inPath`/512)) | md5sum | awk '{print $1}')
md5img=$(dd status=none if=$inPath bs=512 count=$((`stat -c%s $inPath`/512)) | md5sum | awk '{print $1}')
echo "blk: " $md5blk
echo "img: " $md5img
if [ "$md5blk" = "$md5img" ]; then
echo "Match"
else
echo "Error, no match!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment