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
33 rsync -aIv --exclude '*.mnt' $img* $cacheburnimgdir >> $logfile 2>&1
35 cat $logfile | mailx -s "backups: failed to cache $img to local dir $cacheburnimgdir !!!" $mailto
39 img=$cacheburnimgdir/$(basename "$img")
42 # A little paranoia. Make sure the disk image file is there.
43 [ -z "$img" ] && exit 1
44 [ -s "$img" ] || exit 1
46 # To avoid buffer underruns I'm going to stop cron and renice myself
50 # Burn the image to a disk.
51 $cdrecord $cdrecordopts dev=$sdev $img >> $logfile 2>&1
53 if [ "0" != "$?" ]; then
54 echo >&2 "cdrecord failed!"
56 cat $logfile | grep -v -e '[
\b\r]' | mailx -s "backups: failed to burn $img!!!" $mailto
60 # We don't need to be high-priority anymore.
64 # I don't know if this *really* helps but give cdrecord a chance to clean up.
67 # Now verify the disk by running md5sum on the entire contents of the disk
69 dd if=$dev bs=1M count=$imagesizemb 2>>$logfile | md5sum | awk '{print$1}' > $md5sum
71 # Check that the md5sums match
72 if ! cmp $md5sum $img.md5sum; then
73 echo "md5sum check FAILED" >> $logfile
74 echo "dd if=$dev bs=1M count=$imagesizemb 2>>$logfile | md5sum | awk '{print\$1}' > $md5sum" >> $logfile
75 e2label $dev >> $logfile 2>&1
76 cat $logfile | grep -v -e '[
\b\r]' | mailx -s "DVD md5sum doesn't match image file!!!" $mailto
80 # Record the date in the stat file to indicate that this burn was a success
83 # Update the source file stat file if we burned a cached copy of the image
84 [[ $cacheburnimg == 1 && -d $cacheburnimgdir ]] && date >> ${imgmd5%.md5sum}.stat
90 echo "md5sum of burned disks:"
96 } | grep -v -e '[
\b\r]' | mailx -s "DVD burned. File as $(basename ${img%.*})" $mailto >> $logfile 2>&1
98 # Two lines in the stat file indicate two successful burns. Clean-up the image.
99 if [ "$(wc -l $img.stat 2>/dev/null | awk '{print$1}')" == "$makeXcopies" ]; then
100 # Burned the image $makeXcopies number of times. Removing it and associated files!
101 if [[ $cacheburnimg == 1 && -d $cacheburnimgdir ]]; then
102 # Remove our cached copy of the image, its md5sum, and stat file
103 rm -f $img{,.md5sum,.stat}
104 # Now restore our $img variable to point back to the original source file
105 img=${imgmd5%.md5sum}
107 rm -f $img{,.md5sum,.stat}
108 [ -d $img.mnt ] && rmdir $img.mnt