* LSB package support. It can generate LSB packages (not guarenteed

fully conformant with the LSB), and it can take LSB packages and convert
     them into other formats. Unlike all the other conversions, lsb packages's
     dependancy (on lsb) and their package scripts are preserved in the
     generated packages (when allowed by the target package format). This means
     your distribution will need to have a package named 'lsb' for the result
     to be installable. (Debian will have one soon..)
   * Suggest rpm-lsb, which is the preferred rpm to build lsb packages with.
     Use it if it's present, plain old rpm otherwise.
This commit is contained in:
joey
2002-02-11 19:19:44 +00:00
parent cf29615520
commit ea30cb70c6
10 changed files with 265 additions and 69 deletions

View File

@@ -138,7 +138,6 @@ sub scan {
Version => 'version',
Architecture => 'arch',
Maintainer => 'maintainer',
Depends => 'depends',
Section => 'group',
Description => 'summary',
);
@@ -300,11 +299,16 @@ sub prep {
print OUT "\n";
print OUT "Package: ".$this->name."\n";
print OUT "Architecture: ".$this->arch."\n";
print OUT "Depends: \${shlibs:Depends}\n";
if (defined $this->depends) {
print OUT "Depends: ".join(", ", "\${shlibs:Depends}", $this->depends)."\n";
}
else {
print OUT "Depends: \${shlibs:Depends}\n";
}
print OUT "Description: ".$this->summary."\n";
print OUT $this->description."\n";
print OUT " .\n";
print OUT " (Converted from a .".$this->origformat." package by alien.)\n";
print OUT " (Converted from a ".$this->origformat." package by alien.)\n";
close OUT;
# Copyright file.
@@ -381,16 +385,18 @@ EOF
chmod 0755,"$dir/debian/rules";
# Save any scripts.
foreach my $script (qw{postinst postrm preinst prerm}) {
my $data=$this->$script();
next unless defined $data;
next if $data =~ m/^\s*$/;
open (OUT,">$dir/debian/$script") ||
die "$dir/debian/$script: $!";
print OUT $data;
close OUT;
if ($this->usescripts) {
foreach my $script (qw{postinst postrm preinst prerm}) {
my $data=$this->$script();
next unless defined $data;
next if $data =~ m/^\s*$/;
open (OUT,">$dir/debian/$script") ||
die "$dir/debian/$script: $!";
print OUT $data;
close OUT;
}
}
my %dirtrans=( # Note: no trailing slahshes on these directory names!
# Move files to FHS-compliant locations, if possible.
'/usr/man' => '/usr/share/man',

128
Alien/Package/Lsb.pm Normal file
View File

@@ -0,0 +1,128 @@
#!/usr/bin/perl -w
=head1 NAME
Alien::Package::Lsb - an object that represents a lsb package
=cut
package Alien::Package::Lsb;
use strict;
use base qw(Alien::Package::Rpm);
=head1 DESCRIPTION
This is an object class that represents a lsb package. It is derived from
Alien::Package::Rpm.
=head1 FIELDS
=over 4
=head1 METHODS
=over 4
=item checkfile
Lsb files are rpm's with a lsb- prefix, that depend on a package called 'lsb'
and nothing else.
=cut
sub checkfile {
my $this=shift;
my $file=shift;
return unless $file =~ m/^lsb-.*\.rpm$/;
my @deps=`LANG=C rpm -qp -R $file`;
return 1 if grep { s/\s+//g; $_ eq 'lsb' } @deps;
return;
}
=item scan
Uses the parent scan method to read the file. lsb is added to the depends.
=cut
sub scan {
my $this=shift;
$this->SUPER::scan(@_);
$this->distribution("Linux Standard Base");
$this->origformat("lsb");
$this->depends("lsb");
# Converting from lsb, so the scripts should be portable and safe.
# Haha.
$this->usescripts(1);
return 1;
}
=item prep
The parent's prep method is used to generate the spec file. First though,
the package's name is munged to make it lsb compliant (sorta) and lsb is added
to its dependencies.
=cut
sub prep {
my $this=shift;
$this->_orig_name($this->name);
if ($this->name !~ /^lsb-/) {
$this->name("lsb-".$this->name);
}
$this->_orig_depends($this->depends);
$this->depends("lsb");
# Always include scripts when generating lsb package.
$this->_orig_usescripts($this->usescripts);
$this->usescripts(1);
$this->SUPER::prep(@_);
}
=item revert
Undo the changes made by prep.
=cut
sub revert {
my $this=shift;
$this->name($this->_orig_name);
$this->depends($this->_orig_depends);
$this->usescripts($this->_orig_usescripts);
$this->SUPER::revert(@_);
}
=item build
Uses the parent's build command. If a lsb-rpm is available, uses it to build
the package.
=cut
sub build {
my $this=shift;
my $buildcmd=shift || 'rpm';
foreach (split(/:/,$ENV{PATH})) {
if (-x "$_/lsb-rpm") {
$buildcmd='lsb-rpm';
last;
}
}
$this->SUPER::build($buildcmd);
}
=back
=head1 AUTHOR
Joey Hess <joey@kitenet.net>
=cut
1

View File

@@ -246,6 +246,7 @@ sub prep {
print OUT "Name: ".$this->name."\n";
print OUT "Version: ".$this->version."\n";
print OUT "Release: ".$this->release."\n";
print OUT "Requires: ".$this->depends."\n" if length $this->depends;
print OUT "Summary: ".$this->summary."\n";
print OUT "Copyright: ".$this->copyright."\n";
print OUT "Distribution: ".$this->distribution."\n";
@@ -254,30 +255,32 @@ sub prep {
print OUT "\%define _rpmdir ../\n"; # write rpm to current directory
print OUT "\%define _rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm\n";
print OUT "\n";
if ($this->preinst) {
print OUT "\%pre\n";
print OUT $this->preinst."\n";
print OUT "\n";
}
if ($this->postinst) {
print OUT "\%post\n";
print OUT $this->postinst."\n";
print OUT "\n";
}
if ($this->prerm) {
print OUT "\%preun\n";
print OUT $this->prerm."\n";
print OUT "\n";
}
if ($this->postun) {
print OUT "\%postun\n";
print OUT $this->postrm."\n";
print OUT "\n";
if ($this->usescripts) {
if ($this->preinst) {
print OUT "\%pre\n";
print OUT $this->preinst."\n";
print OUT "\n";
}
if ($this->postinst) {
print OUT "\%post\n";
print OUT $this->postinst."\n";
print OUT "\n";
}
if ($this->prerm) {
print OUT "\%preun\n";
print OUT $this->prerm."\n";
print OUT "\n";
}
if ($this->postun) {
print OUT "\%postun\n";
print OUT $this->postrm."\n";
print OUT "\n";
}
}
print OUT "\%description\n";
print OUT $this->description."\n";
print OUT "\n";
print OUT "(Converted from a .".$this->origformat." package by alien.)\n";
print OUT "(Converted from a ".$this->origformat." package by alien.)\n";
print OUT "\n";
print OUT "%files\n";
print OUT $filelist;
@@ -302,10 +305,14 @@ sub cleantree {
Build a rpm. If RPMBUILDOPT is set in the environement, the options in
it are passed to rpm on its command line.
An optional parameter, if passed, can be used to specify the program to use
to build the rpm. It defaults to rpm.
=cut
sub build {
my $this=shift;
my $buildcmd=shift || 'rpm';
my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
# Ask rpm how it's set up. We want to know what architecture it
@@ -352,7 +359,7 @@ sub build {
}
$opts.=" $ENV{RPMBUILDOPTS}" if exists $ENV{RPMBUILDOPTS};
my $command="cd $dir; rpm -bb $opts ".$this->name."-".$this->version."-".$this->release.".spec";
my $command="cd $dir; $buildcmd -bb $opts ".$this->name."-".$this->version."-".$this->release.".spec";
my $log=`$command 2>&1`;
if ($?) {
die "Package build failed. Here's the log of the command ($command):\n", $log;

View File

@@ -234,7 +234,7 @@ sub build {
'', # Set up script. TODO
$this->summary,
$this->description,
'', # Depends.
$this->depends,
'', # Provides.
$this->maintainer,
scalar localtime, # Use current date.

View File

@@ -181,18 +181,20 @@ sub prep {
my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
my $install_made=0;
foreach my $script (keys %{scripttrans()}) {
my $data=$this->$script();
my $out=$this->unpacked_tree."/install/".${scripttrans()}{$script};
next if ! defined $data || $data =~ m/^\s*$/;
if (!$install_made) {
mkdir $this->unpacked_tree."/install", 0755;
$install_made=1;
if ($this->usescripts) {
foreach my $script (keys %{scripttrans()}) {
my $data=$this->$script();
my $out=$this->unpacked_tree."/install/".${scripttrans()}{$script};
next if ! defined $data || $data =~ m/^\s*$/;
if (!$install_made) {
mkdir $this->unpacked_tree."/install", 0755;
$install_made=1;
}
open (OUT, ">$out") || die "$out: $!";
print OUT $data;
close OUT;
chmod 0755, $out;
}
open (OUT, ">$out") || die "$out: $!";
print OUT $data;
close OUT;
chmod 0755, $out;
}
}