aboutsummaryrefslogtreecommitdiffstats
path: root/archivers/rpm2cpio/files
diff options
context:
space:
mode:
authornox <nox@FreeBSD.org>2010-07-09 03:23:25 +0800
committernox <nox@FreeBSD.org>2010-07-09 03:23:25 +0800
commita343e181321150065df064d938a6ba7cd4285958 (patch)
tree4d1d38a52f9cde36942854fe580d068a5617e475 /archivers/rpm2cpio/files
parentcead0f4ebeb35e356d58caba51e68bc187c292c9 (diff)
downloadfreebsd-ports-gnome-a343e181321150065df064d938a6ba7cd4285958.tar.gz
freebsd-ports-gnome-a343e181321150065df064d938a6ba7cd4285958.tar.zst
freebsd-ports-gnome-a343e181321150065df064d938a6ba7cd4285958.zip
- 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>
Diffstat (limited to 'archivers/rpm2cpio/files')
-rw-r--r--archivers/rpm2cpio/files/rpm2cpio86
1 files changed, 41 insertions, 45 deletions
diff --git a/archivers/rpm2cpio/files/rpm2cpio b/archivers/rpm2cpio/files/rpm2cpio
index 7a415f789b5e..24a4c15795f4 100644
--- a/archivers/rpm2cpio/files/rpm2cpio
+++ b/archivers/rpm2cpio/files/rpm2cpio
@@ -1,7 +1,8 @@
-#!/usr/bin/perl
+#!/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
@@ -28,79 +29,74 @@
# 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;
-# 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;
-}
+my ($f, $rpm, $filter) = ();
if ($#ARGV == -1) {
- printhelp if -t STDIN;
- $f = "STDIN";
+ $f = "STDIN";
} elsif ($#ARGV == 0) {
- open(F, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
- $f = 'F';
+ open($f, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
} else {
- printhelp;
+ 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;
}
-printhelp if -t STDOUT;
-
# gobble the file up
undef $/;
$|=1;
-#$rpm = <$f>;
-#close ($f);
-read $f, $rpm, 96 ;
+read $f, $rpm, 96;
-($magic, $major, $minor) = unpack("NCC", $rpm);
+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 && $major != 4;
-$filter="";
-
-read $f, $rpm, 16 or die "No header\n" ;
+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";
+ ($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;
}
- if (substr($rpm, 0, 3) eq "BZh") {
- $filter="bzip2 -cd";
+ # BZh
+ if ($smagic == 0x425a and ($smagic2 & 0xff000000) == 0x68000000) {
+ $filter = "bzip2 -cd";
last;
}
- #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
+ # 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" ;
- $c = unpack("C", $rpm);
- } while($c==0);
+ } while(0 == unpack("C", $rpm));
read $f, $rpm, 15, 1 or die "No header\n" ;
}
-#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";
+open(ZCAT, "| $filter") or die "can't pipe to $filter\n";
while($rpm ne '') {
print ZCAT $rpm;
- read $f, $rpm, 10240 ; # read in blocks
+ read $f, $rpm, 10240; # read in blocks
}
close ZCAT;
-
+close $f;