head	1.4;
access;
symbols
	RELEASE_8_3_0:1.4
	RELEASE_9_0_0:1.4
	RELEASE_7_4_0:1.4
	RELEASE_8_2_0:1.4
	RELEASE_6_EOL:1.4
	RELEASE_8_1_0:1.2
	RELEASE_7_3_0:1.2
	RELEASE_8_0_0:1.2
	RELEASE_7_2_0:1.2
	RELEASE_7_1_0:1.2
	RELEASE_6_4_0:1.2
	RELEASE_5_EOL:1.2
	RELEASE_7_0_0:1.2
	RELEASE_6_3_0:1.2
	PRE_XORG_7:1.2
	RELEASE_4_EOL:1.2
	RELEASE_6_2_0:1.2
	RELEASE_6_1_0:1.2
	RELEASE_5_5_0:1.2
	RELEASE_6_0_0:1.2
	RELEASE_5_4_0:1.2
	RELEASE_4_11_0:1.2
	RELEASE_5_3_0:1.2
	RELEASE_4_10_0:1.2;
locks; strict;
comment	@# @;


1.4
date	2010.08.22.15.29.21;	author nox;	state Exp;
branches;
next	1.3;

1.3
date	2010.07.08.19.23.25;	author nox;	state Exp;
branches;
next	1.2;

1.2
date	2003.12.14.12.27.31;	author netchild;	state Exp;
branches;
next	1.1;

1.1
date	2003.12.12.13.32.47;	author netchild;	state Exp;
branches;
next	;


desc
@@


1.4
log
@Some minor updates:

- remove $/, $| it's artifacts from $rpm = <$f>; time.
  [this might help in low RAM situations]
- change && to and
- whitespace cosmetic.

Submitted by:	Alex Kozlov <spam@@rm-rf.kiev.ua> (via private email)
@
text
@#!/usr/bin/perl -w

# Copyright (C) 1997,1998,1999, Roger Espel Llima
# Copyright (C) 2000, Sergey Babkin
# Copyright (C) 2009, Alex Kozlov
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and any associated documentation files (the "Software"), to 
# deal in the Software without restriction, including without limitation the 
# rights to use, copy, modify, merge, publish, distribute, sublicense, 
# and/or sell copies of the Software, and to permit persons to whom the 
# Software is furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# SOFTWARE'S COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE

# (whew, that's done!)

# why does the world need another rpm2cpio?  because the existing one
# won't build unless you have half a ton of things that aren't really
# required for it, since it uses the same library used to extract RPM's.
# in particular, it won't build on the HPsUX box i'm on.

use strict;

my ($f, $rpm, $filter) = ();

if ($#ARGV == -1) {
	$f = "STDIN";
} elsif ($#ARGV == 0) {
	open($f, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
} else {
	print "rpm2cpio v1.3, perl version by orabidoo\n";
	print "use: rpm2cpio [file.rpm]\n";
	print "dumps the contents to stdout as a GNU cpio archive\n";
	exit 0;
}

read $f, $rpm, 96;

my ($magic, $major, undef) = unpack("NCC", $rpm);

die "Not an RPM\n" if $magic != 0xedabeedb;
die "Not a version 3 or 4 RPM\n" if $major != 3 and $major != 4;

read $f, $rpm, 16 or die "No header\n";
while(1) {
	($magic, undef, my $sections, my $bytes) = unpack("N4", $rpm);
	my ($smagic, $smagic2) = unpack("nN", $rpm);

	#printf(STDERR "0x%x 0x%x 0x%x 0x%x 0x%x\n",
	#	tell($f)-16, $magic, $sections, $bytes, $smagic);

	if ($smagic == 0x1f8b) {
		$filter = "gzip -cd";
		last;
	}
	# BZh
	if ($smagic == 0x425a and ($smagic2 & 0xff000000) == 0x68000000) {
		$filter = "bzip2 -cd";
		last;
	}
	# 0xFD, '7zXZ', 0x0
	if ($smagic == 0xfd37 and $smagic2 == 0x7a585a00) {
		$filter = "xz -cd";
		last;
	}
	# assume lzma if there is no sig
	if ($magic != 0x8eade801) {
		$filter = "lzma -cd";
		last;
	}

	# skip the headers
	seek $f, 16 * $sections + $bytes, 1 or die "File is too small\n";
	do {
		read $f, $rpm, 1 or die "No header\n" ;
	} while(0 == unpack("C", $rpm));
	read $f, $rpm, 15, 1 or die "No header\n" ;
}

open(ZCAT, "| $filter") or die "can't pipe to $filter\n";

while($rpm ne '') {
	print ZCAT $rpm;
	read $f, $rpm, 10240; # read in blocks
}

close ZCAT;
close $f;
@


1.3
log
@- Update and add support for newer rpms that use xz or lzma.  [1]
- Added RUN_DEPENDS on archivers/xz on systems where its not in base.

PR:		ports/148446 [1]
Submitted by:	Alex Kozlov <spam@@rm-rf.kiev.ua>
@
text
@a46 4
# gobble the file up
undef $/;
$|=1;

d52 1
a52 1
die "Not a version 3 or 4 RPM\n" if $major != 3 && $major != 4;
d72 1
a72 1
	if ($smagic == 0xfd37 and $smagic2== 0x7a585a00) {
d83 1
a83 1
	seek $f, 16*$sections+$bytes, 1 or die "File is too small\n";
@


1.2
log
@Add RPM v4 support.

Submitted by:	Marius Strobl <marius@@alchemy.franken.de>
Approved by:	maintainer
@
text
@d1 1
a1 1
#!/usr/bin/perl
d5 1
d32 1
d34 1
a34 9
# add a path if desired
$gzip = "gzip";

sub printhelp {
  print "rpm2cpio, perl version by orabidoo <odar\@@pobox.com>\n";
  print "use: rpm2cpio [file.rpm]\n";
  print "dumps the contents to stdout as a GNU cpio archive\n";
  exit 0;
}
d37 1
a37 2
  printhelp if -t STDIN;
  $f = "STDIN";
d39 1
a39 2
  open(F, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
  $f = 'F';
d41 4
a44 1
  printhelp;
a46 2
printhelp if -t STDOUT;

a49 2
#$rpm = <$f>;
#close ($f);
d51 1
a51 1
read $f, $rpm, 96 ;
d53 1
a53 1
($magic, $major, $minor) = unpack("NCC", $rpm);
d58 4
a61 1
$filter="";
d63 15
a77 7
read $f, $rpm, 16 or die "No header\n" ;
while(1) {
	($magic, $crap, $sections, $bytes) = unpack("N4", $rpm);
	$smagic = unpack("n", $rpm);
	$format="unknown";
	if ($smagic eq 0x1f8b) {
		$filter="gzip -cd";
d80 3
a82 2
	if (substr($rpm, 0, 3) eq "BZh") {
		$filter="bzip2 -cd";
d85 3
a87 3
	#printf(STDERR "0x%x 0x%x 0x%x 0x%x\n", $magic, $sections, $bytes, $smagic);
	die "Error: header not recognized\n" if $magic != 0x8eade801;
	seek $f, 16*$sections+$bytes, 1 or die "FIle is too small\n"; # skip the headers
d90 1
a90 2
		$c = unpack("C", $rpm);
	} while($c==0);
d94 1
a94 7
#read $f, $rpm, 20 or die "No gzip header\n"; # the gzip header
#$smagic = unpack("n", $rpm);
#printf(STDERR "0x%x\n", $smagic);
die "Error: bogus RPM\n" if $filter eq "";

open(ZCAT, "| $filter") || die "can't pipe to $filter\n";
#print STDERR "CPIO archive found!\n";
d98 1
a98 1
	read $f, $rpm, 10240 ; # read in blocks
d102 1
a102 1

@


1.1
log
@ - add missing file from the last update
 - distinfo isn't needed anymore, the used file has no home and is
   included

PR:		59980 (part of)
Submitted by:	maintainer
@
text
@d65 1
a65 1
die "Not a version 3 RPM\n" if $major != 3;
@

