1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#!/usr/bin/perl
#
# Package for converting from a .slp (Stampede) file.
# Pull in details on the binary footer.
use Slp;
package From::slp;
use strict;
# Pass it a chunk of footer, it will attempt a decode and spit back the result
# in a hash, %fields.
sub DecodeFooter { my $footer=shift;
my %fields;
($fields{CONFFILES},
$fields{PRIORITY},
$fields{COMPRESSTYPE},
$fields{RELEASE},
$fields{COPYRIGHT},
$fields{CONFLICTS},
$fields{SETUPSCRIPT},
$fields{SUMMARY},
$fields{DESCRIPTION},
$fields{DEPENDS},
$fields{PROVIDES},
$fields{AUTHOR},
$fields{DATE},
$fields{COMPILER},
$fields{VERSION},
$fields{NAME},
$fields{ARCH},
$fields{GROUP},
$fields{SLPKGVERSION},
)=unpack($slp::footer_packstring,$footer);
# A simple sanity check.
if (! $fields{SLPKGVERSION} || $fields{SLPKGVERSION} < $slp::footer_version) {
Alien::Error("This is not a V$slp::footer_version or greater Stampede package");
}
return %fields;
}
# Pass it a filename of a .slp file, it will pull out a footer and return it
# in a scalar.
sub GetFooter { my ($filename)=@_;
open (SLP,"<$filename") || Alien::Error("unable to read $filename: $!");
seek SLP,(-1 * $slp::footer_size),2; # position at beginning of footer (2 = seek from EOF)
read SLP,$_,$slp::footer_size;
close SLP;
return $_;
}
# Query a slp file for fields, and return a hash of the fields found.
# Pass the filename of the slp file to query.
sub GetFields { my ($self,$file)=@_;
my %fields=DecodeFooter(GetFooter($file));
# Massage the fields into appropriate formats.
if ($fields{CONFFILES}) {
$fields{CONFFILES}=~s/:/\n/g;
$fields{CONFFILES}.="\n";
}
if ($$slp::copyrighttrans{$fields{COPYRIGHT}}) {
$fields{COPYRIGHT}=$$slp::copyrighttrans{$fields{COPYRIGHT}};
}
else {
Alien::Warning("I don't know what copyright type \"$fields{COPYRIGHT}\" is.");
$fields{COPYRIGHT}="unknown";
}
if ($$slp::archtrans{$fields{ARCH}}) {
$fields{ARCH}=$$slp::archtrans{$fields{ARCH}};
}
else {
Alien::Error("An unknown architecture, \"$fields{ARCH}\" was specified.");
}
$fields{RELEASE}++ unless $main::keep_version;
$fields{DISTRIBUTION}="Stampede";
# Read in the list of all files.
$fields{FILELIST}=undef;
my $fn;
foreach $fn (`bzip2 -d < $file | tar -tf -`) {
# They may have a leading "." we don't want.
$fn=~s:^\./:/:;
# Ensure there is always a leading '/'.
if ($fn=~m:^/: eq undef) {
$fn="/$fn";
}
$fields{FILELIST}.="$fn\n";
}
# TODO: read in postinst script.
return %fields;
}
# Unpack a slp file.
# They can be compressed in various ways, depending on what is in
# $fields{COMPRESSTYPE}.
sub Unpack { my ($self,$file,%fields)=@_;
if ($fields{COMPRESSTYPE} eq 0) {
Alien::SafeSystem ("(cd ..;cat $file) | bzip2 -d | tar xpf -","Error unpacking $file\n");
}
elsif ($fields{COMPRESSTYPE} eq 1) {
# .gz
Alien::SafeSystem ("(cd ..;cat $file) | tar zxpf -","Error unpacking $file\n");
}
else {
# Seems .zip might be a possibility, but I have no way of testing it.
Alien::Error("This packages uses an unknown compression type, $fields{COMPRESSTYPE}.");
}
}
1
|