Warning: I've done no testing of this script on anything other than my own machine. Take care when running these scripts, as they can result in wiping the wrong disk if you are not careful. You've been warned.
To speed up imaging of disks instead of using dd and copying the whole thing (including blocks that are just full of zeroes), we can use partclone to be more intelligent about things. This is a two step process, first we must prepare the image to something partclone knows how to use, and then we can restore it to our disks.
apt-get install partclone fdisk mount