15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era s11u2-sru
authorRich Burridge <rich.burridge@oracle.com>
Tue, 23 Jun 2015 07:09:37 -0700
branchs11u2-sru
changeset 4525 27c45fc09026
parent 4524 1d366b8c5c2d
child 4527 72aac4474845
15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
components/rpm2cpio/Makefile
components/rpm2cpio/rpm2cpio.license
components/rpm2cpio/rpm2cpio.p5m
components/rpm2cpio/src/rpm2cpio.pl
--- a/components/rpm2cpio/Makefile	Fri Jun 19 07:15:22 2015 -0600
+++ b/components/rpm2cpio/Makefile	Tue Jun 23 07:09:37 2015 -0700
@@ -20,18 +20,20 @@
 #
 
 #
-# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
 #
 
 include ../../make-rules/shared-macros.mk
 
-# The version of rpm2cpio.pl delivered in SFW does not seem to be
-# available for download anymore, so it is exceptionally delivered in
-# the Userland gate itself.
+# The version of rpm2cpio.pl delivered in Userland does not seem to be
+# available in the form of a compressed source tarball, so it is
+# exceptionally delivered in the Userland gate itself. Note that the version
+# number comes from the PORTVERSION field of the Makefile at the
+# COMPONENT_PROJECT_URL site.
 #
 COMPONENT_NAME=		rpm2cpio
-COMPONENT_VERSION=	0.5.11
-COMPONENT_PROJECT_URL=	http://www.iagora.com/~espel/rpm2cpio/
+COMPONENT_VERSION=	1.3
+COMPONENT_PROJECT_URL=	http://svnweb.freebsd.org/ports/head/archivers/rpm2cpio
 COMPONENT_SRC=		src
 COMPONENT_BUGDB=	utility/rpm
 
--- a/components/rpm2cpio/rpm2cpio.license	Fri Jun 19 07:15:22 2015 -0600
+++ b/components/rpm2cpio/rpm2cpio.license	Tue Jun 23 07:09:37 2015 -0700
@@ -1,4 +1,6 @@
 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 
--- a/components/rpm2cpio/rpm2cpio.p5m	Fri Jun 19 07:15:22 2015 -0600
+++ b/components/rpm2cpio/rpm2cpio.p5m	Tue Jun 23 07:09:37 2015 -0700
@@ -18,14 +18,14 @@
 #
 # CDDL HEADER END
 #
-# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
 #
 
 set name=pkg.fmri \
     value=pkg:/package/rpm@$(IPS_COMPONENT_VERSION),$(BUILD_VERSION)
 set name=pkg.summary value="Utilities for processing RPM archives"
 set name=com.oracle.info.description value="the rpm2cpio archive utility"
-set name=com.oracle.info.tpno value=17710
+set name=com.oracle.info.tpno value=17824
 set name=info.classification \
     value="org.opensolaris.category.2008:System/Packaging"
 set name=info.upstream-url value=$(COMPONENT_PROJECT_URL)
@@ -37,4 +37,4 @@
 file rpm2cpio.pl path=usr/bin/rpm2cpio
 legacy pkg=SUNWrpm desc="Utilities for processing RPM archives" \
     name="Utilities for processing RPM archives"
-license rpm2cpio.license license=BSD
+license rpm2cpio.license license=BSD-like
--- a/components/rpm2cpio/src/rpm2cpio.pl	Fri Jun 19 07:15:22 2015 -0600
+++ b/components/rpm2cpio/src/rpm2cpio.pl	Tue Jun 23 07:09:37 2015 -0700
@@ -1,6 +1,8 @@
-#!/usr/perl5/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 
@@ -27,64 +29,70 @@
 # 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.
 
-
-# add a path if desired
-$gzip = "gzip";
-
-sub printhelp {
-  print <<HERE;
-rpm2cpio, perl version by orabidoo <odar\@pobox.com>
-dumps the contents to stdout as a cpio archive
+use strict;
 
-use: rpm2cpio [file.rpm] > file.cpio
-
-Here's how to use cpio:
-     list of contents:   cpio -t -i < /file/name
-        extract files:   cpio -d -i < /file/name
-HERE
-
-  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;
+read $f, $rpm, 96;
 
-# gobble the file up
-undef $/;
-$|=1;
-$rpm = <$f>;
-close ($f);
-
-($magic, $major, $minor, $crap) = unpack("NCC C90", $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;
+die "Not a version 3 or 4 RPM\n" if $major != 3 and $major != 4;
 
-$rpm = substr($rpm, 96);
+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);
 
-while ($rpm ne '') {
-  $rpm =~ s/^\c@*//s;
-  ($magic, $crap, $sections, $bytes) = unpack("N4", $rpm);
-  $smagic = unpack("n", $rpm);
-  last if $smagic eq 0x1f8b;
-  die "Error: header not recognized\n" if $magic != 0x8eade801;
-  $rpm = substr($rpm, 16*(1+$sections) + $bytes);
+	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" ;
 }
 
-die "bogus RPM\n" if $rpm eq '';
+open(ZCAT, "| $filter") or die "can't pipe to $filter\n";
 
-open(ZCAT, "|gzip -cd") || die "can't pipe to gzip\n";
-print STDERR "CPIO archive found!\n";
+while($rpm ne '') {
+	print ZCAT $rpm;
+	read $f, $rpm, 10240; # read in blocks
+}
 
-print ZCAT $rpm;
 close ZCAT;
-
+close $f;