Created
January 6, 2018 22:22
-
-
Save Sulter/32bdbc3e537b46c6b522107a6eca146c to your computer and use it in GitHub Desktop.
copies .img onto block device and cheks for errors (md5sum comparison).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
usage="$(basename "$0") [-h] [-i path] [-o path] | |
copies .img onto block device and cheks for errors (md5sum comparison). | |
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 | |
sudo dd bs=4M if=$inPath of=$outPath status=progress conv=fsync | |
sudo sync | |
#status=none | |
md5blk=$(sudo dd status=none if=$outPath bs=512 count=$((`stat -c%s $inPath`/512)) | md5sum | awk '{print $1}') | |
md5img=$(sudo 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