]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/dvd-writepart.in
Add drive name to reserved Volume list printout in SD.
[bacula/bacula] / bacula / scripts / dvd-writepart.in
1 #!@PYTHON@
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 %e %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 growcmd = "@GROWISOFS@"
21
22 growcmd += " -use-the-force-luke=tty"
23 growcmd += " -quiet"
24
25 # Comment the following line if you want the tray to be reloaded
26 # when writing ends.
27 growcmd += " -use-the-force-luke=notray"
28
29 #### You should probably not modify anything below this line
30
31 import popen2
32 import os
33 import sys
34 import time
35 import signal
36
37 pid=0
38
39 def is4gbsupported():
40    processi = popen2.Popen4("uname -s -r")
41    status = processi.wait()
42    if not os.WIFEXITED(status):
43       print "dvd-writepart: Cannot execute uname, allowing to cross the 4gb boundary."
44       return 1
45    if os.WEXITSTATUS(status) != 0:
46       print "dvd-writepart: Cannot execute uname, allowing to cross the 4gb boundary."
47       return 1
48    strres = processi.fromchild.readline()[0:-1]
49    res = strres.split(" ")
50    if len(res) != 2:
51       print "dvd-writepart: Unable to parse uname (" + strres + "), allowing to cross the 4gb boundary."
52       return 1
53    if res[0] != "Linux":
54       print "dvd-writepart: The current OS is no Linux, allowing to cross the 4gb boundary."
55       return 1
56    ver = res[1].split(".")
57    if len(ver) < 3:
58       print "dvd-writepart: Unable to parse version string (" + res[1] + "), allowing to cross the 4gb boundary."
59       return 1
60    subver = ver[2].split("-")
61    
62    if ((not ver[0].isdigit()) or (not ver[1].isdigit()) or (not subver[0].isdigit())):
63       print "dvd-writepart: Unable to parse version string (" + res[1] + "), allowing to cross the 4gb boundary."
64       return 1
65    
66    if (int(ver[0]) > 2) or (int(ver[1]) > 6) or ((int(ver[0]) == 2) and (int(ver[1]) == 6) and (int(subver[0]) >= 8)):
67       print "dvd-writepart: Kernel version >=2.6.8, allowing to cross the 4gb boundary."
68       return 1
69    else:
70       print "dvd-writepart: Kernel version <2.6.8, not allowing to cross the 4gb boundary."
71       return 0
72
73 def term_handler(signum, frame):
74    print 'dvd-writepart: Signal term_handler called with signal', signum
75    if pid != 0:
76       print "dvd-writepart: Sending SIGTERM to pid", pid
77       os.kill(pid, signal.SIGTERM)
78       time.sleep(3)
79       print "dvd-writepart: Sending SIGKILL to pid", pid
80       os.kill(pid, signal.SIGKILL)
81       sys.exit(1)
82
83 if len(sys.argv) != 4:
84    print "dvd-writepart: Wrong number of arguments."
85    sys.exit(1)
86
87 if is4gbsupported():
88    growcmd += " -use-the-force-luke=4gms"
89
90 if sys.argv[1] == "0":
91    growcmd += " -M"
92 else:
93    growcmd += " -Z"
94
95 growcmd += " " + sys.argv[2] # device
96 growcmd += " -R " + sys.argv[3] # filename
97
98 #Test cmd:
99 #growcmd = "bash -c \"while [ 1 ]; do echo \"G\"; sleep 5; done\""
100
101 print "dvd-writepart: executing: " + growcmd
102
103 signal.signal(signal.SIGTERM, term_handler)
104
105 processi = popen2.Popen4(growcmd)
106 pid = processi.pid
107 status = processi.poll()
108 while status == -1:
109    line = processi.fromchild.readline()
110    while len(line) > 0:
111       print line,
112       line = processi.fromchild.readline()
113    time.sleep(1)
114    status = processi.poll()
115
116 if os.WEXITSTATUS(status) != 0:
117    print "dvd-writepart: Bad exit status " + str(os.WEXITSTATUS(status))
118    sys.exit(os.WEXITSTATUS(status))
119