components/rpm2cpio/src/rpm2cpio.pl
author pkidd <patrick.kidd@oracle.com>
Wed, 17 Feb 2016 12:41:40 -0800
branchs11u3-sru
changeset 5466 9e19ac095ef2
parent 4514 d5eea6257d67
permissions -rw-r--r--
build metadata for S11.3SRU6.2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
     1
#!/usr/bin/perl -w
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
     2
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
     3
# Copyright (C) 1997,1998,1999, Roger Espel Llima
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
     4
# Copyright (C) 2000, Sergey Babkin
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
     5
# Copyright (C) 2009, Alex Kozlov
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
     6
# 
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
     7
# Permission is hereby granted, free of charge, to any person obtaining a copy
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
     8
# of this software and any associated documentation files (the "Software"), to 
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
     9
# deal in the Software without restriction, including without limitation the 
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    10
# rights to use, copy, modify, merge, publish, distribute, sublicense, 
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    11
# and/or sell copies of the Software, and to permit persons to whom the 
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    12
# Software is furnished to do so, subject to the following conditions:
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    13
# 
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    14
# The above copyright notice and this permission notice shall be included in
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    15
# all copies or substantial portions of the Software.
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    16
# 
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    17
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    18
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    19
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    20
# SOFTWARE'S COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    21
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    22
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    23
# THE SOFTWARE
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    24
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    25
# (whew, that's done!)
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    26
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    27
# why does the world need another rpm2cpio?  because the existing one
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    28
# won't build unless you have half a ton of things that aren't really
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    29
# required for it, since it uses the same library used to extract RPM's.
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    30
# in particular, it won't build on the HPsUX box i'm on.
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    31
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    32
use strict;
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    33
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    34
my ($f, $rpm, $filter) = ();
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    35
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    36
if ($#ARGV == -1) {
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    37
	$f = "STDIN";
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    38
} elsif ($#ARGV == 0) {
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    39
	open($f, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    40
} else {
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    41
	print "rpm2cpio v1.3, perl version by orabidoo\n";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    42
	print "use: rpm2cpio [file.rpm]\n";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    43
	print "dumps the contents to stdout as a GNU cpio archive\n";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    44
	exit 0;
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    45
}
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    46
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    47
read $f, $rpm, 96;
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    48
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    49
my ($magic, $major, undef) = unpack("NCC", $rpm);
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    50
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    51
die "Not an RPM\n" if $magic != 0xedabeedb;
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    52
die "Not a version 3 or 4 RPM\n" if $major != 3 and $major != 4;
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    53
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    54
read $f, $rpm, 16 or die "No header\n";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    55
while(1) {
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    56
	($magic, undef, my $sections, my $bytes) = unpack("N4", $rpm);
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    57
	my ($smagic, $smagic2) = unpack("nN", $rpm);
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    58
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    59
	#printf(STDERR "0x%x 0x%x 0x%x 0x%x 0x%x\n",
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    60
	#	tell($f)-16, $magic, $sections, $bytes, $smagic);
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    61
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    62
	if ($smagic == 0x1f8b) {
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    63
		$filter = "gzip -cd";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    64
		last;
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    65
	}
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    66
	# BZh
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    67
	if ($smagic == 0x425a and ($smagic2 & 0xff000000) == 0x68000000) {
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    68
		$filter = "bzip2 -cd";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    69
		last;
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    70
	}
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    71
	# 0xFD, '7zXZ', 0x0
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    72
	if ($smagic == 0xfd37 and $smagic2 == 0x7a585a00) {
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    73
		$filter = "xz -cd";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    74
		last;
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    75
	}
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    76
	# assume lzma if there is no sig
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    77
	if ($magic != 0x8eade801) {
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    78
		$filter = "lzma -cd";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    79
		last;
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    80
	}
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    81
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    82
	# skip the headers
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    83
	seek $f, 16 * $sections + $bytes, 1 or die "File is too small\n";
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    84
	do {
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    85
		read $f, $rpm, 1 or die "No header\n" ;
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    86
	} while(0 == unpack("C", $rpm));
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    87
	read $f, $rpm, 15, 1 or die "No header\n" ;
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    88
}
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    89
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    90
open(ZCAT, "| $filter") or die "can't pipe to $filter\n";
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    91
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    92
while($rpm ne '') {
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    93
	print ZCAT $rpm;
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    94
	read $f, $rpm, 10240; # read in blocks
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    95
}
307
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    96
c12c36cb5349 7054536 move rpm2cpio to userland
Lukas Rovensky <Lukas.Rovensky@oracle.com>
parents:
diff changeset
    97
close ZCAT;
4514
d5eea6257d67 15477360 SUNBT6696488 rpm2cpio needs updating to cope with rpms from the modern era
Rich Burridge <rich.burridge@oracle.com>
parents: 307
diff changeset
    98
close $f;