2000-04-21 02:23:53 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
|
|
Alien::Package::Rpm - an object that represents a rpm package
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
package Alien::Package::Rpm;
|
|
|
|
|
use strict;
|
|
|
|
|
use base qw(Alien::Package);
|
|
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
|
|
This is an object class that represents a rpm package. It is derived from
|
|
|
|
|
Alien::Package.
|
|
|
|
|
|
|
|
|
|
=head1 FIELDS
|
|
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
|
|
=item prefixes
|
|
|
|
|
|
|
|
|
|
Relocatable rpm packages have a prefixes field.
|
|
|
|
|
|
|
|
|
|
=head1 METHODS
|
|
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
2000-04-21 22:18:49 +00:00
|
|
|
=item checkfile
|
|
|
|
|
|
|
|
|
|
Detect rpm files by their extention.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub checkfile {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
my $file=shift;
|
|
|
|
|
|
|
|
|
|
return $file =~ m/.*\.rpm$/;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-21 05:08:50 +00:00
|
|
|
=item install
|
|
|
|
|
|
|
|
|
|
Install a rpm. If RPMINSTALLOPT is set in the environement, the options in
|
|
|
|
|
it are passed to rpm on its command line.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub install {
|
|
|
|
|
my $this=shift;
|
2000-04-21 06:40:08 +00:00
|
|
|
my $rpm=shift;
|
2000-04-21 05:08:50 +00:00
|
|
|
|
2003-02-15 20:46:09 +00:00
|
|
|
(system("rpm -ivh ".(exists $ENV{RPMINSTALLOPT} ? $ENV{RPMINSTALLOPT} : '').$rpm) == 0)
|
2000-09-11 23:27:32 +00:00
|
|
|
or die "Unable to install";
|
2000-04-21 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
2000-04-21 07:33:12 +00:00
|
|
|
=item scan
|
2000-04-21 02:23:53 +00:00
|
|
|
|
2000-04-21 07:33:12 +00:00
|
|
|
Implement the scan method to read a rpm file.
|
2000-04-21 02:23:53 +00:00
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
2000-04-21 07:33:12 +00:00
|
|
|
sub scan {
|
2000-04-21 02:23:53 +00:00
|
|
|
my $this=shift;
|
2000-04-21 09:56:06 +00:00
|
|
|
$this->SUPER::scan(@_);
|
2000-04-21 02:23:53 +00:00
|
|
|
my $file=$this->filename;
|
|
|
|
|
|
|
|
|
|
my %fieldtrans=(
|
|
|
|
|
PREIN => 'preinst',
|
|
|
|
|
POSTIN => 'postinst',
|
|
|
|
|
PREUN => 'prerm',
|
|
|
|
|
POSTUN => 'postrm',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# These fields need no translation except case.
|
|
|
|
|
foreach (qw{name version release arch changelogtext summary
|
|
|
|
|
description copyright prefixes}) {
|
|
|
|
|
$fieldtrans{uc $_}=$_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Use --queryformat to pull out all the fields we need.
|
|
|
|
|
foreach my $field (keys(%fieldtrans)) {
|
2000-05-22 23:23:32 +00:00
|
|
|
$_=`LANG=C rpm -qp --queryformat \%{$field} $file`;
|
2000-04-21 02:23:53 +00:00
|
|
|
$field=$fieldtrans{$field};
|
2000-05-09 21:42:41 +00:00
|
|
|
$_='' if $_ eq '(none)';
|
|
|
|
|
$this->$field($_);
|
2000-04-21 02:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Get the conffiles list.
|
2002-03-24 02:35:58 +00:00
|
|
|
$this->conffiles([map { chomp; $_ } `LANG=C rpm -qcp $file`]);
|
2002-03-28 19:37:18 +00:00
|
|
|
if (defined $this->conffiles->[0] &&
|
|
|
|
|
$this->conffiles->[0] eq '(contains no files)') {
|
2002-03-24 02:35:58 +00:00
|
|
|
$this->conffiles([]);
|
|
|
|
|
}
|
2000-04-21 02:23:53 +00:00
|
|
|
|
2000-04-21 06:16:26 +00:00
|
|
|
$this->binary_info(scalar `rpm -qpi $file`);
|
2000-04-21 02:23:53 +00:00
|
|
|
|
|
|
|
|
# Get the filelist.
|
2002-03-24 02:35:58 +00:00
|
|
|
$this->filelist([map { chomp; $_ } `LANG=C rpm -qpl $file`]);
|
2002-04-01 04:06:14 +00:00
|
|
|
if (defined $this->filelist->[0] &&
|
2002-03-28 19:37:18 +00:00
|
|
|
$this->filelist->[0] eq '(contains no files)') {
|
2002-03-24 02:35:58 +00:00
|
|
|
$this->filelist([]);
|
|
|
|
|
}
|
2000-04-21 02:23:53 +00:00
|
|
|
|
|
|
|
|
# Sanity check and sanitize fields.
|
|
|
|
|
unless (defined $this->summary) {
|
|
|
|
|
# Older rpms will have no summary, but will have a
|
|
|
|
|
# description. We'll take the 1st line out of the
|
|
|
|
|
# description, and use it for the summary.
|
|
|
|
|
$this->summary($this->description."\n")=~m/(.*?)\n/m;
|
|
|
|
|
|
|
|
|
|
# Fallback.
|
|
|
|
|
if (! $this->summary) {
|
|
|
|
|
$this->summary('Converted RPM package');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unless (defined $this->copyright) {
|
|
|
|
|
$this->copyright('unknown');
|
|
|
|
|
}
|
|
|
|
|
unless (defined $this->description) {
|
|
|
|
|
$this->description($this->summary);
|
|
|
|
|
}
|
|
|
|
|
if (! defined $this->release || ! defined $this->version ||
|
|
|
|
|
! defined $this->name) {
|
|
|
|
|
die "Error querying rpm file";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->distribution("Red Hat");
|
2000-04-21 06:16:26 +00:00
|
|
|
$this->origformat("rpm");
|
2000-04-21 02:23:53 +00:00
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-21 05:08:50 +00:00
|
|
|
=item unpack
|
|
|
|
|
|
|
|
|
|
Implement the unpack method to unpack a rpm file. This is a little nasty
|
|
|
|
|
because it has to handle relocatable rpms and has to do a bit of
|
|
|
|
|
permissions fixing as well.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub unpack {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
$this->SUPER::unpack(@_);
|
|
|
|
|
my $workdir=$this->unpacked_tree;
|
2000-05-09 21:42:41 +00:00
|
|
|
|
2003-02-15 20:46:09 +00:00
|
|
|
(system("rpm2cpio ".$this->filename." | (cd $workdir; cpio --extract --make-directories --no-absolute-filenames --preserve-modification-time) 2>/dev/null") == 0)
|
2000-09-11 23:27:32 +00:00
|
|
|
or die "Unpacking of `".$this->filename."' failed";
|
2000-04-21 05:08:50 +00:00
|
|
|
|
|
|
|
|
# If the package is relocatable. We'd like to move it to be under
|
|
|
|
|
# the $this->prefixes directory. However, it's possible that that
|
|
|
|
|
# directory is in the package - it seems some rpm's are marked as
|
|
|
|
|
# relocatable and unpack already in the directory they can relocate
|
|
|
|
|
# to, while some are marked relocatable and the directory they can
|
|
|
|
|
# relocate to is removed from all filenames in the package. I
|
|
|
|
|
# suppose this is due to some change between versions of rpm, but
|
|
|
|
|
# none of this is adequatly documented, so we'll just muddle
|
|
|
|
|
# through.
|
|
|
|
|
#
|
|
|
|
|
# Test to see if the package contains the prefix directory already.
|
|
|
|
|
if (defined $this->prefixes && ! -e "$workdir/".$this->prefixes) {
|
|
|
|
|
# Get the files to move.
|
2000-05-09 21:42:41 +00:00
|
|
|
my @filelist=glob("$workdir/*");
|
2000-04-21 05:08:50 +00:00
|
|
|
|
|
|
|
|
# Now, make the destination directory.
|
|
|
|
|
my $collect=$workdir;
|
|
|
|
|
foreach (split m:/:, $this->prefixes) {
|
2000-05-09 21:42:41 +00:00
|
|
|
if ($_ ne '') { # this keeps us from using anything but relative paths.
|
2000-09-11 23:27:32 +00:00
|
|
|
$collect.="/$_";
|
2003-02-15 20:46:09 +00:00
|
|
|
mkdir($collect,0755) || die "unable to mkdir $collect: $!";
|
2000-04-21 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# Now move all files in the package to the directory we made.
|
2003-03-16 05:35:36 +00:00
|
|
|
if (@filelist) {
|
|
|
|
|
(system("mv", @filelist, "$workdir/".$this->prefixes) == 0)
|
|
|
|
|
or die "error moving unpacked files into the default prefix directory: $!";
|
|
|
|
|
}
|
2000-04-21 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-25 19:10:56 +00:00
|
|
|
# cpio does not necessarily store all parent directories in an
|
|
|
|
|
# archive, and so some directories, if it has to make them and has
|
|
|
|
|
# no permission info, may come out mode 700. Here I just chown all
|
|
|
|
|
# extracted directories to mode 755, which is more reasonable.
|
|
|
|
|
# Note that the next section overrides these default permissions,
|
|
|
|
|
# if override data exists in the rpm permissions info. And such
|
|
|
|
|
# data should always exist, so this is probably a no-op.
|
|
|
|
|
system("find $workdir -type d -perm 700 -print0 | xargs --no-run-if-empty -0 chmod 700");
|
|
|
|
|
|
|
|
|
|
# rpm files have two sets of permissions; the set in the cpio
|
|
|
|
|
# archive, and the set in the control data; which override them.
|
|
|
|
|
# The set in the control data are more correct, so let's use those.
|
|
|
|
|
# Some permissions setting may have to be postponed until the
|
|
|
|
|
# postinst.
|
|
|
|
|
my %owninfo = ();
|
|
|
|
|
open (GETPERMS, 'rpm --queryformat \'[%{FILEMODES} %{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]\' -qp '.$this->filename.' |');
|
|
|
|
|
while (<GETPERMS>) {
|
|
|
|
|
chomp;
|
|
|
|
|
my ($mode, $owner, $group, $file) = split(/ /, $_, 4);
|
|
|
|
|
$mode = $mode & 07777; # remove filetype
|
|
|
|
|
my $uid = getpwnam($owner);
|
|
|
|
|
if (! defined $uid || $> != 0) {
|
|
|
|
|
$owninfo{$file}=$owner;
|
|
|
|
|
$uid=0;
|
2000-04-21 05:08:50 +00:00
|
|
|
}
|
2002-08-25 19:10:56 +00:00
|
|
|
my $gid = getgrnam($group);
|
|
|
|
|
if (! defined $gid || $> != 0) {
|
|
|
|
|
if (exists $owninfo{$file}) {
|
|
|
|
|
$owninfo{$file}.=":$group";
|
2002-08-19 16:53:30 +00:00
|
|
|
}
|
2002-08-25 19:10:56 +00:00
|
|
|
else {
|
|
|
|
|
$owninfo{$file}=":$group";
|
2002-08-19 16:53:30 +00:00
|
|
|
}
|
2002-08-25 19:10:56 +00:00
|
|
|
$gid=0;
|
|
|
|
|
}
|
|
|
|
|
next unless -e "$workdir/$file"; # skip broken links
|
|
|
|
|
if ($> == 0) {
|
2002-08-19 16:53:30 +00:00
|
|
|
chown($uid, $gid, "$workdir/$file") || die "failed chowning $file to $uid\:$gid\: $!";
|
|
|
|
|
}
|
2002-08-25 19:10:56 +00:00
|
|
|
chmod($mode, "$workdir/$file") || die "failed changing mode of $file to $mode\: $!";
|
2002-08-19 16:53:30 +00:00
|
|
|
}
|
2002-08-25 19:10:56 +00:00
|
|
|
$this->owninfo(\%owninfo);
|
2002-08-19 16:53:30 +00:00
|
|
|
|
2000-04-21 05:08:50 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-21 08:48:04 +00:00
|
|
|
=item prep
|
|
|
|
|
|
|
|
|
|
Prepare for package building by generating the spec file.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub prep {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
|
|
|
|
|
|
|
|
|
|
# Place %config in front of files that are conffiles.
|
|
|
|
|
my @conffiles = @{$this->conffiles};
|
|
|
|
|
my $filelist;
|
|
|
|
|
foreach my $fn (@{$this->filelist}) {
|
2000-07-20 22:52:50 +00:00
|
|
|
# Unquote any escaped characters in filenames - needed for
|
|
|
|
|
# non ascii characters. (eg. iso_8859-1 latin set)
|
|
|
|
|
if ($fn =~ /\\/) {
|
|
|
|
|
$fn=eval qq{"$fn"};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Note all filenames are quoted in case they contain
|
|
|
|
|
# spaces.
|
2000-04-21 08:48:04 +00:00
|
|
|
if ($fn =~ m:/$:) {
|
2000-07-20 22:52:50 +00:00
|
|
|
$filelist.=qq{%dir "$fn"\n};
|
2000-04-21 08:48:04 +00:00
|
|
|
}
|
|
|
|
|
elsif (grep(m:^\Q$fn\E$:,@conffiles)) { # it's a conffile
|
2000-07-20 22:52:50 +00:00
|
|
|
$filelist.=qq{%config "$fn"\n};
|
2000-04-21 08:48:04 +00:00
|
|
|
}
|
|
|
|
|
else { # normal file
|
|
|
|
|
$filelist.=qq{"$fn"\n};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Write out the spec file.
|
|
|
|
|
my $spec="$dir/".$this->name."-".$this->version."-".$this->release.".spec";
|
|
|
|
|
open (OUT, ">$spec") || die "$spec: $!";
|
|
|
|
|
my $pwd=`pwd`;
|
|
|
|
|
chomp $pwd;
|
|
|
|
|
print OUT "Buildroot: $pwd/$dir\n"; # must be absolute dirname
|
|
|
|
|
print OUT "Name: ".$this->name."\n";
|
|
|
|
|
print OUT "Version: ".$this->version."\n";
|
|
|
|
|
print OUT "Release: ".$this->release."\n";
|
2002-03-24 02:35:58 +00:00
|
|
|
print OUT "Requires: ".$this->depends."\n"
|
|
|
|
|
if defined $this->depends && length $this->depends;
|
2000-04-21 08:48:04 +00:00
|
|
|
print OUT "Summary: ".$this->summary."\n";
|
|
|
|
|
print OUT "Copyright: ".$this->copyright."\n";
|
|
|
|
|
print OUT "Distribution: ".$this->distribution."\n";
|
|
|
|
|
print OUT "Group: Converted/".$this->group."\n";
|
|
|
|
|
print OUT "\n";
|
|
|
|
|
print OUT "\%define _rpmdir ../\n"; # write rpm to current directory
|
|
|
|
|
print OUT "\%define _rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm\n";
|
|
|
|
|
print OUT "\n";
|
2002-02-11 19:19:44 +00:00
|
|
|
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";
|
|
|
|
|
}
|
2000-12-08 23:11:19 +00:00
|
|
|
}
|
2000-04-21 08:48:04 +00:00
|
|
|
print OUT "\%description\n";
|
|
|
|
|
print OUT $this->description."\n";
|
|
|
|
|
print OUT "\n";
|
2002-02-11 19:19:44 +00:00
|
|
|
print OUT "(Converted from a ".$this->origformat." package by alien.)\n";
|
2000-04-21 08:48:04 +00:00
|
|
|
print OUT "\n";
|
|
|
|
|
print OUT "%files\n";
|
2002-03-24 02:35:58 +00:00
|
|
|
print OUT $filelist if defined $filelist;
|
2000-04-21 08:48:04 +00:00
|
|
|
close OUT;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-22 02:09:13 +00:00
|
|
|
=item cleantree
|
|
|
|
|
|
|
|
|
|
Delete the spec file.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub cleantree {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
|
|
|
|
|
|
|
|
|
|
unlink "$dir/".$this->name."-".$this->version."-".$this->release.".spec";
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-21 08:48:04 +00:00
|
|
|
=item build
|
|
|
|
|
|
|
|
|
|
Build a rpm. If RPMBUILDOPT is set in the environement, the options in
|
|
|
|
|
it are passed to rpm on its command line.
|
|
|
|
|
|
2002-02-11 19:19:44 +00:00
|
|
|
An optional parameter, if passed, can be used to specify the program to use
|
|
|
|
|
to build the rpm. It defaults to rpm.
|
|
|
|
|
|
2000-04-21 08:48:04 +00:00
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub build {
|
|
|
|
|
my $this=shift;
|
2003-02-03 19:40:25 +00:00
|
|
|
my $buildcmd=shift || 'rpmbuild';
|
2000-04-21 08:48:04 +00:00
|
|
|
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
|
|
|
|
|
# will output, and where it will place rpms.
|
|
|
|
|
my ($rpmarch, $rpmdir);
|
|
|
|
|
foreach (`rpm --showrc`) {
|
|
|
|
|
chomp;
|
|
|
|
|
if (/^build arch\s+:\s(.*)$/) {
|
|
|
|
|
$rpmarch=$1;
|
|
|
|
|
}
|
|
|
|
|
elsif (/^rpmdir\s+:\s(.*)$/) {
|
|
|
|
|
$rpmdir=$1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!$rpmarch) {
|
|
|
|
|
die "rpm --showrc failed";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Debian's "all" architecture is a special case, and the output rpm
|
|
|
|
|
# will be a noarch rpm.
|
|
|
|
|
$rpmarch='noarch' if $this->arch eq 'all';
|
|
|
|
|
|
|
|
|
|
my $rpm=$this->name."-".$this->version."-".$this->release.".$rpmarch.rpm";
|
2000-04-22 00:56:50 +00:00
|
|
|
my $opts='';
|
2000-04-21 08:48:04 +00:00
|
|
|
if ($rpmdir) {
|
|
|
|
|
# Old versions of rpm toss it off in the middle of nowhere.
|
|
|
|
|
$rpm="$rpmdir/$rpmarch/$rpm";
|
|
|
|
|
|
|
|
|
|
# This is the old command line argument to make noarch
|
|
|
|
|
# rpms.
|
2000-04-22 00:56:50 +00:00
|
|
|
$opts="--buildarch noarch" if $rpmarch eq 'noarch';
|
2000-04-21 08:48:04 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
# Presumably we're delaing with rpm 3.0 or above, which
|
|
|
|
|
# doesn't output rpmdir in any format I'd care to try to
|
|
|
|
|
# parse. Instead, rpm is now of a late enough version to
|
|
|
|
|
# notice the %define's in the spec file, that will make the
|
|
|
|
|
# file end up in the directory we started in.
|
|
|
|
|
# Anyway, let's assume this is version 3 or above.
|
|
|
|
|
|
|
|
|
|
# This is the new command line arcgument to make noarch
|
|
|
|
|
# rpms. It appeared in rpm version 3.
|
2002-01-04 21:12:41 +00:00
|
|
|
$opts="--target noarch" if $rpmarch eq 'noarch';
|
2000-04-21 08:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
2000-04-22 23:32:45 +00:00
|
|
|
$opts.=" $ENV{RPMBUILDOPTS}" if exists $ENV{RPMBUILDOPTS};
|
2002-02-11 19:19:44 +00:00
|
|
|
my $command="cd $dir; $buildcmd -bb $opts ".$this->name."-".$this->version."-".$this->release.".spec";
|
2002-01-04 21:12:41 +00:00
|
|
|
my $log=`$command 2>&1`;
|
2001-07-15 14:23:13 +00:00
|
|
|
if ($?) {
|
2002-01-04 21:12:41 +00:00
|
|
|
die "Package build failed. Here's the log of the command ($command):\n", $log;
|
2001-07-15 14:23:13 +00:00
|
|
|
}
|
2000-04-21 08:48:04 +00:00
|
|
|
|
|
|
|
|
return $rpm;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-21 05:08:50 +00:00
|
|
|
=item version
|
|
|
|
|
|
|
|
|
|
Set/get version.
|
|
|
|
|
|
|
|
|
|
When retreiving the version, remove any dashes in it.
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub version {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
|
|
|
|
|
# set
|
|
|
|
|
$this->{version} = shift if @_;
|
|
|
|
|
|
|
|
|
|
# get
|
|
|
|
|
return unless defined wantarray; # optimization
|
|
|
|
|
$_=$this->{version};
|
|
|
|
|
tr/-/_/;
|
|
|
|
|
return $_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
=item postinst
|
|
|
|
|
|
|
|
|
|
=item postrm
|
|
|
|
|
|
|
|
|
|
=item preinst
|
|
|
|
|
|
|
|
|
|
=item prerm
|
|
|
|
|
|
|
|
|
|
Set/get script fields.
|
|
|
|
|
|
2000-04-21 08:48:04 +00:00
|
|
|
When retrieving a value, we have to do some truely sick mangling. Since
|
2000-04-21 05:08:50 +00:00
|
|
|
debian/slackware scripts can be anything -- perl programs or binary files
|
|
|
|
|
-- and rpm is limited to only shell scripts, we need to encode the files
|
|
|
|
|
and add a scrap of shell script to make it unextract and run on the fly.
|
|
|
|
|
|
2001-02-08 03:10:41 +00:00
|
|
|
When setting a value, we do some mangling too. Rpm maitainer scripts
|
|
|
|
|
are typically shell scripts, but often lack the leading #!/bin/sh
|
|
|
|
|
This can confuse dpkg, so add the #!/bin/sh if it looks like there
|
|
|
|
|
is no shebang magic already in place.
|
|
|
|
|
|
2000-04-21 05:08:50 +00:00
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
# This helper function deals with all the scripts.
|
|
|
|
|
sub _script_helper {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
my $script=shift;
|
|
|
|
|
|
|
|
|
|
# set
|
2001-02-08 03:10:41 +00:00
|
|
|
if (@_) {
|
|
|
|
|
my $value=shift;
|
2002-03-06 17:59:15 +00:00
|
|
|
if (length $value and $value !~ m/^#!\s*\//) {
|
2001-02-08 03:10:41 +00:00
|
|
|
$value="#!/bin/sh\n$value";
|
|
|
|
|
}
|
|
|
|
|
$this->{$script} = $value;
|
|
|
|
|
}
|
2000-04-21 05:08:50 +00:00
|
|
|
$this->{$script} = shift if @_;
|
|
|
|
|
|
|
|
|
|
# get
|
|
|
|
|
return unless defined wantarray; # optimization
|
|
|
|
|
$_=$this->{$script};
|
2000-04-22 02:09:13 +00:00
|
|
|
return '' unless defined $_;
|
|
|
|
|
return $_ if m/^\s*$/;
|
2002-03-06 17:59:15 +00:00
|
|
|
return $_ if m/^#!\s*\/bin\/sh/; # looks like a shell script already
|
2000-04-21 05:08:50 +00:00
|
|
|
my $f = pack("u",$_);
|
|
|
|
|
$f =~ s/%/%%/g; # Rpm expands %S, so escape such things.
|
2001-02-08 03:10:41 +00:00
|
|
|
return "#!/bin/sh\n".
|
|
|
|
|
"set -e\n".
|
2000-04-21 05:08:50 +00:00
|
|
|
"mkdir /tmp/alien.\$\$\n".
|
|
|
|
|
qq{perl -pe '\$_=unpack("u",\$_)' << '__EOF__' > /tmp/alien.\$\$/script\n}.
|
|
|
|
|
$f."__EOF__\n".
|
|
|
|
|
"chmod 755 /tmp/alien.\$\$/script\n".
|
|
|
|
|
"/tmp/alien.\$\$/script \"\$@\"\n".
|
|
|
|
|
"rm -f /tmp/alien.\$\$/script\n".
|
|
|
|
|
"rmdir /tmp/alien.\$\$";
|
|
|
|
|
}
|
|
|
|
|
sub postinst {
|
|
|
|
|
my $this=shift;
|
2000-04-22 01:47:39 +00:00
|
|
|
$this->_script_helper('postinst', @_);
|
2000-04-21 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
sub postrm {
|
|
|
|
|
my $this=shift;
|
2000-04-22 01:47:39 +00:00
|
|
|
$this->_script_helper('postrm', @_);
|
2000-04-21 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
sub preinst {
|
|
|
|
|
my $this=shift;
|
2000-04-22 01:47:39 +00:00
|
|
|
$this->_script_helper('preinst', @_);
|
2000-04-21 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
sub prerm {
|
|
|
|
|
my $this=shift;
|
2000-04-22 01:47:39 +00:00
|
|
|
$this->_script_helper('prerm', @_);
|
2000-04-21 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
2000-04-21 02:23:53 +00:00
|
|
|
=item arch
|
|
|
|
|
|
|
|
|
|
Set/get arch field. When the arch field is set, some sanitizing is done
|
2000-04-21 05:08:50 +00:00
|
|
|
first to convert it to the debian format used internally.
|
2000-04-21 02:23:53 +00:00
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
sub arch {
|
|
|
|
|
my $this=shift;
|
|
|
|
|
return $this->{arch} unless @_;
|
|
|
|
|
my $arch=shift;
|
|
|
|
|
|
|
|
|
|
if ($arch eq 1) {
|
|
|
|
|
$arch='i386';
|
|
|
|
|
}
|
|
|
|
|
elsif ($arch eq 2) {
|
|
|
|
|
$arch='alpha';
|
|
|
|
|
}
|
|
|
|
|
elsif ($arch eq 3) {
|
|
|
|
|
$arch='sparc';
|
|
|
|
|
}
|
|
|
|
|
elsif ($arch eq 6) {
|
|
|
|
|
$arch='m68k';
|
|
|
|
|
}
|
|
|
|
|
elsif ($arch eq 'noarch') {
|
|
|
|
|
$arch='all';
|
|
|
|
|
}
|
|
|
|
|
elsif ($arch eq 'ppc') {
|
|
|
|
|
$arch='powerpc';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Treat 486, 586, etc, as 386.
|
2000-04-21 05:08:50 +00:00
|
|
|
if ($arch =~ m/i\d86/i || $arch =~ m/pentium/i) {
|
2000-04-21 02:23:53 +00:00
|
|
|
$arch='i386';
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-18 17:42:39 +00:00
|
|
|
# Treat armv4l as arm.
|
|
|
|
|
if ($arch eq 'armv4l') {
|
|
|
|
|
$arch='arm';
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-21 02:23:53 +00:00
|
|
|
return $this->{arch}=$arch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
|
|
Joey Hess <joey@kitenet.net>
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
1
|