Skip to content

Instantly share code, notes, and snippets.

@morhekil
Created April 26, 2009 20:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morhekil/102155 to your computer and use it in GitHub Desktop.
Save morhekil/102155 to your computer and use it in GitHub Desktop.
Disk image verification script for OS X
#!/bin/bash
# This OS X script reads the disk, calculates it's checksum, and then compares
# it to the checksum of the original image.
# Was written originally to verify burned images of XBox 360 games, but
# can be actually used to verify any image at all, I guess.
#
# Run it with image's file name as the argument:
# ./verifyiso ~/path/image.iso
# Names of the DVD drive device (say /dev/disk2), replace with your own
DISKNAME="disk2"
echo -n "Unmounting disk drive..."
hdiutil unmount /dev/$DISKNAME
isoname=$1
byteslen=`ls -l $isoname | awk '{ print $5 }'`
blockslen=`echo "$byteslen / 2048" | bc`
echo "Length is $blockslen blocks"
echo "Reading DVD and calculating disk checksum..."
md5drive=`dd if=/dev/$DISKNAME bs=2048 count=$blockslen | md5`
echo -n "Done with reading, ejecting the disk now..."
hdiutil eject /dev/$DISKNAME
echo -n "Calculating local checksum..."
md5local=`md5 $isoname | awk '{ print $4 }'`
echo $md5local
echo ""
if [ $md5local = $md5drive ]; then
echo "Checksums are EQUAL:"
else
echo "Checksums are DIFFERENT:"
fi
echo "local: $md5local"
echo "drive: $md5drive"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment