diff --git a/archivers/rpm2cpio/Makefile b/archivers/rpm2cpio/Makefile index d609369f58a5..00b1c6e87085 100644 --- a/archivers/rpm2cpio/Makefile +++ b/archivers/rpm2cpio/Makefile @@ -6,8 +6,7 @@ # PORTNAME= rpm2cpio -PORTVERSION= 1.2 -PORTREVISION= 2 +PORTVERSION= 1.3 CATEGORIES= archivers MASTER_SITES= # none DISTFILES= # none @@ -19,16 +18,24 @@ NO_WRKSUBDIR= yes USE_PERL5= yes NO_BUILD= yes +REINPLACE_ARGS= + PLIST_FILES= bin/rpm2cpio.pl +.include + +.if ( (${OSVERSION} >= 900000 && ${OSVERSION} < 900012) || ${OSVERSION} < 800505 ) +RUN_DEPENDS+= ${LOCALBASE}/bin/xz:${PORTSDIR}/archivers/xz +.endif + do-fetch: @${DO_NADA} do-extract: @${MKDIR} ${WRKSRC} - ${PERL5} -p -e "if (1 .. 1) {s-^#!/usr/bin/perl-#!${PERL}-;}" ${FILESDIR}/${PORTNAME} >${WRKDIR}/${PORTNAME} + @${REINPLACE_CMD} -e 's|^#!/usr/bin/perl|#!${PERL}|' ${FILESDIR}/${PORTNAME} >${WRKDIR}/${PORTNAME} do-install: ${INSTALL_SCRIPT} ${WRKDIR}/${PORTNAME} ${PREFIX}/bin/${PORTNAME}.pl -.include +.include 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 \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;