Magellan Linux

Annotation of /trunk/file-roller/rpm2cpio-file-roller

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (hide annotations) (download)
Tue May 8 20:06:05 2007 UTC (17 years, 5 months ago) by niro
File size: 2556 byte(s)
-import

1 niro 144 #!/usr/bin/perl
2    
3     # Copyright (C) 1997,1998,1999, Roger Espel Llima
4     #
5     # Permission is hereby granted, free of charge, to any person obtaining a copy
6     # of this software and any associated documentation files (the "Software"), to
7     # deal in the Software without restriction, including without limitation the
8     # rights to use, copy, modify, merge, publish, distribute, sublicense,
9     # and/or sell copies of the Software, and to permit persons to whom the
10     # Software is furnished to do so, subject to the following conditions:
11     #
12     # The above copyright notice and this permission notice shall be included in
13     # all copies or substantial portions of the Software.
14     #
15     # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16     # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17     # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18     # SOFTWARE'S COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19     # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20     # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21     # THE SOFTWARE
22    
23     # (whew, that's done!)
24    
25     # why does the world need another rpm2cpio? because the existing one
26     # won't build unless you have half a ton of things that aren't really
27     # required for it, since it uses the same library used to extract RPM's.
28     # in particular, it won't build on the HPsUX box i'm on.
29    
30    
31     # add a path if desired
32     $gzip = "gzip";
33    
34     sub printhelp {
35     print "rpm2cpio, perl version by orabidoo <odar\@pobox.com>\n";
36     print "use: rpm2cpio [file.rpm]\n";
37     print "dumps the contents to stdout as a GNU cpio archive\n";
38     exit 0;
39     }
40    
41     if ($#ARGV == -1) {
42     printhelp if -t STDIN;
43     $f = "STDIN";
44     } elsif ($#ARGV == 0) {
45     open(F, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
46     $f = 'F';
47     } else {
48     printhelp;
49     }
50    
51     printhelp if -t STDOUT;
52    
53     # gobble the file up
54     undef $/;
55     $|=1;
56     $rpm = <$f>;
57     close ($f);
58    
59     ($magic, $major, $minor, $crap) = unpack("NCC C90", $rpm);
60    
61     die "Not an RPM\n" if $magic != 0xedabeedb;
62     die "Not a version 3 RPM\n" if $major != 3;
63    
64     $rpm = substr($rpm, 96);
65    
66     while ($rpm ne '') {
67     $rpm =~ s/^\c@*//s;
68     ($magic, $crap, $sections, $bytes) = unpack("N4", $rpm);
69     $smagic = unpack("n", $rpm);
70     last if $smagic eq 0x1f8b;
71     die "Error: header not recognized\n" if $magic != 0x8eade801;
72     $rpm = substr($rpm, 16*(1+$sections) + $bytes);
73     }
74    
75     die "bogus RPM\n" if $rpm eq '';
76    
77     open(ZCAT, "|gzip -cd") || die "can't pipe to gzip\n";
78     print STDERR "CPIO archive found!\n";
79    
80     print ZCAT $rpm;
81     close ZCAT;
82