]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/dvd-writepart.in
Update dvd-writepart (auto-detect kernel version, integrated watchdog).
[bacula/bacula] / bacula / scripts / dvd-writepart.in
1 #!/bin/bash
2 #
3 # Bacula interface to growisofs, used to write to DVD+/-R(W)
4 #
5 #  $Id$
6 #
7 #  If you set in your Device resource
8 #
9 #  Write Part Command = "path-to-this-script/dvd-writepart %n %a %v"
10 #    you will have the following input to this script:
11 #
12 #  dvd-writepart "erase"  "device"  "part_filename"
13 #                   $1       $2           $3
14 #
15 #  for example:
16 #
17 #  dvd-writepart 0 /dev/hda File-0001
18
19 MKISOFS=@MKISOFS@
20 GROWISOFS=@GROWISOFS@
21
22 # GROWARGS="-use-the-force-luke=tty -quiet"
23 GROWARGS="-quiet"
24
25 # Uncomment the following line if you do not want the tray to be reloaded
26 # when writing ends.
27 GROWARGS="${GROWARGS} -use-the-force-luke=notray"
28
29 #### You should probably not modify anything below this line
30
31 # If Linux kernel version >=2.6.8, allow a session to start beyond the
32 # 4gb boundary.
33 kver=`uname -r | cut -d. -f1,2`
34 ksubver=`uname -r | cut -d. -f3 | cut -d- -f1`
35
36 if test "a$kver" = "a2.6" ; then
37    if test "$ksubver" > 7 ; then
38       echo "Kernel version >= 2.6.8, allowing to cross the 4gb boundary."
39       GROWARGS="${GROWARGS} -use-the-force-luke=4gms"
40    fi
41 fi
42
43 if test $# -ne 3 ; then
44   echo "usage: dvd-writepart part_number device part_filename"
45   echo "  Wrong number of arguments arguments given (!= 3)."
46   exit 1
47 fi
48
49 # Setup arguments
50 erase=$1
51 dev=$2
52 filename=$3
53
54 if test $erase = 1 ; then
55   arg="-Z"
56 else
57   arg="-M"  
58 fi
59
60 # Starts growisofs
61 echo Running ${GROWISOFS} ${GROWARGS} $arg $dev -R $filename...
62 ${GROWISOFS} ${GROWARGS} $arg $dev -R $filename &
63 #bash -c "while [ 1 ]; do echo "G"; sleep 1; done" &
64 growpid=$!
65 parentpid=$$
66
67 # Starts watchdog : checks if the parent is alive. If not, kill
68 # growisofs.
69
70 bash -c "rtn=0; while [ \$rtn = 0 ]; do sleep 5; ps -p $parentpid; rtn=\$?; echo W\$rtn; done; echo \"Parent dead killing $growpid\"; kill $growpid; sleep 5; kill -9 $growpid" &
71 watchpid=$!
72
73 # Waits for growisofs to stop
74 wait $growpid
75 rtn=$?
76
77 # Kill the watchdog
78 kill -9 $watchpid
79
80 exit $rtn