More stuff
[backups/.git] / scripts / burn-imgs.sh
1 #!/bin/sh
2
3 PATH=$(dirname $0):/bin:/usr/bin
4
5 . config.sh
6
7 # If the noburn file is there then don't burn.
8 [ -f "$burnlockfile" ] && exit 0
9
10 # Discover disk images by looking for .img.md5sum files in $imagedir
11 imgmd5=$(ls $imagedir/*.img.md5sum | head -n 1)
12
13 logfile=$(tempfile)
14
15 # If we didn't find an non-empty file then exit gracefully
16 [ -z "$imgmd5" ] && exit 0
17 [ -s "$imgmd5" ] || exit 0
18
19 # Get the name of the disk image by stripping off the tailing '.md5sum'
20 img=${imgmd5%.md5sum}
21
22 # A little paranoia.  Make sure the disk image file is there.
23 [ -z "$img" ] && exit 1
24 [ -s "$img" ] || exit 1
25
26 # Burn the image to a disk.
27 cdrecord-wrapper.sh -dao dev=$sdev $isoimage > $logfile 2>&1
28
29 if [ 0 != "$?" ]; then
30   echo >&2 "cdrecord failed!"
31   exit 1
32 fi
33
34 # Now verify the disk by running md5sum on the entire contents of the disk
35 md5sum=$(tempfile)
36 dd if=$dev bs=1M count=4440 2>$logfile | md5sum | awk '{print$1}' > $md5sum
37
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
41   exit 1
42 fi
43
44 # Record the date in the stat file to indicate that this burn was a success
45 date >> $img.stat
46
47 touch $burnlockfile
48
49 { # Send e-mail
50   echo "Image md5sum:"
51   cat $img.md5sum
52   echo
53   echo "md5sum of burned disks:"
54   cat $img.stat
55   echo
56   cat $logfile
57 } | mailx -s "DVD burned.  File it as ${img%.*}" $mailto > $logfile 2>&1
58
59 # Two lines in the stat file indicate two successful burns.  Clean-up the image.
60 if [ "$(wc -l $img.stat 2>/dev/null)" == "2" ]; then
61   # Burned the image twice.  Removing it and associated files!
62   rm -f $img{,.md5sum,.stat}
63   [ -d $img.mnt ] && rmdir $img.mnt
64 fi