Imported Upstream version 2.5.2p1
[debian/amanda] / dumper-src / generic-dumper.pl.in
1 require "newgetopt.pl";
2 use Text::ParseWords;
3
4 print DEBUG "FHOUT 6: ARGV[0]=" . $ARGV[0] . "\n" if ($debug == 1);
5 print DEBUG "FHOUT 6: ARGV[1]=" . $ARGV[1] . "\n" if ($debug == 1);
6 print DEBUG "FHOUT 6: ARGV[2]=" . $ARGV[2] . "\n" if ($debug == 1);
7 print DEBUG "FHOUT 6: ARGV[3]=" . $ARGV[3] . "\n" if ($debug == 1);
8 print DEBUG "FHOUT 6: ARGV[4]=" . $ARGV[4] . "\n" if ($debug == 1);
9 print DEBUG "FHOUT 6: ARGV[5]=" . $ARGV[5] . "\n" if ($debug == 1);
10 print DEBUG "FHOUT 6: ARGV[6]=" . $ARGV[6] . "\n" if ($debug == 1);
11 print DEBUG "FHOUT 6: ARGV[7]=" . $ARGV[7] . "\n" if ($debug == 1);
12 print DEBUG "FHOUT 6: ARGV[8]=" . $ARGV[8] . "\n" if ($debug == 1);
13 print DEBUG "FHOUT 6: ARGV[9]=" . $ARGV[9] . "\n" if ($debug == 1);
14
15 $result = &NGetOpt ("config=s", "host=s", "disk=s", "device=s", "level=s", "index=s", "message=s", "collection", "record");
16 $result = $result;
17
18 print DEBUG "FHOUT 6: config    =" . $opt_config . "\n" if ($debug == 1);
19 print DEBUG "FHOUT 6: disk      =" . $opt_disk   . "\n" if ($debug == 1);
20 print DEBUG "FHOUT 6: host      =" . $opt_host   . "\n" if ($debug == 1);
21 print DEBUG "FHOUT 6: device    =" . $opt_device . "\n" if ($debug == 1);
22 print DEBUG "FHOUT 6: level     =" . $opt_level  . "\n" if ($debug == 1);
23 print DEBUG "FHOUT 6: index     =" . $opt_index  . "\n" if ($debug == 1);
24 print DEBUG "FHOUT 6: message   =" . $opt_message. "\n" if ($debug == 1);
25 print DEBUG "FHOUT 6: collection=" . $opt_collection. "\n" if ($debug == 1);
26 print DEBUG "FHOUT 6: record    =" . $opt_record . "\n" if ($debug == 1);
27
28 print DEBUG "FHOUT 6: A-ARGV[0]=" . $ARGV[0] . "\n" if ($debug == 1);
29 print DEBUG "FHOUT 6: A-ARGV[1]=" . $ARGV[1] . "\n" if ($debug == 1);
30 print DEBUG "FHOUT 6: A-ARGV[2]=" . $ARGV[2] . "\n" if ($debug == 1);
31 print DEBUG "FHOUT 6: A-ARGV[3]=" . $ARGV[3] . "\n" if ($debug == 1);
32 print DEBUG "FHOUT 6: A-ARGV[4]=" . $ARGV[4] . "\n" if ($debug == 1);
33 print DEBUG "FHOUT 6: A-ARGV[5]=" . $ARGV[5] . "\n" if ($debug == 1);
34 print DEBUG "FHOUT 6: A-ARGV[6]=" . $ARGV[6] . "\n" if ($debug == 1);
35
36 if (defined $opt_config) {
37   $opt_config =~ /^([\_\.A-Za-z0-9]*)$/;
38   $opt_config = $1;
39 }
40
41 if (defined $opt_host) {
42   $opt_host =~ /^([\_\.A-Za-z0-9]*)$/;
43   $opt_host = $1;
44 }
45
46 if (defined $opt_disk) {
47   $opt_disk =~ /^([\/\_\:\.A-Za-z0-9]*)$/;
48   $opt_disk = $1;
49 }
50
51 if (defined $opt_device) {
52   $opt_device =~ /^([\/\_\:\.A-Za-z0-9]*)$/;
53   $opt_device = $1;
54 }
55
56 if (defined $opt_level) {
57   $opt_level =~ /^(\d)$/;
58   $opt_level = $1;
59 }
60
61 # Read tool property
62
63 $command = $ARGV[0];
64
65 %property = ();
66 while($property_line = <STDIN>) {
67   chomp $property_line;
68   ($prop_name, $prop_value) = shellwords($property_line);
69   push @{$property{$prop_name}}, $prop_value;
70   print DEBUG "$prop_name = $prop_value\n" if ($debug == 1);
71 }
72
73 if ($debug == 1) {
74   foreach $prop_name (keys(%property)) {
75     print DEBUG "PROPERTY: $prop_name\n";
76     print DEBUG "    VALUE: ", join(',',@{$property{$prop_name}}) , "\n";
77   }
78 }
79
80 sub wrapper_support();
81 sub wrapper_selfcheck();
82 sub wrapper_estimate();
83 sub wrapper_backup();
84 sub wrapper_restore();
85
86 if ($command eq "support") {
87    wrapper_support();
88 }
89 elsif ($command eq "selfcheck") {
90    wrapper_selfcheck();
91 }
92 elsif ($command eq "estimate") {
93    wrapper_estimate();
94 }
95 elsif ($command eq "backup") {
96    wrapper_backup();
97 }
98 elsif ($command eq "restore") {
99    wrapper_restore();
100 }
101 else {
102    printf STDERR "Unknown command `$command'.\n";
103    exit 1;
104 }
105
106
107 sub wrapper_support() {
108    if(defined(&command_support)) {
109       command_support($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
110       exit 0;
111    }
112    print "LEVEL 0-", $max_level , "\n" if defined($max_level);
113    print "INDEX-LINE YES\n"   if defined($index_line)   && $index_line   == 1;
114    print "INDEX-XML NO\n"     if defined($index_xml)    && $index_xml    == 1;
115    print "MESSAGE-LINE YES\n" if defined($message_line) && $message_line == 1;
116    print "MESSAGE-XML NO\n"   if defined($message_xml)  && $message_xml  == 1;
117    print "RECORD YES\n"       if defined($record)       && $record       == 1;
118    print "INCLUDE-FILE NO\n"  if defined($include_file) && $include_file == 1;
119    print "INCLUDE-LIST NO\n"  if defined($include_list) && $include_list == 1;
120    print "EXCLUDE-FILE NO\n"  if defined($exclude_file) && $exclude_file == 1;
121    print "EXCLUDE-LIST NO\n"  if defined($exclude_list) && $exclude_list == 1;
122    print "COLLECTION NO\n"    if defined($collection)   && $collection   == 1;
123    exit 1;
124 }
125
126 sub wrapper_selfcheck() {
127    if(defined(&command_selfcheck)) {
128       command_selfcheck($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
129    }
130    else {
131       exit 1;
132    }
133 }
134
135 sub wrapper_estimate() {
136    if(defined(&command_estimate)) {
137       command_estimate($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
138    } else {
139       exit 1;
140    }
141 }
142
143 sub wrapper_estimate_parse() {
144    if(defined(&command_estimate_parse)) {
145       command_estimate_parse($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
146    }
147    else {
148       printf STDERR "`estimate-parse' is not supported.\n";
149       exit 1;
150    }
151 }
152
153 sub wrapper_backup() {
154    if(defined(&command_backup)) {
155       command_backup($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
156    } else {
157 print DEBUG "wrapper_backup: !defined(command_backup)\n" if ($debug == 1);
158       exit 1;
159    }
160 }
161
162 sub wrapper_backup_parse() {
163    if(defined(&command_backup_parse)) {
164       command_backup_parse($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
165    }
166    else {
167       printf STDERR "`backup-parse' is not supported.\n";
168       exit 1;
169    }
170 }
171
172 sub wrapper_index_from_output() {
173    if(defined(&command_index_from_output)) {
174       command_index_from_output($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
175    }
176    else {
177       printf STDERR "`index-from-output' is not supported.\n";
178       exit 1;
179    }
180 }
181
182 sub wrapper_index_from_image() {
183    if(defined(&command_index_from_image)) {
184       command_index_from_image($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
185    }
186    else {
187       printf STDERR "command `index-from-image' is not supported.\n";
188       exit 1;
189    }
190 }
191
192 sub wrapper_restore() {
193    if(defined(&command_restore)) {
194       command_restore($opt_config, $opt_host, $opt_disk, $opt_device, $opt_level);
195    }
196    else {
197      printf STDERR "`restore' is not supported.\n";
198      exit 1;
199    }
200 }
201
202 sub parse_options() {
203    my($no_option) = @_;
204    my($options, @options, $option, $name, $option_name, $value);
205
206    while($no_option <= $#ARGV) {
207       $options = $ARGV[${no_option}];
208       @options = split (/;/,$options);
209       foreach $option (@options) {
210          if( $option =~ /=/ ) {
211             ($name,$value) = split(/=/,$option);
212          }
213          else {
214             $name  = $option;
215             $value = 1;
216          }
217          $option_name = "option_$name";
218          $option_name =~ s/\-/\_/g;
219          $$option_name = $value;
220       }
221       $no_option++;
222    }
223 }
224
225 sub check_file {
226    my($filename, $mode) = @_;
227
228    stat($filename);
229
230    if($mode eq "e") {
231       if( -e _ ) {
232          print "OK $filename exists\n";
233       }
234       else {
235          print "ERROR [can not find $filename]\n";
236       }
237    }
238    elsif($mode eq "x") {
239       if( -x _ ) {
240          print "OK $filename executable\n";
241       }
242       else {
243          print "ERROR [can not execute $filename]\n";
244       }
245    }
246    elsif($mode eq "r") {
247       if( -r _ ) {
248          print "OK $filename readable\n";
249       }
250       else {
251          print "ERROR [can not read $filename]\n";
252       }
253    }
254    elsif($mode eq "w") {
255       if( -w _ ) {
256          print "OK $filename writable\n";
257       }
258       else {
259          print "ERROR [can not write $filename]\n";
260       }
261    }
262    else {
263       print "ERROR [check_file: unknow mode $mode]\n";
264    }
265 }
266
267 sub check_dir {
268 }
269
270 sub check_suid {
271 }
272
273 1;