3 export PATH=$(dirname $0):/bin:/usr/bin:/sbin
5 # source the default configuration
8 # source the system specific configuration
9 [ -f /etc/lsbackups.conf ] && . /etc/lsbackups.conf
11 # If the noburn file is there then don't burn.
12 [ -f "$noburnfile" ] && exit 0
14 # Discover disk images by looking for .iso.md5sum files in $imagedir
15 imgmd5=$(ls $imagedir/*.iso.md5sum 2>/dev/null | head -n 1)
17 # If we didn't find an non-empty file then exit gracefully
18 [ -z "$imgmd5" ] && exit 0
19 [ -s "$imgmd5" ] || exit 0
23 # Get the name of the disk image by stripping off the tailing '.md5sum'
28 # Now check to see if we need to cache the image to a local drive before burning the image
29 if [[ $cacheburnimg == 1 && -d $cacheburnimgdir ]]; then
30 rsync -av --exclude '*.mnt' $img* $cacheburnimgdir > $logfile 2>&1
32 cat $logfile | mailx -s "backups: failed to cache $img to local dir $cacheburnimgdir !!!" $mailto
35 img=$cacheburnimgdir/$(basename "$img")
38 # A little paranoia. Make sure the disk image file is there.
39 [ -z "$img" ] && exit 1
40 [ -s "$img" ] || exit 1
42 # To avoid buffer underruns I'm going to stop cron and renice myself
46 # Burn the image to a disk.
47 cdrecord-wrapper.sh $cdrecordopts dev=$sdev $img > $logfile 2>&1
49 if [ "0" != "$?" ]; then
50 echo >&2 "cdrecord failed!"
52 cat $logfile | grep -v -e '[
\b\r]' | mailx -s "backups: failed to burn $img!!!" $mailto
56 # We don't need to be high-priority anymore.
60 # I don't know if this *really* helps but give cdrecord a chance to clean up.
63 # Now verify the disk by running md5sum on the entire contents of the disk
65 dd if=$dev bs=1M count=$imagesizemb 2>>$logfile | md5sum | awk '{print$1}' > $md5sum
67 # Check that the md5sums match
68 if ! cmp $md5sum $img.md5sum; then
69 echo "md5sum check FAILED" >> $logfile
70 echo "dd if=$dev bs=1M count=$imagesizemb 2>>$logfile | md5sum | awk '{print\$1}' > $md5sum" >> $logfile
71 e2label $dev >> $logfile 2>&1
72 cat $logfile | grep -v -e '[
\b\r]' | mailx -s "DVD md5sum doesn't match image file!!!" $mailto
76 # Record the date in the stat file to indicate that this burn was a success
79 # Update the source file stat file if we burned a cached copy of the image
80 [[ $cacheburnimg == 1 && -d $cacheburnimgdir ]] && date >> ${imgmd5%.md5sum}.stat
86 echo "md5sum of burned disks:"
92 } | grep -v -e '[
\b\r]' | mailx -s "DVD burned. File as $(basename ${img%.*})" $mailto >> $logfile 2>&1
94 # Two lines in the stat file indicate two successful burns. Clean-up the image.
95 if [ "$(wc -l $img.stat 2>/dev/null | awk '{print$1}')" == "$makeXcopies" ]; then
96 # Burned the image $makeXcopies number of times. Removing it and associated files!
97 if [[ $cacheburnimg == 1 && -d $cacheburnimgdir ]]; then
98 # Remove our cached copy of the image, its md5sum, and stat file
99 rm -f $img{,.md5sum,.stat}
100 # Now restore our $img variable to point back to the original source file
101 img=${imgmd5%.md5sum}
103 rm -f $img{,.md5sum,.stat}
104 [ -d $img.mnt ] && rmdir $img.mnt