Initial revision

This commit is contained in:
joey
1999-09-05 06:03:10 +00:00
parent ad046046f0
commit e546405fae
25 changed files with 2751 additions and 0 deletions

175
lib/Alien.pm Normal file
View File

@@ -0,0 +1,175 @@
#!/usr/bin/perl
#
# Misc. functions used by alien.
package Alien;
use strict;
# Print out a status line.
sub Status { my $message=shift;
print "-- $message\n";
}
# Print out an error message and exit the program.
sub Error { my $message=shift;
print STDERR "alien: $message\n";
exit 1;
}
# Run a system command, and print an error message if it fails.
# The errormessage parameter is optional.
sub SafeSystem { my ($command,$errormessage)=@_;
my $ret=system $command;
if (int($ret/256) > 0) {
$errormessage="Error running: $command" if !$errormessage;
Error($errormessage);
}
}
# Make the passed directory. Exits with error if the directory already
# exists.
sub SafeMkdir { my ($dir)=@_;
if (-e $dir) {
Error("Directory $dir already exists.\nRemove it and re-run alien.");
}
mkdir $dir,0755 || Error("Unable to make directory, \"$dir\": $!");
}
# Pass the filename of a package.
# Returns "rpm" or "tgz" or "deb", depending on what it thinks the file type
# is, based on the filename.
# Perhaps this should call file(1), instead?
#
# Note that the file type this returns corresponds to directories in
# $libdir.
sub FileType { my $file=shift;
if ($file=~m/.*\.rpm/ ne undef) {
return 'rpm';
}
elsif ($file=~m/.*\.(tgz|tar\.gz)/ ne undef) {
return 'tgz';
}
elsif ($file=~m/.*\.deb/ ne undef) {
return 'deb';
}
else {
Error("Format of filename bad: $file");
}
}
# Pass this the name and version and revision of a package, it will return the
# filename of a patch file for the package or undef if there is none.
sub GetPatch { my ($name,$version,$revision)=@_;
my @patches=glob("$main::patchdir/$name\_$version-$revision*.diff.gz");
if ($#patches < 0) {
# try not matching the revision, see if that helps.
@patches=glob("$main::patchdir/$name\_$version*.diff.gz");
if ($#patches < 0) {
# fallback to anything that matches the name.
@patches=glob("$main::patchdir/$name\_*.diff.gz");
}
}
# If we ended up with multiple matches, return the first.
return $patches[0];
}
# Apply the given patch file to the given subdirectory.
sub Patch { my ($patchfile,$subdir)=@_;
Status("Patching in $patchfile");
chdir $subdir;
# cd .. here in case the patchfile's name was a relative path.
# The -f passed to zcat makes it pass uncompressed files through
# without error.
SafeSystem("(cd ..;zcat -f $patchfile) | patch -p1","Patch error.\n");
# look for .rej files
if (`find . -name "*.rej"`) {
Error("Patch failed: giving up.");
}
SafeSystem('find . -name \'*.orig\' -exec rm {} \\;',"Error removing .orig files");
chdir "..";
}
# Returns the 822-date.
sub GetDate {
my $date=`822-date`;
chomp $date;
if (!$date) {
Error("822-date did not return a valid result.\n");
}
return $date;
}
# Returns a email address for the current user.
sub GetEmail {
if (!$ENV{EMAIL}) {
my $login = getlogin || (getpwuid($<))[0] || $ENV{USER};
open (MAILNAME,"</etc/mailname");
my $mailname=<MAILNAME>;
chomp $mailname;
close MAILNAME;
if (!$mailname) {
$mailname=`hostname -f`;
chomp $mailname;
}
return "$login\@$mailname";
}
else {
return $ENV{EMAIL};
}
}
# Returns the user name of the user who is running this.
sub GetUserName {
my $username;
my $username_in_passwd=undef;
my $login = getlogin || (getpwuid($<))[0] || $ENV{USER};
open (PASSWD,"</etc/passwd");
while (<PASSWD>) {
my (@fields)=split(/:/,$_);
if ($fields[0] eq $login) {
$username=$fields[4];
$username_in_passwd=1; # don't try NIS, no matter what.
close PASSWD;
}
}
close PASSWD;
if (!$username_in_passwd && !$username && -x "/usr/bin/ypmatch") {
# Give NIS a try.
open (YPMATCH,"ypmatch $login passwd.byname |");
my (@fields)=split(/:/,<YPMATCH>);
$username=$fields[4];
close YPMATCH;
}
# Remove GECOS(?) fields from username.
$username=~s/,.*//g;
# The ultimate fallback.
if (!$username) {
$username=$login;
}
return $username;
}
# Fill out a template, and save it to the passed location.
# The hash that is passed to this function lists the tags that can be onthe
# template, and the values to fill in for those tags.
sub FillOutTemplate { my ($fn,$destfn,%fields)=@_;
open (IN,"<$fn") || Error("$fn: $!");
open (OUT,">$destfn") || Error("$destfn: $!");
while (<IN>) {
s/#(.*?)#/$fields{$1}/g;
print OUT $_;
}
close OUT;
close IN;
}
1

131
lib/Fromdeb.pm Normal file
View File

@@ -0,0 +1,131 @@
#!/usr/bin/perl
#
# Package for converting from a .deb file.
package From::deb;
use strict;
# Global variable initialization.
# This is set to 1 if dpkg-deb is in the path.
my $dpkg_deb=undef;
my $dir;
foreach $dir (split(/:/,$ENV{PATH})) {
if (-x "$dir/dpkg-deb") {
$dpkg_deb=1;
last;
}
}
# Query a deb file for fields, and return a hash of the fields found.
# Pass the filename of the deb file to query.
sub GetFields { my ($self,$file)=@_;
my %fields;
# Extract the control file from the deb file.
my @control;
if ($dpkg_deb) {
@control = `dpkg-deb --info $file control`;
}
else {
@control = `ar p $file control.tar.gz | tar Oxzf - control`;
}
# Parse control file and extract fields.
my $i=0;
while ($i<=$#control) {
$_ = $control[$i];
chomp;
$fields{NAME} = $1 if (/^Package: (.+)/i);
$fields{VERSION} = $1 if (/^Version: (.+)/i);
$fields{ARCH} = $1 if (/^Architecture: (.+)/i);
$fields{MAINTAINER} = $1 if (/^Maintainer: (.+)/i);
$fields{DEPENDS} = $1 if (/^Depends: (.+)/i);
$fields{REQUIRES} = $1 if (/^Requires: (.+)/i);
$fields{GROUP} = $1 if (/^Section: (.+)/i);
if (/^Description: (.+)/i) {
$fields{SUMMARY} = "$1";
$i++;
while (($i<=$#control) && ($control[$i])) {
$control[$i] =~ s/^ //g; #remove leading space
$control[$i] = "\n" if ($control[$i] eq ".\n");
$fields{DESCRIPTION}.=$control[$i];
$i++;
}
$i--;
}
$i++;
}
$fields{COPYRIGHT}="see /usr/doc/$fields{NAME}/copyright";
$fields{GROUP}="unknown" if (!$fields{GROUP});
$fields{DISTRIBUTION}="Debian";
if ($fields{VERSION} =~ /(.+)-(.+)/) {
$fields{VERSION} = $1;
$fields{RELEASE} = $2;
} else {
$fields{RELEASE} = '1';
}
# Just get rid of epochs for now.
if ($fields{VERSION} =~ /\d+:(.*)/) {
$fields{VERSION} = $1;
}
# Read in the list of conffiles, if any.
if ($dpkg_deb) {
$fields{CONFFILES}=`dpkg-deb --info $file conffiles 2>/dev/null`;
}
else {
$fields{CONFFILES}=
`ar p $file control.tar.gz | tar Oxzf - conffiles 2>/dev/null`;
}
# Read in the list of all files.
# Note that tar doesn't supply a leading `/', so we have to add that.
$fields{FILELIST}=undef;
if ($dpkg_deb) {
my $fn;
foreach $fn (`dpkg-deb --fsys-tarfile $file | tar tf -`) {
$fields{FILELIST}.="/$fn";
}
}
else {
my $fn;
foreach $fn (`ar p $file data.tar.gz | tar tzf -`) {
$fields{FILELIST}.="/$fn";
}
}
if ($main::scripts) {
# Read in the scripts, if any.
my $field;
for $field ('postinst', 'postrm', 'preinst', 'prerm') {
if ($dpkg_deb) {
$fields{uc($field)}=`dpkg-deb --info $file $field 2>/dev/null`;
}
else {
$fields{uc($field)}=
`ar p $file control.tar.gz | tar Oxzf - $field 2>/dev/null`;
}
}
}
$fields{RELEASE}++ unless $main::keep_version;
return %fields;
}
# Handles unpacking of debs.
sub Unpack { my ($self,$file,%fields)=@_;
if ($dpkg_deb) {
Alien::SafeSystem ("(cd ..;dpkg-deb -x $file $fields{NAME}-$fields{VERSION})",
"Error unpacking $file\n");
}
else {
Alien::SafeSystem ("(cd ..;ar p $file data.tar.gz) | tar zxpf -",
"Error unpacking $file\n");
}
}
1

128
lib/Fromrpm.pm Normal file
View File

@@ -0,0 +1,128 @@
#!/usr/bin/perl
#
# Package for converting from a .rpm file.
package From::rpm;
use strict;
# Query a rpm file for fields, and return a hash of the fields found.
# Pass the filename of the rpm file to query.
sub GetFields { my ($self,$file)=@_;
my %fields;
# This maps rpm fields (the keys) to the name we want
# for each field (the values).
my %fieldtrans;
# Get the scripts fields too?
if ($main::scripts) {
%fieldtrans=(
'PREIN' => 'PREINST',
'POSTIN' => 'POSTINST',
'PREUN' => 'PRERM',
'POSTUN' => 'POSTRM',
);
}
# These fields need no translation.
my $field;
foreach $field ('NAME','VERSION','RELEASE','ARCH','CHANGELOGTEXT','SUMMARY',
'DESCRIPTION', 'COPYRIGHT', 'DEFAULTPREFIX') {
$fieldtrans{$field}=$field;
}
# Use --queryformat to pull out all the fields we need.
foreach $field (keys(%fieldtrans)) {
$_=`rpm -qp $file --queryformat \%{$field}`;
$fields{$fieldtrans{$field}}=$_ if $_ ne '(none)';
}
if ($main::scripts) {
# Fix up the scripts - they are always shell scripts, so make them so.
foreach $field ('PREINST','POSTINST','PRERM','POSTRM') {
$fields{$field}="#!/bin/sh\n$fields{$field}" if $fields{$field};
}
}
# Get the conffiles list.
# TOCHECK: if this is a relocatable package and DEFAULTPREFIX is set,
# do we need to prepend DEFAULTPREFIX to each of these filenames?
$fields{CONFFILES}=`rpm -qcp $file`;
# Include the output of rpm -qi in the copyright file.
$fields{COPYRIGHT_EXTRA}=`rpm -qpi $file`;
# Sanity check fields.
if (!$fields{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.
($fields{SUMMARY})=($fields{DESCRIPTION}."\n")=~m/(.*?)\n/m;
# Fallback.
if (!$fields{SUMMARY}) {
$fields{SUMMARY}="Converted RPM package";
}
}
if (!$fields{COPYRIGHT}) {
$fields{COPYRIGHT}="unknown";
}
if (!$fields{DESCRIPTION}) {
$fields{DESCRIPTION}=$fields{SUMMARY};
}
# Convert ARCH into string, if it isn't already a string.
if ($fields{ARCH} eq 1) {
$fields{ARCH}='i386';
}
elsif ($fields{ARCH} eq 2) {
$fields{ARCH}='alpha';
}
elsif ($fields{ARCH} eq 3) {
$fields{ARCH}='sparc';
}
elsif ($fields{ARCH} eq 6) {
$fields{ARCH}='m68k';
}
elsif ($fields{ARCH} eq "noarch") { # noarch = all
$fields{ARCH}='all';
}
if ($fields{RELEASE} eq undef || $fields{VERSION} eq undef|| !$fields{NAME}) {
Alien::Error("Error querying rpm file.");
}
$fields{RELEASE}++ unless $main::keep_version;
$fields{DISTRIBUTION}="Red Hat";
return %fields;
}
# Unpack a rpm file.
sub Unpack { my ($self,$file,%fields)=@_;
Alien::SafeSystem("(cd ..;rpm2cpio $file) | cpio --extract --make-directories --no-absolute-filenames --preserve-modification-time",
"Error unpacking $file\n");
if ($fields{DEFAULTPREFIX} ne undef) {
print "Moving unpacked files into $fields{DEFAULTPREFIX}\n";
# We have extracted the package, but it's in the wrong place. Move it
# to be under the DEFAULTPREFIX directory.
# First, get a list of files to move.
my $filelist=join ' ',glob('*');
# Now, make the destination directory.
my $collect=undef;
foreach (split(m:/:,$fields{DEFAULTPREFIX})) {
if ($_ ne undef) { # this keeps us from using anything but relative paths.
$collect.="$_/";
mkdir $collect,0755 || Alien::Error("Unable to make directory: $collect: $!");
}
}
# Now move all files in the package to the directory we made.
Alien::SafeSystem("mv $filelist ./$fields{DEFAULTPREFIX}",
"Error moving unpacked files into the default prefix directory\n");
}
}
1

139
lib/Fromslp.pm Normal file
View File

@@ -0,0 +1,139 @@
#!/usr/bin/perl
#
# Package for converting from a .slp (Stampede) file.
package From::slp;
use strict;
# Becuase .slp files are a binary format we parse by hand, I need to code in
# the details of the structure here.
# Complete sizeof(slpformat) from slp.h in the stampede package manager source.
$From::slp::footer_size=3784;
# This is the pack format string for the footer.
$From::slp::footer_packstring="A756IIIIA128A128A80A1536A512A512A30A30IA20A20III";
# What package format are we up to now? (Lowest one this is still compatable
# with.)
$From::slp::footer_version=5;
# Pass it a chunk of footer, it will attempt a decode and spit back the result
# in a hash, %fields.
sub DecodeFooter { my $footer=shift;
my %fields;
($fields{CONFFILES},
$fields{PRIORITY},
$fields{COMPRESSTYPE},
$fields{RELEASE},
$fields{COPYRIGHT},
$fields{CONFLICTS},
$fields{SETUPSCRIPT},
$fields{SUMMARY},
$fields{DESCRIPTION},
$fields{DEPENDS},
$fields{PROVIDES},
$fields{AUTHOR},
$fields{DATE},
$fields{COMPILER},
$fields{VERSION},
$fields{NAME},
$fields{ARCH},
$fields{GROUP},
$fields{SLPKGVERSION},
)=unpack($From::slp::footer_packstring,$footer);
# A simple sanity check.
if (! $fields{SLPKGVERSION} || $fields{SLPKGVERSION} < $From::slp::footer_version) {
Alien::Error("This is not a V$From::slp::footer_version or greater Stampede package");
}
return %fields;
}
# Pass it a filename of a .slp file, it will pull out a footer and return it
# in a scalar.
sub GetFooter { my ($filename)=@_;
open (SLP,"<$filename") || Alien::Error("unable to read $filename: $!");
seek SLP,(-1 * $From::slp::footer_size),2; # position at beginning of footer (2 = seek from EOF)
read SLP,$_,$From::slp::footer_size;
close SLP;
return $_;
}
# Query a slp file for fields, and return a hash of the fields found.
# Pass the filename of the slp file to query.
sub GetFields { my ($self,$file)=@_;
my %fields=DecodeFooter(GetFooter($file));
# Massage the fields into appropriate formats.
if ($fields{CONFFILES}) {
$fields{CONFFILES}=~s/:/\n/g;
$fields{CONFFILES}.="\n";
}
if ($fields{COPYRIGHT} == 0) {
$fields{COPYRIGHT}="GPL";
}
elsif ($fields{COPYRIGHT} == 1) {
$fields{COPYRIGHT}="BSD";
}
elsif ($fields{COPYRIGHT} == 2) {
$fields{COPYRIGHT}="LGPL";
}
elsif ($fields{COPYRIGHT} == 3) {
$fields{COPYRIGHT}="unknown";
}
else {
Alien::Warning("I don't know what copyright type \"$fields{COPYRIGHT}\" is.");
$fields{COPYRIGHT}="unknown";
}
if ($fields{ARCH} == 0) {
$fields{ARCH}='all';
}
elsif ($fields{ARCH} == 1) {
$fields{ARCH}='i386';
}
elsif ($fields{ARCH} == 2) {
$fields{ARCH}='sparc';
}
elsif ($fields{ARCH} == 3) {
$fields{ARCH}='alpha';
}
elsif ($fields{ARCH} == 4) {
$fields{ARCH}='powerpc';
}
elsif ($fields{ARCH} == 5) {
$fields{ARCH}='m68k';
}
else {
Alien::Error("An unknown architecture of \"$fields{ARCH}\" was specified.");
}
$fields{RELEASE}++ unless $main::keep_version;
$fields{DISTRIBUTION}="Stampede";
# Read in the list of all files.
# Note that they will have a leading "." we don't want.
$fields{FILELIST}=undef;
my $fn;
foreach $fn (`tar -Itf $file`) {
$fn=~s/^\.//;
$fields{FILELIST}.="$fn\n";
}
# TODO: read in postinst script.
return %fields;
}
# Unpack a slp file.
sub Unpack { my ($self,$file,%fields)=@_;
# Note it's a .tar.bz2, this the -I
Alien::SafeSystem ("(cd ..;cat $file) | tar Ixpf -","Error unpacking $file\n");
}
1

96
lib/Fromtgz.pm Normal file
View File

@@ -0,0 +1,96 @@
#!/usr/bin/perl
#
# Package for converting from a tgz file.
package From::tgz;
use strict;
# Query a tgz file for fields, and return a hash of the fields found.
# Pass the filename of the tgz file to query.
sub GetFields { my ($self,$file)=@_;
my %fields;
# Get basename of the filename.
my ($basename)=('/'.$file)=~m#^/?.*/(.*?)$#;
# Strip out any tar extentions.
$basename=~s/\.(tgz|tar\.gz)$//;
if ($basename=~m/(.*)-(.*)/ ne undef) {
$fields{NAME}=$1;
$fields{VERSION}=$2;
}
else {
$fields{NAME}=$basename;
$fields{VERSION}=1;
}
$fields{ARCH}='i386';
if ($main::tgzdescription eq undef) {
$fields{SUMMARY}='Converted Slackware tgz package';
}
else {
$fields{SUMMARY}=$main::tgzdescription;
}
$fields{DESCRIPTION}=$fields{SUMMARY};
$fields{COPYRIGHT}="unknown";
$fields{RELEASE}=1;
$fields{DISTRIBUTION}="Slackware";
# Now figure out the conffiles. Assume anything in etc/ is a conffile.
# It's a little nasty to do it here, but it's much cleaner than waiting
# until the tar file is unpacked and then doing it.
$fields{CONFFILES}='';
open (FILELIST,"tar zvtf $file | grep etc/ |")
|| Alien::Error("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/^(.*) (.*)$/;
$fields{CONFFILES}.="/$2\n";
}
}
close FILELIST;
# Now get the whole filelist. We have to add leading /'s to the filenames.
# We have to ignore all files under /install/
$fields{FILELIST}='';
open (FILELIST, "tar ztf $file |");
while (<FILELIST>) {
if ($_=~m:^install/: eq undef) {
$fields{FILELIST}.="/$_";
}
}
close FILELIST;
# Now get the scripts.
if ($main::scripts) {
my %scripttrans=(
'doinst.sh' => 'POSTINST',
'delete.sh' => 'POSTRM',
'predelete.sh' => 'PRERM',
'predoinst.sh' => 'PREINST',
);
my $script;
foreach $script (keys(%scripttrans)) {
$fields{$scripttrans{$script}}=
`tar Oxzf $file install/$script 2>/dev/null`;
}
}
return %fields;
}
# Handles unpacking of tgz's.
sub Unpack { my ($self,$file)=@_;
Alien::SafeSystem ("(cd ..;cat $file) | tar zxpf -","Error unpacking $file\n");
# Delete this install directory that has slackware info in it.
Alien::SafeSystem ("rm -rf install");
}
1

41
lib/Slp.pm Normal file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/perl
# Becuase .slp files are a binary format we parse by hand, I need to code in
# the details of the structure here.
package slp;
use strict;
# Complete sizeof(slpformat) from slp.h in the stampede package manager source.
$slp::footer_size=3784;
# This is the pack format string for the footer.
# (A=space terminated character, I=unsigned integer.)
$slp::footer_packstring="A756IIIIA128A128A80A1536A512A512A30A30IA20A20III";
# What package format are we up to now? (Lowest one this is still compatable
# with.)
$slp::footer_version=5;
# This is a translation table between architectures and the number
# that represents them in a slp package.
$slp::archtrans={
0 => 'all',
1 => 'i386',
2 => 'sparc',
3 => 'alpha',
4 => 'powerpc',
5 => 'm68k',
};
# This is a translation table between copyrights and the number that
# represents them in a slp package
$slp::copyrighttrans={
0 => 'GPL',
1 => 'BSD',
2 => 'LGPL',
3 => 'unknown',
254 => 'unknown',
};
1

113
lib/Todeb.pm Normal file
View File

@@ -0,0 +1,113 @@
#!/usr/bin/perl
#
# Package for converting to .deb file.
package To::deb;
use strict;
# Mangle the fields to fit debian standards.
sub FixFields { my ($self,%fields)=@_;
# Make sure package name is all lower case.
$fields{NAME}=lc($fields{NAME});
# Make sure the package name contains no invalid characters.
$fields{NAME} =~ tr/_/-/;
$fields{NAME} =~ s/[^a-z0-9-\.\+]//g;
# Fix up the description field to Debian standards (indented at
# least one space, no empty lines.)
my $description=undef;
my $line;
foreach $line (split(/\n/,$fields{DESCRIPTION})) {
$line=~s/\t/ /g; # change tabs to spaces.
$line=~s/\s+$//g; # remove trailing whitespace.
if (!$line) { # empty lines
$line=" .";
}
else { # normal lines
$line=" $line";
}
$description.=$line."\n";
}
chomp $description;
$fields{DESCRIPTION}=$description."\n";
return %fields;
}
# Create debian/* files, either from a patch, or automatically.
sub Convert { my ($self,$workdir,%fields)=@_;
if ($main::generate && !$main::single) {
Alien::SafeSystem("cp -fa $workdir $workdir.orig", "Error creating $workdir.orig");
}
# Do the actual conversion here.
mkdir "$fields{NAME}-$fields{VERSION}/debian",0755
|| Alien::Error("Unable to make debian directory");
my $patchfile=$main::patchfile;
$patchfile=Alien::GetPatch($fields{NAME},$fields{VERSION},$fields{RELEASE}) if !$patchfile;
if ($patchfile) {
Alien::Patch($patchfile,$workdir);
}
else {
$self->AutoDebianize($workdir,%fields);
}
chmod 0755,"$workdir/debian/rules";
# Make the .orig directory if we were instructed to do so.
if ($main::single) {
print "Directory $workdir prepared.\n";
}
elsif ($main::generate) {
print "Directories $workdir and $workdir.orig prepared.\n";
}
}
# Fill out templates to create debian/* files.
# Pass it the work directory, and the type of package we are debianizing.
sub AutoDebianize { my ($self,$workdir,%fields)=@_;
Alien::Status("Automatic package debianization");
# Generate some more fields we need.
$fields{DATE}=Alien::GetDate();
$fields{EMAIL}=Alien::GetEmail();
$fields{USERNAME}=Alien::GetUserName();
# Fill out all the templates.
my $fn;
foreach $fn (glob("$main::libdir/to-$main::desttype/$main::filetype/*")) {
my $destfn=$fn;
$destfn=~s#^$main::libdir/to-$main::desttype/$main::filetype/##;
Alien::FillOutTemplate($fn,"$main::workdir/debian/$destfn",%fields);
}
# Autogenerate the scripts without templates, so the scripts
# only exist if they need to.
my $script;
foreach $script ('postinst','postrm','preinst','prerm') {
if ($fields{uc($script)}) {
open (OUT,">$workdir/debian/$script") ||
Alien::Error("$workdir/debian/$script: $!");;
print OUT $fields{uc($script)};
close OUT;
}
}
}
# Passed the available info about the package in a hash, return the name of
# the debian package that will be made.
sub GetPackageName { my ($self,%fields)=@_;
return "$fields{NAME}_$fields{VERSION}-$fields{RELEASE}_$fields{ARCH}.deb";
}
# Build the debian package.
sub Build { my ($self)=@_;
Alien::SafeSystem("debian/rules binary","Package build failed.\n");
}
# Install the debian package that is passed.
sub Install { my ($self,$package)=@_;
Alien::SafeSystem("dpkg --no-force-overwrite -i $package");
}
1

109
lib/Torpm.pm Normal file
View File

@@ -0,0 +1,109 @@
#!/usr/bin/perl
#
# Package for converting to .rpm file.
package To::rpm;
use strict;
# Mangle the fields to make rpm happy with them.
sub FixFields { my ($self,%fields)=@_;
# Make sure the version has no dashes in it.
$fields{VERSION} =~ tr/-/_/;
# Fix up the scripts. Since debian/slackware scripts can be anything, even
# perl programs or binary files, and redhat 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.
my $field;
foreach $field ('POSTINST', 'POSTRM', 'PREINST', 'PRERM') {
if ($fields{$field}) {
$fields{$field}=
"rm -f /tmp/alien.$field\n".
qq{perl -pe '\$_=unpack("u",\$_)' << '__EOF__' > /tmp/alien.$field\n}.
pack("u",$fields{$field}).
"__EOF__\n".
"sh /tmp/alien.$field \"\$@\"\n".
"rm -f /tmp/alien.$field\n";
}
}
return %fields;
}
# Generate the spec file.
sub Convert { my ($self,$workdir,%fields)=@_;
Alien::Status("Automatic spec file generation");
# Create some more fields we will need.
my $pwd=`pwd`;
chomp $pwd;
$fields{BUILDROOT}="$pwd/$workdir"; # must be absolute filename.
# Remove directories from the filelist. Place %config in front of files
# that are conffiles.
my @conffiles=split(/\n/,$fields{CONFFILES});
my $filelist;
my $fn;
foreach $fn (split(/\n/,$fields{FILELIST})) {
if ($fn=~m:/$: eq undef) { # not a directory
my $efn=quotemeta($fn);
if (grep(m:^$efn$:,@conffiles)) { # it's a conffile
$filelist.="%config $fn\n";
}
else { # normal file
$filelist.="$fn\n";
}
}
}
$fields{FILELIST}=$filelist;
Alien::FillOutTemplate("$main::libdir/to-$main::desttype/$main::filetype/spec",
"$workdir/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",%fields);
if ($main::generate) {
print "Directory $workdir prepared.\n";
}
}
# Passed the available info about the package in a hash, return the name of
# the rpm package that will be made.
sub GetPackageName { my ($self,%fields)=@_;
# 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 || !$rpmdir) {
Alien::Error("rpm --showrc failed.");
}
# Debian's "all" architecture is a special case, and the output rpm will
# be a noarch rpm.
if ($fields{ARCH} eq 'all') { $rpmarch='noarch' }
return "$rpmdir/$rpmarch/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.$rpmarch.rpm";
}
# Build a rpm file.
sub Build { my ($self,%fields)=@_;
# Debian's "all" architecture is a special case where we make noarch rpms.
my $buildarch;
if ($fields{ARCH} eq 'all') { $buildarch="--buildarch noarch" }
Alien::SafeSystem("rpm $buildarch -bb $ENV{RPMBUILDOPT} $fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",
"Error putting together the RPM package.\n");
}
# Install the passed rpm file.
sub Install { my ($self,$package)=shift;
Alien::SafeSystem("rpm -ivh $ENV{RPMINSTALLOPT} $package");
}
1

132
lib/Toslp.pm Normal file
View File

@@ -0,0 +1,132 @@
#!/usr/bin/perl
#
# Package for converting to stampede package format.
# Pull in details on the binary footer.
use Slp;
package To::slp;
use strict;
# Mangle the fields as necessary for a stampede package.
sub FixFields { my ($self,%fields)=@_;
# Mangle conffiles to the format they want.
$fields{CONFFILES}=~s/\n/:/g;
$fields{CONFFILES}=~s/:$//;
# Use priority optional for alien packages.
$fields{PRIORITY}=2;
# I always use bzip2 as the compression type.
$fields{COMPRESSTYPE}=0;
# Their version of release is a unsigned integer, so I need to
# convert anythnig more compilcated.
$fields{RELEASE}=int($fields{RELEASE});
# I don't try to guess copyright, just use unknown.
$fields{COPYRIGHT}=254;
# I don't try to fill these in with meaningful values.
$fields{CONFLICTS}="";
$fields{DEPENDS}="";
$fields{PROVIDES}="";
# TODO:
$fields{SETUPSTRIPT}=undef;
# Let's use the current date for this.
$fields{DATE}=`date`;
chomp $fields{DATE};
# Pick a compiler version.
if ($fields{ARCH} eq 'all') {
$fields{COMPILER}=253; # No compiler
}
else {
$fields{COMPILER}=252; # Unknown compiler
}
# Pick a binary format from the translation table.
$fields{BINFORMAT}=undef;
my $archnum;
foreach $archnum (keys %$slp::archtrans) {
if ($$slp::archtrans{$archnum} eq $fields{ARCH}) {
$fields{BINFORMAT} = $archnum;
last;
}
}
if ($fields{BINFORMAT} eq undef) {
Alien::Error("Stampede does not appear to support architecure $fields{ARCH} packages.");
}
# This is really the software category; use unknown.
$fields{GROUP}=252;
$fields{SLPKGVERSION}=$slp::footer_version;
return %fields;
}
# Do any necessary conversions on the file tree.
sub Convert { my ($self,$workdir,%fields)=@_;
}
# Passed the available info about the package in a hash, return the name of
# the slp package that will be made.
sub GetPackageName { my ($self,%fields)=@_;
return "$fields{NAME}-$fields{VERSION}.slp";
}
# Returns a slp footer in a scalar.
sub MakeFooter { my %fields=@_;
# We cannot use the actual $slp::footer_packstring, becuase it uses
# space terminated strings (A) instead of null terminated strings (a).
# This is good for decoding, but not for encoding.
$_=$slp::footer_packstring;
tr/A/a/;
return pack($_,(
$fields{CONFFILES},
$fields{PRIORITY},
$fields{COMPRESSTYPE},
$fields{RELEASE},
$fields{COPYRIGHT},
$fields{CONFLICTS},
$fields{SETUPSCRIPT},
$fields{SUMMARY},
$fields{DESCRIPTION},
$fields{DEPENDS},
$fields{PROVIDES},
$fields{AUTHOR},
$fields{DATE},
$fields{COMPILER},
$fields{VERSION},
$fields{NAME},
$fields{ARCH},
$fields{GROUP},
$fields{SLPKGVERSION},
));
}
# Build a slp file.
# This consists of first generating a .tar.bz2 file, and then appending the
# footer to it.
sub Build { my ($self,%fields)=@_;
# Note the -I is for making a .bzip2 file.
Alien::SafeSystem("tar cIf ../".$self->GetPackageName(%fields)." .");
# Now append the footer to that.
open (OUT,">>../".$self->GetPackageName(%fields)) ||
Alien::Error("Unable to append footer.");
print OUT MakeFooter(%fields);
close OUT;
}
# Install the passed slp file.
sub Install { my ($self,$package)=shift;
Alien::SafeSystem("slpi $package");
}
1

67
lib/Totgz.pm Normal file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/perl
#
# Package for converting to .tgz file.
package To::tgz;
use strict;
sub FixFields { my ($self,%fields)=@_;
# Nothing to do.
return %fields;
}
sub Convert { my ($self,$workdir,%fields)=@_;
if ($main::scripts) {
my $install_made=undef;
my %scripttrans=(
'doinst.sh' => 'POSTINST',
'delete.sh' => 'POSTRM',
'predelete.sh' => 'PRERM',
'predoinst.sh' => 'PREINST',
);
my $script;
foreach $script (keys(%scripttrans)) {
if ($fields{$scripttrans{$script}}) {
if (!$install_made) {
Alien::Status("Setting up scripts.");
mkdir "$fields{NAME}-$fields{VERSION}/install",0755
|| Alien::Error("Unable to make install directory");
$install_made=1;
}
open (OUT,">$workdir/install/$script") ||
Alien::Error("$workdir/install/$script: $!");;
print OUT $fields{$scripttrans{$script}};
close OUT;
chmod 0755,"$workdir/install/$script";
}
}
}
}
# Passed the available info about the package in a hash, return the name of
# the tgz package that will be made.
sub GetPackageName { my ($self,%fields)=@_;
return "$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.tgz";
}
# Build a tgz file.
sub Build { my ($self,%fields)=@_;
Alien::SafeSystem("tar czf ../".$self->GetPackageName(%fields)." .");
}
# Install the passed tgz file.
sub Install { my ($self,$package)=shift;
if (-x "/sbin/installpkg") {
Alien::SafeSystem("/sbin/installpkg $package");
}
else {
print STDERR "Sorry, I cannot install the generated .tgz file,\n";
print STDERR "\"$package\" because /sbin/installpkg is not\n";
print STDERR "present. You can use tar to install it yourself.\n";
exit 1; # otherwise alien will delete the package file on us.
}
}
1

4
lib/test Normal file
View File

@@ -0,0 +1,4 @@
use Alien;
use Fromslp;
%fields=From::slp::DecodeFooter(From::slp::GetFooter(shift));

1
lib/to-deb/rpm/conffiles Normal file
View File

@@ -0,0 +1 @@
#CONFFILES#

54
lib/to-deb/rpm/rules Executable file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/make -f
#
# This is a special rules files for handling alien or binary packages
# Christoph Lameter, October 30, 1996
package=#NAME#
debian/build:
$(checkdir)
touch debian/build
clean:
$(checkdir)
-rm -f debian/build
-rm -rf *~ debian/tmp debian/*~ debian/files*
binary-indep: checkroot debian/build
$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package. If there were any they would be
# made here.
binary-arch: checkroot debian/build
$(checkdir)
-rm -rf debian/tmp
# Install binary package
install -d debian/tmp
cp -a `ls | grep -v debian` debian/tmp
#
# If you need to move files around in debian/tmp or do some
# binary patching ... Insert it here
#
debstd
dpkg-gencontrol
dpkg --build debian/tmp ..
define checkdir
test -f debian/rules
endef
# Below here is fairly generic really
binary: binary-indep binary-arch
build: debian/build
source diff:
@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
checkroot:
$(checkdir)
test root = "`whoami`"
.PHONY: binary binary-arch binary-indep clean checkroot

9
lib/to-deb/slp/changelog Normal file
View File

@@ -0,0 +1,9 @@
#NAME# (#VERSION#-#RELEASE#) unstable; urgency=low
* Converted from Stampede .slp binary format to debian
-- #USERNAME# <#EMAIL#> #DATE#
Local variables:
mode: debian-changelog
End:

10
lib/to-deb/slp/control Normal file
View File

@@ -0,0 +1,10 @@
Source: #NAME#
Section: #SECTION#
Priority: extra
Maintainer: #USERNAME# <#EMAIL#>
Package: #NAME#
Architecture: #ARCH#
Depends: ${shlibs:Depends}
Description: #SUMMARY#
#DESCRIPTION#

4
lib/to-deb/slp/copyright Normal file
View File

@@ -0,0 +1,4 @@
This package was debianized by the alien program by converting
a Stampede linux Package on #DATE#.
Copyright: #COPYRIGHT#