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