rpm2cpio.pl revision 307
307N/A#!/usr/perl5/bin/perl
307N/A
307N/A# Copyright (C) 1997,1998,1999, Roger Espel Llima
307N/A#
307N/A# Permission is hereby granted, free of charge, to any person obtaining a copy
307N/A# of this software and any associated documentation files (the "Software"), to
307N/A# deal in the Software without restriction, including without limitation the
307N/A# rights to use, copy, modify, merge, publish, distribute, sublicense,
307N/A# and/or sell copies of the Software, and to permit persons to whom the
307N/A# Software is furnished to do so, subject to the following conditions:
307N/A#
307N/A# The above copyright notice and this permission notice shall be included in
307N/A# all copies or substantial portions of the Software.
307N/A#
307N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
307N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
307N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
307N/A# SOFTWARE'S COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
307N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
307N/A# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
307N/A# THE SOFTWARE
307N/A
307N/A# (whew, that's done!)
307N/A
307N/A# why does the world need another rpm2cpio? because the existing one
307N/A# won't build unless you have half a ton of things that aren't really
307N/A# required for it, since it uses the same library used to extract RPM's.
307N/A# in particular, it won't build on the HPsUX box i'm on.
307N/A
307N/A
307N/A# add a path if desired
307N/A$gzip = "gzip";
307N/A
307N/Asub printhelp {
307N/A print <<HERE;
307N/Arpm2cpio, perl version by orabidoo <odar\@pobox.com>
307N/Adumps the contents to stdout as a cpio archive
307N/A
307N/Ause: rpm2cpio [file.rpm] > file.cpio
307N/A
307N/AHere's how to use cpio:
307N/A list of contents: cpio -t -i < /file/name
307N/A extract files: cpio -d -i < /file/name
307N/AHERE
307N/A
307N/A exit 0;
307N/A}
307N/A
307N/Aif ($#ARGV == -1) {
307N/A printhelp if -t STDIN;
307N/A $f = "STDIN";
307N/A} elsif ($#ARGV == 0) {
307N/A open(F, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
307N/A $f = 'F';
307N/A} else {
307N/A printhelp;
307N/A}
307N/A
307N/Aprinthelp if -t STDOUT;
307N/A
307N/A# gobble the file up
307N/Aundef $/;
307N/A$|=1;
307N/A$rpm = <$f>;
307N/Aclose ($f);
307N/A
307N/A($magic, $major, $minor, $crap) = unpack("NCC C90", $rpm);
307N/A
307N/Adie "Not an RPM\n" if $magic != 0xedabeedb;
307N/Adie "Not a version 3 or 4 RPM\n" if $major != 3 && $major != 4;
307N/A
307N/A$rpm = substr($rpm, 96);
307N/A
307N/Awhile ($rpm ne '') {
307N/A $rpm =~ s/^\c@*//s;
307N/A ($magic, $crap, $sections, $bytes) = unpack("N4", $rpm);
307N/A $smagic = unpack("n", $rpm);
307N/A last if $smagic eq 0x1f8b;
307N/A die "Error: header not recognized\n" if $magic != 0x8eade801;
307N/A $rpm = substr($rpm, 16*(1+$sections) + $bytes);
307N/A}
307N/A
307N/Adie "bogus RPM\n" if $rpm eq '';
307N/A
307N/Aopen(ZCAT, "|gzip -cd") || die "can't pipe to gzip\n";
307N/Aprint STDERR "CPIO archive found!\n";
307N/A
307N/Aprint ZCAT $rpm;
307N/Aclose ZCAT;
307N/A