3 # Unpack disks from TCP transport.
5 # Copyright (C) 2007 Red Hat Inc.
6 # Written by Richard W.M. Jones <rjones@redhat.com>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 XXX This needs a rewrite
33 my $noninteractive = 0;
39 Getopt::Long::Configure ("bundling");
42 "d|directory=s", \$outputdir,
44 "n|noninteractive", \$noninteractive,
46 "help" => \$help, man => \$man,
48 pod2usage (1) if $help;
49 pod2usage (-exitstatus => 0, -verbose => 2) if $man;
54 # Process each input file.
59 open DISKS,"$filename" or die "$filename: $!";
60 my $zcat_open = 0; # If we have a pipe open to zcat now.
61 my $newline_chomped = 0; # If we need to add a \n
62 my $lineno = 0; # Current line number.
67 # Is it a header for the next disk image?
68 if (/^p2v (.*) (\d+)$/) {
72 # Close the previous file (if open).
73 close ZCAT if $zcat_open;
75 # Check the image name.
77 ($imagename =~ /\.\./ || $imagename =~ m{/} ||
78 $imagename !~ /^[-.A-Za-z0-9]+$/)) {
79 print "$filename: bad image name at line $lineno: $imagename\n";
82 $imagename = $outputdir . "/" . $imagename;
84 if (!$force && -f $imagename) {
85 print "$filename: disk image already exists at line $lineno: $imagename\n";
89 if (!$noninteractive) {
90 print "Write disk image $imagename ($sectors sectors)? (y/n) ";
92 exit 3 if $key =~ /^n/i;
95 open ZCAT, "| zcat > $imagename" or die "zcat: $!";
99 # Otherwise we're in the middle of data.
102 print "$filename: corrupt data at line $lineno\n";
105 print ZCAT "\n" if $newline_chomped;
107 $newline_chomped = 1; # For the next newline.
111 close ZCAT if $zcat_open;