Files
alien/Alien/Package/Tgz.pm

225 lines
4.4 KiB
Perl
Raw Normal View History

2000-04-21 21:26:14 +00:00
#!/usr/bin/perl -w
=head1 NAME
Alien::Package::Tgz - an object that represents a tgz package
=cut
2000-04-21 23:30:45 +00:00
package Alien::Package::Tgz;
2000-04-21 21:26:14 +00:00
use strict;
use base qw(Alien::Package);
=head1 DESCRIPTION
This is an object class that represents a tgz package, as used in Slackware.
It is derived from Alien::Package.
2000-04-21 22:09:14 +00:00
=head1 CLASS DATA
=over 4
=item scripttrans
Translation table between canoical script names and the names used in
tgz's.
=cut
2000-04-22 01:16:10 +00:00
use constant scripttrans => {
2000-04-21 22:09:14 +00:00
postinst => 'doinst.sh',
postrm => 'delete.sh',
prerm => 'predelete.sh',
preinst => 'predoinst.sh',
};
=back
2000-04-21 21:26:14 +00:00
=head1 METHODS
=over 4
2000-04-21 22:18:49 +00:00
=item checkfile
Detect tgz files by their extention.
=cut
sub checkfile {
my $this=shift;
my $file=shift;
return $file =~ m/.*\.(?:tgz|tar\.(?:gz|Z|z)|taz)$/;
}
2000-04-21 21:26:14 +00:00
=item install
Install a tgz with installpkg. Pass in the filename of the tgz to install.
installpkg (a slackware program) is used because I'm not sanguine about
just untarring a tgz file. It might trash a system.
=cut
sub install {
my $this=shift;
my $tgz=shift;
if (-x "/sbin/installpkg") {
$this->do("/sbin/installpkg", "$tgz")
or die "Unable to install";
2000-04-21 21:26:14 +00:00
}
else {
die "Sorry, I cannot install the generated .tgz file because /sbin/installpkg is not present. You can use tar to install it yourself.\n"
}
}
=item scan
2000-04-21 22:09:14 +00:00
Scan a tgz file for fields. Has to scan the filename for most of the
information, since there is little useful metadata in the file itself.
2000-04-21 21:26:14 +00:00
=cut
sub scan {
my $this=shift;
$this->SUPER::scan(@_);
my $file=$this->filename;
# Get basename of the filename.
my ($basename)=('/'.$file)=~m#^/?.*/(.*?)$#;
# Strip out any tar extentions.
$basename=~s/\.(tgz|tar\.(gz|Z))$//;
if ($basename=~m/(.*)-(.*?[0-9]+.*)/) {
2000-04-21 21:26:14 +00:00
$this->name($1);
$this->version($2);
}
else {
$this->name($basename);
$this->version(1);
}
$this->arch('all');
$this->summary("Converted Slackware tgz package");
$this->description($this->summary);
$this->copyright('unknown');
$this->release(1);
$this->distribution("Slackware");
$this->group("unknown");
2000-04-21 21:26:14 +00:00
$this->origformat('tgz');
2000-04-22 01:47:39 +00:00
$this->changelogtext('');
$this->binary_info($this->runpipe("ls -l $file"));
2000-04-21 21:26:14 +00:00
# Now figure out the conffiles. Assume anything in etc/ is a
# conffile.
my @conffiles;
open (FILELIST,"tar zvtf $file | grep etc/ |") ||
die "getting filelist: $!";
while (<FILELIST>) {
# Make sure it's a normal file. This is looking at the
# permissions, and making sure the first character is '-'.
# Ie: -rw-r--r--
if (m:^-:) {
# Strip it down to the filename.
m/^(.*) (.*)$/;
push @conffiles, "/$2";
}
}
$this->conffiles(\@conffiles);
# Now get the whole filelist. We have to add leading /'s to the
# filenames. We have to ignore all files under /install/
my @filelist;
open (FILELIST, "tar ztf $file |") ||
die "getting filelist: $!";
while (<FILELIST>) {
chomp;
2000-04-21 21:26:14 +00:00
unless (m:^install/:) {
push @filelist, "/$_";
}
}
$this->filelist(\@filelist);
# Now get the scripts.
2000-04-21 22:09:14 +00:00
foreach my $script (keys %{scripttrans()}) {
$this->$script($this->runpipe("tar Oxzf $file install/${scripttrans()}{$script} 2>/dev/null"));
2000-04-21 21:26:14 +00:00
}
return 1;
}
=item unpack
Unpack tgz.
=cut
sub unpack {
my $this=shift;
$this->SUPER::unpack(@_);
my $file=$this->filename;
$this->do("cat $file | (cd ".$this->unpacked_tree."; tar zxpf -)")
or die "Unpacking of '$file' failed: $!";
2000-04-21 21:26:14 +00:00
# Delete the install directory that has slackware info in it.
$this->do("cd ".$this->unpacked_tree."; rm -rf ./install");
2000-04-21 21:26:14 +00:00
return 1;
}
=item prep
2000-04-21 22:09:14 +00:00
Adds a populated install directory to the build tree.
2000-04-21 21:26:14 +00:00
=cut
sub prep {
my $this=shift;
my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
2000-04-21 22:09:14 +00:00
my $install_made=0;
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)
|| die "unable to mkdir ".$this->unpacked_tree."/install: $!";
$install_made=1;
}
open (OUT, ">$out") || die "$out: $!";
print OUT $data;
close OUT;
$this->do("chmod", 755, $out);
2000-04-21 22:09:14 +00:00
}
}
2000-04-21 21:26:14 +00:00
}
=item build
Build a tgz.
=cut
sub build {
my $this=shift;
my $tgz=$this->name."-".$this->version.".tgz";
$this->do("cd ".$this->unpacked_tree."; tar czf ../$tgz .")
or die "Package build failed";
2000-04-21 21:26:14 +00:00
return $tgz;
}
=head1 AUTHOR
Joey Hess <joey@kitenet.net>
=cut
1