5 mailto=carl@ecbaldwin.net
8 imagedir="/backup/imgs"
10 # Discover disk images by looking for .img.md5sum files in $imagedir
11 imgmd5=$(ls $imagedir/*.img.md5sum | head -n 1)
15 # If we didn't find an non-empty file then exit gracefully
16 [ -z "$imgmd5" ] && exit 0
17 [ -s "$imgmd5" ] || exit 0
19 # Get the name of the disk image by stripping off the tailing '.md5sum'
22 # A little paranoia. Make sure the disk image file is there.
23 [ -z "$img" ] && exit 1
24 [ -s "$img" ] || exit 1
26 # Burn the image to a disk.
27 cdrecord-wrapper.sh -dao dev=$sdev $isoimage > $logfile 2>&1
29 if [ 0 != "$?" ]; then
30 echo >&2 "cdrecord failed!"
34 # Now verify the disk by running md5sum on the entire contents of the disk
36 dd if=$dev bs=1M count=4440 2>$logfile | md5sum | awk '{print$1}' > $md5sum
38 # Check that the md5sums match
39 if ! cmp $md5sum $isoimage.md5sum; then
40 echo "Failed" | mailx -s "DVD md5sum doesn't match image file!!!" $mailto
44 # Record the date in the stat file to indicate that this burn was a success
51 echo "md5sum of burned disks:"
55 } | mailx -s "DVD burned. File it as ${img%.*}" $mailto > $logfile 2>&1
57 # Two lines in the stat file indicate two successful burns. Clean-up the image.
58 if [ "$(wc -l $img.stat 2>/dev/null)" == "2" ]; then
59 # Burned the image twice. Removing it and associated files!
60 rm -f $img{,.md5sum,.stat}
61 [ -d $img.mnt ] && rmdir $img.mnt