Oops, adding ninjahelper to Makefile
[matthijs/upstream/backupninja.git] / handlers / makecd
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 #
3 # burncd handler script for backupninja
4 #
5 getconf backupdir /var/backups/makecd
6 getconf exclude
7 getconf target
8 getconf burnertype cd
9 getconf system no
10 getconf isoonly yes
11 getconf imagefile backup.iso
12 getconf device
13
14 # define needed executables:
15 MKISOFS="/usr/bin/mkisofs"
16 GROWISOFS="/usr/bin/growisofs"
17 #CDRECORD="/usr/bin/cdrecord"
18 CDRECORD="/usr/bin/cdrecord.mmap"
19 CDRDAO="/usr/bin/cdrdao"
20 DVDINFO="/usr/bin/dvd+rw-mediainfo"
21
22 # create backup dirs and check existence of progs.
23
24 [ -d $backupdir ] || mkdir -p $backupdir
25 [ -d $backupdir ] || fatal "Backup directory '$backupdir'"
26 [ -e "$target" ]  || fatal "target does not exist "
27
28 [ -x "$MKISOFS" ]   || debug 3 "echo executable mkisofs not present"
29 [ -x "$GROWISOFS" ] || debug 3 "echo executable growisofs not present"
30 [ -x "$CDRECORD" ]  || debug 3 "echo executable cdrecord not present"
31 [ -x "$CDRDAO" ]    || debug 3 "echo executable cdrdao not present"
32
33 if [ "$isoonly" == "no" ]; then
34         [ -e $device ] || fatal "No Burner device available"
35 fi
36
37 outputfile="$backupdir/$imagefile"
38 execstr="$MKISOFS --quiet -R -o $outputfile "
39
40 str=""
41 # excludes
42 for i in $exclude; do
43         str=" -x ${i}$str"
44 done
45
46 debug 0 "echo $str "
47 execstr="${execstr} $str $target "
48 debug 0 "echo $execstr "
49
50 output=` $execstr 2>&1 `
51 code=$?
52 if [ "$code" == "0" ]; then
53         debug $output
54         info "Successfully finished creation of iso"
55 else
56         warning $output
57         warning "Failed to create iso"
58 fi
59
60 if [ "$isoonly" == "no" ]; then
61
62         if [ "$burnertype" == "cd" ]; then 
63                 # burning iso to CD
64                 $CDRECORD -v gracetime=2 dev=$device speed=8 -dao -data $outputfile 
65                 code=$?
66                 if [ "$code" == "0" ]; then
67                         debug $output
68                         info "Successfully burned CD"
69                 else
70                         warning $output
71                         warning "Failed to create CD"
72                 fi
73         fi
74         if [ "$burnertype" == "dvd" ]; then 
75                 # burning iso dvd
76                 $GROWISOFS -speed=2 -Z $device=$outputfile -use-the-force-luke=notray -use-the-force-luke=tty
77                 code=$?
78                 if [ "$code" == "0" ]; then
79                         debug $output
80                         info "Successfully burned DVD"
81                 else
82                         warning $output
83                         warning "Failed to create DVD"
84                 fi
85         fi
86 fi
87 return 0