2000-04-21 09:56:06 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
|
|
Alien::Package::Slp - an object that represents a slp package
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
2000-04-21 23:30:45 +00:00
|
|
|
package Alien::Package::Slp;
|
2000-04-21 09:56:06 +00:00
|
|
|
use strict;
|
|
|
|
|
use Alien::Package; # perlbug
|
|
|
|
|
use base qw(Alien::Package);
|
|
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
|
|
This is an object class that represents a slp package. It is derived from
|
|
|
|
|
Alien::Package.
|
|
|
|
|
|
|
|
|
|
=head1 CLASS DATA
|
|
|
|
|
|
|
|
|
|
The following data is global to the class, and is used to describe the slp
|
|
|
|
|
package format, which this class processes directly.
|
|
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
|
|
=item footer_size
|
|
|
|
|
|
|
|
|
|
Complete sizeof(slpformat) from slp.h in the stampede package manager
|
|
|
|
|
source.
|
|
|
|
|
|
|
|
|
|
=item footer_packstring
|
|
|
|
|
|
|
|
|
|
This is the pack format string for the footer. (A=space terminated
|
|
|
|
|
character, I=unsigned integer.)
|
|
|
|
|
|
|
|
|
|
=item footer_version
|
|
|
|
|
|
|
|
|
|
What package format are we up to now? (Lowest one this is still
|
|
|
|
|
compatable with.)
|
|
|
|
|
|
|
|
|
|
=item archtrans
|
|
|
|
|
|
|
|
|
|
This is a translation table between architectures and the number
|
|
|
|
|
that represents them in a slp package.
|
|
|
|
|
|
2000-04-21 10:50:54 +00:00
|
|
|
=item fieldlist
|
|
|
|
|
|
|
|
|
|
This is a list of all the fields in the order they appear in the footer.
|
|
|
|
|
|
2000-04-21 09:56:06 +00:00
|
|
|
=cut
|
|
|
|
|
|
2000-04-22 01:16:10 +00:00
|
|
|
use constant footer_size => 3784;
|
|
|
|
|
use constant footer_packstring => "A756IIIIA128A128A80A1536A512A512A30A30IA20A20III";
|
|
|
|
|
use constant footer_version => 5;
|
|
|
|
|
use constant archtrans => {
|
2000-04-21 09:56:06 +00:00
|
|
|
0 => 'all',
|
|
|
|
|
1 => 'i386',
|
|
|
|
|
2 => 'sparc',
|
|
|
|
|
3 => 'alpha',
|
|
|
|
|
4 => 'powerpc',
|
|
|
|
|
5 => 'm68k',
|
2000-04-22 01:16:10 +00:00
|
|
|
};
|
|
|
|
|
use constant copyrighttrans => {
|
2000-04-21 09:56:06 +00:00
|
|
|
0 => 'GPL',
|
|
|
|
|
1 => 'BSD',
|
|
|
|
|
2 => 'LGPL',
|
|
|
|
|
3 => 'unknown',
|
|
|
|
|
254 => 'unknown',
|
2000-04-22 01:16:10 +00:00
|
|
|
};
|
|
|
|
|
use constant fieldlist => [qw{conffiles priority compresstype release copyright
|
|
|
|
|
conflicts setupscript summary description depends
|
|
|
|
|
provides maintainer date compiler version name
|
|
|
|
|
arch group slpkgversion}];
|
2000-04-21 09:56:06 +00:00
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
|
|
=head1 FIELDS
|
|
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
2000-04-21 10:50:54 +00:00
|
|
|
=item compresstype
|
|
|
|
|
|
|
|
|
|
Holds the compression type used in the slp file.
|
|
|
|
|
|
|
|
|
|
=item slpkgversion
|
|
|
|
|
|
|
|
|
|
Holds the slp package format version of the slp file.
|
|
|
|
|
|
|
|
|
|
=item
|
|
|
|
|
|
2000-04-21 09:56:06 +00:00
|
|
|
=head1 METHODS
|
|
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
2000-04-21 22:18:49 +00:00
|
|
|
=item checkfile
|
|
|
|
|
|
|
|
|
|
Detect slp files by their extention.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub checkfile {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
my $file=shift;
|
|
|
|
|
|
|
|
|
|
return $file =~ m/.*\.slp$/;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-21 09:56:06 +00:00
|
|
|
=item install
|
|
|
|
|
|
|
|
|
|
Install a slp. Pass in the filename of the slp to install.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub install {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
my $slp=shift;
|
|
|
|
|
|
2000-09-11 23:27:32 +00:00
|
|
|
system("slpi $slp") == 0
|
|
|
|
|
or die "Unable to install";
|
2000-04-21 09:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
2000-04-21 10:50:54 +00:00
|
|
|
=item getfooter
|
|
|
|
|
|
|
|
|
|
Pulls the footer out of the slp file and returns it.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub getfooter {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
my $file=$this->filename;
|
|
|
|
|
|
|
|
|
|
open (SLP,"<$file") || die "$file: $!";
|
|
|
|
|
# position at beginning of footer (2 = seek from EOF)
|
|
|
|
|
seek SLP,(- footer_size),2;
|
|
|
|
|
read SLP,$_,footer_size;
|
|
|
|
|
close SLP;
|
|
|
|
|
return $_;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-21 09:56:06 +00:00
|
|
|
=item scan
|
|
|
|
|
|
|
|
|
|
Implement the scan method to read a slp file.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub scan {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
$this->SUPER::scan(@_);
|
|
|
|
|
my $file=$this->filename;
|
|
|
|
|
|
2000-04-21 10:50:54 +00:00
|
|
|
# Decode the footer.
|
2000-04-21 21:06:44 +00:00
|
|
|
my @values=unpack(footer_packstring(),$this->getfooter);
|
2000-04-21 10:50:54 +00:00
|
|
|
# Populate fields.
|
2000-04-21 21:06:44 +00:00
|
|
|
foreach my $field (@{fieldlist()}) {
|
2000-04-21 10:50:54 +00:00
|
|
|
$_=shift @values;
|
|
|
|
|
$this->$field($_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# A simple sanity check.
|
2000-04-21 21:06:44 +00:00
|
|
|
if (! defined $this->slpkgversion || $this->slpkgversion < footer_version()) {
|
2000-04-21 10:50:54 +00:00
|
|
|
die "unsupported stampede package version";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Read in the file list.
|
|
|
|
|
my @filelist;
|
|
|
|
|
# FIXME: support gzip files too!
|
|
|
|
|
foreach (`bzip2 -d < $file | tar -tf -`) {
|
2000-04-22 01:47:39 +00:00
|
|
|
chomp;
|
2000-04-21 10:50:54 +00:00
|
|
|
s:^\./:/:;
|
|
|
|
|
$_="/$_" unless m:^/:;
|
2000-04-21 21:06:44 +00:00
|
|
|
push @filelist, $_;
|
2000-04-21 10:50:54 +00:00
|
|
|
}
|
2000-04-22 01:47:39 +00:00
|
|
|
$this->filelist(\@filelist);
|
2000-04-21 10:50:54 +00:00
|
|
|
|
|
|
|
|
# TODO: read in postinst script.
|
|
|
|
|
|
|
|
|
|
$this->distribution('Stampede');
|
|
|
|
|
$this->origformat('slp');
|
2000-04-22 01:47:39 +00:00
|
|
|
$this->changelogtext('');
|
|
|
|
|
$this->binary_info(`ls -l $file`);
|
2000-04-21 10:50:54 +00:00
|
|
|
|
2000-04-21 09:56:06 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
=item unpack
|
|
|
|
|
|
2000-04-21 10:50:54 +00:00
|
|
|
Unpack a slp file. They can be compressed in various ways, depending on
|
|
|
|
|
what is in the compresstype field.
|
2000-04-21 09:56:06 +00:00
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub unpack {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
$this->SUPER::unpack(@_);
|
|
|
|
|
my $file=$this->filename;
|
2000-04-21 10:50:54 +00:00
|
|
|
my $compresstype=$this->compresstype;
|
|
|
|
|
|
|
|
|
|
if ($compresstype == 0) {
|
2000-04-22 01:47:39 +00:00
|
|
|
system("bzip2 -d < $file | (cd ".$this->unpacked_tree."; tar xpf -)")
|
2000-04-21 10:50:54 +00:00
|
|
|
}
|
|
|
|
|
elsif ($compresstype == 1) {
|
2001-05-09 15:13:34 +00:00
|
|
|
system("gzip -dc $file | (cd ".$this->unpacked_tree."; tar xpf -)")
|
2000-04-21 10:50:54 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
die "package uses an unknown compression type, $compresstype (please file a bug report)";
|
|
|
|
|
}
|
2000-04-21 09:56:06 +00:00
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
=item build
|
|
|
|
|
|
|
|
|
|
Build a slp.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub build {
|
|
|
|
|
my $this=shift;
|
2000-04-21 21:06:44 +00:00
|
|
|
my $slp=$this->name."-".$this->version.".slp";
|
|
|
|
|
|
|
|
|
|
# Now generate the footer.
|
|
|
|
|
# We cannot use the actual $slp::footer_packstring, becuase it uses
|
|
|
|
|
# space terminated strings (A) instead of null terminated strings
|
|
|
|
|
# (a). That is good for decoding, but not for encoding.
|
|
|
|
|
my $fmt=footer_packstring();
|
|
|
|
|
$fmt=~tr/A/a/;
|
2000-04-22 01:16:10 +00:00
|
|
|
|
2000-04-21 21:06:44 +00:00
|
|
|
my $footer=pack($fmt,
|
|
|
|
|
$this->conffiles,
|
|
|
|
|
2, # Use priority optional for alien packages.
|
|
|
|
|
0, # Always use bzip2 as the compression type.
|
|
|
|
|
$this->release,
|
|
|
|
|
254, # Don't try to guess copyright, just use unknown.
|
|
|
|
|
'', # Conflicts.
|
|
|
|
|
'', # Set up script. TODO
|
2000-04-22 01:16:10 +00:00
|
|
|
$this->summary,
|
2000-04-21 21:06:44 +00:00
|
|
|
$this->description,
|
|
|
|
|
'', # Depends.
|
|
|
|
|
'', # Provides.
|
2000-04-22 01:16:10 +00:00
|
|
|
$this->maintainer,
|
2000-04-21 21:06:44 +00:00
|
|
|
scalar localtime, # Use current date.
|
|
|
|
|
252, # Unknown compiler.
|
|
|
|
|
$this->version,
|
|
|
|
|
$this->name,
|
|
|
|
|
$this->arch,
|
|
|
|
|
252, # Unknown group.
|
|
|
|
|
footer_version(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# Generate .tar.bz2 file.
|
|
|
|
|
# Note that it's important I use "./*" instead of just "." or
|
|
|
|
|
# something like that, becuase it results in a tar file where all
|
|
|
|
|
# the files in it start with "./", which is consitent with how
|
|
|
|
|
# normal stampede files look.
|
2000-09-11 23:27:32 +00:00
|
|
|
system("(cd ".$this->unpacked_tree."; tar cf - ./*) | bzip2 - > $slp") == 0
|
|
|
|
|
or die "package build failed: $!";
|
2000-04-21 21:06:44 +00:00
|
|
|
|
|
|
|
|
# Now append the footer.
|
|
|
|
|
open (OUT,">>$slp") || die "$slp: $!";
|
|
|
|
|
print OUT $footer;
|
|
|
|
|
close OUT;
|
|
|
|
|
|
|
|
|
|
return $slp;
|
2000-04-21 09:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
2000-04-21 10:50:54 +00:00
|
|
|
=item conffiles
|
|
|
|
|
|
|
|
|
|
Set/get conffiles.
|
|
|
|
|
|
|
|
|
|
When the conffiles are set, the format used by slp (a colon-delimited list)
|
2000-04-21 21:06:44 +00:00
|
|
|
is turned into the real list that is used internally. The list is changed
|
|
|
|
|
back into slp's internal format when it is retreived.
|
2000-04-21 10:50:54 +00:00
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub conffiles {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
|
|
|
|
|
# set
|
2000-04-21 21:06:44 +00:00
|
|
|
$this->{conffiles}=[split /:/, shift] if @_;
|
2000-04-21 10:50:54 +00:00
|
|
|
|
|
|
|
|
# get
|
|
|
|
|
return unless defined wantarray; # optimization
|
2000-04-21 21:06:44 +00:00
|
|
|
return join(':',@{$this->{conffiles}});
|
2000-04-21 10:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
=item copyright
|
|
|
|
|
|
|
|
|
|
Set/get copyright.
|
|
|
|
|
|
|
|
|
|
When the copyright is set, the number used by slp is changed into a textual
|
|
|
|
|
description. This is changed back into a number when the value is
|
|
|
|
|
retreived.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub copyright {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
|
|
|
|
|
# set
|
2000-04-21 21:06:44 +00:00
|
|
|
$this->{copyright}=(${copyrighttrans()}{shift} || 'unknown') if @_;
|
2000-04-21 10:50:54 +00:00
|
|
|
|
|
|
|
|
# get
|
|
|
|
|
return unless defined wantarray; # optimization
|
2000-04-21 21:06:44 +00:00
|
|
|
my %transcopyright=reverse %{copyrighttrans()};
|
|
|
|
|
return $transcopyright{$this->{copyright}}
|
|
|
|
|
if (exists $transcopyright{$this->{copyright}});
|
|
|
|
|
return 254; # unknown
|
2000-04-21 10:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
=item arch
|
|
|
|
|
|
|
|
|
|
Set/get arch.
|
|
|
|
|
|
|
|
|
|
When the arch is set, the number used by slp is changed into a textual
|
|
|
|
|
description. This is changed back into a number when the value is
|
|
|
|
|
retreived.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub arch {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
|
|
|
|
|
# set
|
|
|
|
|
if (@_) {
|
2000-04-22 01:16:10 +00:00
|
|
|
my $arch=shift;
|
|
|
|
|
$this->{arch}=${archtrans()}{$arch};
|
|
|
|
|
die "unknown architecture $arch" unless defined $this->{arch};
|
2000-04-21 10:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# get
|
|
|
|
|
return unless defined wantarray; # optimization
|
2000-04-21 21:06:44 +00:00
|
|
|
my %transarch=reverse %{archtrans()};
|
|
|
|
|
return $transarch{$this->{arch}}
|
|
|
|
|
if (exists $transarch{$this->{arch}});
|
|
|
|
|
die "Stampede does not support architecture ".$this->{arch}." packages";
|
2000-04-21 10:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2000-04-21 21:06:44 +00:00
|
|
|
=item release
|
|
|
|
|
|
|
|
|
|
Set/get release version.
|
|
|
|
|
|
|
|
|
|
When the release version is retreived, it is converted to an unsigned
|
|
|
|
|
integer, as is required by the slp package format.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub release {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
|
|
|
|
|
# set
|
2000-04-22 01:16:10 +00:00
|
|
|
$this->{release}=shift if @_;
|
2000-04-21 21:06:44 +00:00
|
|
|
|
|
|
|
|
# get
|
|
|
|
|
return unless defined wantarray; # optimization
|
|
|
|
|
return int($this->{release});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-21 09:56:06 +00:00
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
|
|
Joey Hess <joey@kitenet.net>
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
1
|