diff --git a/Alien/Package.pm b/Alien/Package.pm index 1eb81b7..83a472e 100644 --- a/Alien/Package.pm +++ b/Alien/Package.pm @@ -61,7 +61,8 @@ The package's maintainer. =item depends -The package's dependancies. +The package's dependancies. Only dependencies that should exist on all +target distributions can be put in here though (ie: lsb). =item group @@ -120,6 +121,11 @@ The preinst script of the package. The prerm script of the package. +=item usescripts + +Only use the above scripts fields when generating the package if this is set +to a true value. + =item unpacked_tree Points to a directory where the package has been unpacked. @@ -266,6 +272,15 @@ build methods might have on it. sub cleantree {} +=item revert + +This method should ensure that the object is in the same state it was in +before the prep method was called. + +=cut + +sub revert {} + =item build This method takes a prepped build tree, and simply builds a package from diff --git a/Alien/Package/Deb.pm b/Alien/Package/Deb.pm index e2738bb..07f3750 100644 --- a/Alien/Package/Deb.pm +++ b/Alien/Package/Deb.pm @@ -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', diff --git a/Alien/Package/Lsb.pm b/Alien/Package/Lsb.pm new file mode 100644 index 0000000..1af1e24 --- /dev/null +++ b/Alien/Package/Lsb.pm @@ -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 + +=cut + +1 diff --git a/Alien/Package/Rpm.pm b/Alien/Package/Rpm.pm index 121db1f..224f763 100644 --- a/Alien/Package/Rpm.pm +++ b/Alien/Package/Rpm.pm @@ -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; diff --git a/Alien/Package/Slp.pm b/Alien/Package/Slp.pm index d380dfc..172133f 100644 --- a/Alien/Package/Slp.pm +++ b/Alien/Package/Slp.pm @@ -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. diff --git a/Alien/Package/Tgz.pm b/Alien/Package/Tgz.pm index abcdedc..1e94369 100644 --- a/Alien/Package/Tgz.pm +++ b/Alien/Package/Tgz.pm @@ -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; } } diff --git a/alien.lsm.in b/alien.lsm.in index 54c06a9..1f36330 100644 --- a/alien.lsm.in +++ b/alien.lsm.in @@ -2,12 +2,13 @@ Begin3 Title: alien Version: @version@ Entered-date: 31MAR97 -Description: Alien converts Slackware .tgz packages, Red Hat .rpm packages - and Debian .deb packages. It can convert these formats to - either .deb or .rpm. It works only on binary packages. -Keywords: dpkg rpm tgz convert -Author: joey@kite.ml.org -Primary-site: sunsite.unc.edu /pub/Linux/utils/scripts +Description: Alien converts Slackware .tgz packages, Red Hat .rpm packages, + Debian .deb packages, and Stampede .slp packages. It can + convert from any of the formats to any other format. It works + only on binary packages. It also support LSB packages. +Keywords: debian dpkg deb red hat redhat rpm slackware tgz stampede slp convert package LSB +Author: joey@kitenet.net +Primary-site: sunsite.unc.edu /pub/Linux/utils/package 32 alien-@version@.tar.gz Copying-policy: GPL End diff --git a/alien.pl b/alien.pl index 46aebe8..f235d59 100755 --- a/alien.pl +++ b/alien.pl @@ -11,10 +11,10 @@ alien - Convert or install an alien binary package =head1 DESCRIPTION B is a program that converts between Redhat rpm, Debian deb, -Stampede slp and Slackware tgz file formats. If you want to use a package -from another linux distribution than the one you have installed on your -system, you can use alien to convert it to your preferred package format -and install it. +Stampede slp, Slackware tgz, and Solaris pkg file formats. If you want to +use a package from another linux distribution than the one you have +installed on your system, you can use alien to convert it to your preferred +package format and install it. It also supports LSB packages. =head1 WARNING @@ -39,6 +39,22 @@ alien version. For converting to and from rpm format the Red Hat Package Manager must be installed. +=item lsb + +To convert from lsb packages, the Red Hat Package Manager must be installed. +Unlike the other package formats, alien can handle the depenendencies of +lsb packages if the destination package format supports dependencies. Note +that this means that the package generated from a lsb package will depend on +a package named "lsb" -- your distribution should provide a package by that +name, if it is lsb compliant. The scripts in the lsb package will be converted +by default as well. + +To generate lsb packages, the Red Hat Package Manager must be installed, +and alien will use by preference a program named lsb-rpm, if it exists. +No guarantees are made that the generated lsb packages will be fully LSB +compliant, and it's rather unlikely they will unless you build them in the +lsbdev environment. + =item deb For converting to (but not from) deb format, the gcc, make, debmake, @@ -136,6 +152,8 @@ scripts might be designed to work on a system unlike your own, and could cause problems. It is recommended that you examine the scripts by hand and check to see what they do before using this option. +This is enabled by default when converting from lsb packages. + =item B<-k>, B<--keep-version> By default, alien adds one to the minor version number of each package it @@ -230,6 +248,7 @@ use Alien::Package::Rpm; use Alien::Package::Tgz; use Alien::Package::Slp; use Alien::Package::Pkg; +use Alien::Package::Lsb; # Returns a list of directories to search for patches. sub patchdirs { @@ -257,6 +276,7 @@ Usage: alien [options] file [...] directory. -r, --to-rpm Generate a RedHat rpm package. --to-slp Generate a Stampede slp package. + -l, --to-lsb Generate a LSB package. -t, --to-tgz Generate a Slackware tgz package. Enables the following option: --description= Specify package description. @@ -279,6 +299,7 @@ my (%destformats, $generate, $install, $single, $scripts, $patchfile, GetOptions( "to-deb|d", sub { $destformats{deb}=1 }, "to-rpm|r", sub { $destformats{rpm}=1 }, + "to-lsb|l", sub { $destformats{lsb}=1 }, "to-tgz|t", sub { $destformats{tgz}=1 }, "to-slp", sub { $destformats{slp}=1 }, "to-pkg|p", sub { $destformats{pkg}=1 }, @@ -336,7 +357,13 @@ foreach my $file (@ARGV) { # Figure out what kind of file this is. my $package; - if (Alien::Package::Rpm->checkfile($file)) { + + # Check lsb before rpm, since lsb packages are really just + # glorified rpms. + if (Alien::Package::Lsb->checkfile($file)) { + $package=Alien::Package::Lsb->new(filename => $file); + } + elsif (Alien::Package::Rpm->checkfile($file)) { $package=Alien::Package::Rpm->new(filename => $file); } elsif (Alien::Package::Deb->checkfile($file)) { @@ -356,13 +383,7 @@ foreach my $file (@ARGV) { die "Unknown type of package, $file.\n"; } - # Kill scripts from the package, unless they were enabled. - unless (defined $scripts) { - $package->postinst(''); - $package->postrm(''); - $package->preinst(''); - $package->prerm(''); - } + $package->usescripts($scripts) unless $package->usescripts; # Increment release. unless (defined $keepversion) { @@ -434,5 +455,7 @@ foreach my $file (@ARGV) { # Note I don't unlink it. I figure that might annoy # people, since it was an input file. } + + $package->revert; } } diff --git a/debian/changelog b/debian/changelog index 55c6328..ba23401 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,17 @@ +alien (8.00) unstable; urgency=low + + * 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. + + -- Joey Hess Mon, 11 Feb 2002 12:55:42 -0500 + alien (7.32) unstable; urgency=low * Support ancient (bo-era) debs with upper-case field names. Closes: #130736 diff --git a/debian/control b/debian/control index d37d1be..f772400 100644 --- a/debian/control +++ b/debian/control @@ -9,11 +9,11 @@ Package: alien Architecture: all Section: admin Depends: debhelper (>= 3), ${perl:Depends}, rpm (>= 2.4.4-2), dpkg-dev, make, cpio -Suggests: patch, bzip2 -Description: Install Red Hat, Stampede, and Slackware Packages with dpkg. - Alien allows you to convert Red Hat, Stampede and Slackware Packages into - Debian packages, which can be installed with dpkg. +Suggests: patch, bzip2, lsb-rpm +Description: Install LSB, Red Hat, Stampede, and Slackware Packages with dpkg. + Alien allows you to convert LSB, Red Hat, Stampede and Slackware Packages + into Debian packages, which can be installed with dpkg. . - It can also convert into Slackware, Red Hat, and Stampede packages. + It can also generate packages of any of the other formats. . This is a tool only suitable for binary packages.