rewritten (and untested)

This commit is contained in:
joey
2000-04-21 23:24:47 +00:00
parent 9487c7a173
commit 00d7b76356

284
alien
View File

@@ -1,4 +1,4 @@
#!/usr/bin/perl #!/usr/bin/perl -w
=head1 NAME =head1 NAME
@@ -46,8 +46,8 @@ dpkg-dev, and dpkg packages must be installed.
=item tgz =item tgz
Note that when converting from the tgz format, B<alien> will simply generate an Note that when converting from the tgz format, B<alien> will simply generate an
output package that has the same files in it as are in the tar file. This output package that has the same files in it as are in the tgz file. This
only works well if the tar file has precompiled binaries in it in a only works well if the tgz file has precompiled binaries in it in a
standard linux directory tree. Do NOT run alien on tar files with source standard linux directory tree. Do NOT run alien on tar files with source
code in them, unless you want this source code to be installed in your root code in them, unless you want this source code to be installed in your root
directory when you install the package! directory when you install the package!
@@ -191,11 +191,11 @@ incorrect owners and permissions.
Alien was written by Christoph Lameter, B<<clameter@debian.org>>. Alien was written by Christoph Lameter, B<<clameter@debian.org>>.
Deb to rpm conversion code was taken from the Martian program by deb to rpm conversion code was taken from the Martian program by
Randolph Chung, B<<rc42@cornell.edu>>. Randolph Chung, B<<tausq@debian.org>>.
Alien has been extensively rewritten (3 times) and is now maintained by Joey Hess Alien has been extensively rewritten (3 times) and is now maintained by
B<<joeyh@debian.org>>. Joey Hess, B<<joeyh@debian.org>>.
=head1 COPYRIGHT =head1 COPYRIGHT
@@ -205,216 +205,152 @@ License.
=cut =cut
use strict; use strict;
use Getopt::Long;
use Alien::Package::Deb;
use Alien::Package::Rpm;
use Alien::Package::Tgz;
use Alien::Package::Slp;
# Globals. # Returns a list of directories to search for patches.
use vars qw($desttype $file $filetype $generate $install $workdir $libdir sub patchdirs {
$keep_version $scripts $tgzdescription $patchfile $nopatch $single my $prefix="/usr"; # PREFIX_AUTOREPLACE done by Makefile, do not edit.
$prefix @patchdirs); return '/var/lib/alien',"$prefix/lib/alien/patches";
BEGIN {
$prefix="/usr"; # PREFIX_AUTOREPLACE done by Makefile, do not edit.
# Directory where alien templates, etc, are stored.
$libdir="$prefix/share/alien";
push @INC, $libdir;
} }
# Directories where alien patches are stored.
@patchdirs=('/var/lib/alien',"$prefix/lib/alien/patches");
use Getopt::Long;
# Load up all of alien's modules.
use Alien;
use Fromrpm;
use Fromdeb;
use Fromtgz;
use Fromslp;
use Torpm;
use Todeb;
use Totgz;
use Toslp;
# Display alien's version number. # Display alien's version number.
sub Version { sub version {
my $version_string='unknown'; # VERSION_AUTOREPLACE done by Makefile, do not edit. my $version_string='unknown'; # VERSION_AUTOREPLACE done by Makefile, do not edit.
print "Alien version $version_string\n"; print "Alien version $version_string\n";
exit;
} }
# Display usage help. # Display usage help.
sub Usage { sub usage {
print <<eof; print STDERR <<EOF;
Usage: alien [options ...] file [...] Usage: alien [options] file [...]
file [...] Package file or files to convert. file [...] Package file or files to convert.
-d, --to-deb Generate a Debian deb package. (default) -d, --to-deb Generate a Debian deb package (default).
Enables the following options: Enables the following options:
--patch=<patch> Specify patch file to use instead of automatically --patch=<patch> Specify patch file to use instead of automatically
looking for patch in /var/lib/alien. looking for patch in /var/lib/alien.
--nopatch Do not use patches. --nopatch Do not use patches.
--single Like --generate, but do not create .orig
directory.
-r, --to-rpm Generate a RedHat rpm package. -r, --to-rpm Generate a RedHat rpm package.
--to-slp Generate a Stampede slp package.
-t, --to-tgz Generate a Slackware tgz package. -t, --to-tgz Generate a Slackware tgz package.
--to-slp Generate a Stampede .slp package. Enables the following options:
--description=<desc> Specify package description.
-i, --install Install generated package. -i, --install Install generated package.
-g, --generate Unpack, but do not generate a new package. -g, --generate Unpack, but do not generate a new package.
-s, --single Like --generate, but do not create .orig directory.
-c, --scripts Include scripts in package. -c, --scripts Include scripts in package.
-k, --keep-version Do not change version of generated package. -k, --keep-version Do not change version of generated package.
--description=<desc> Specify package description.
-h, --help Display this help message. -h, --help Display this help message.
-v, --version Display alien's version number. -v, --version Display alien's version number.
eof EOF
exit 1;
} }
# Process parameters. # Start by processing the parameters.
# Sets some global variables. my (%destformats, $generate, $install, $single, $scripts, $patchfile,
sub GetParams { $nopatch, $tgzdescription, $keepversion);
my ($todeb, $torpm, $totgz, $toslp, $help, $version);
# Get options. GetOptions(
my $ret=GetOptions( "to-deb|d", sub { $destformats{deb}=1 },
"to-deb|d", \$todeb, "to-rpm|r", sub { $destformats{rpm}=1 },
"to-rpm|r", \$torpm, "to-tgz|t", sub { $destformats{tgz}=1 },
"to-tgz|t", \$totgz, "to-slp", sub { $destformats{slp}=1 },
"to-slp", \$toslp,
"generate|g", \$generate, "generate|g", \$generate,
"install|i", \$install, "install|i", \$install,
"single|s", \$single, "single|s", sub { $single=1; $generate =1 },
"scripts|c", \$scripts, "scripts|c", \$scripts,
"patch|p=s", \$patchfile, "patch|p=s", \$patchfile,
"nopatch", \$nopatch, "nopatch", \$nopatch,
"description=s", \$tgzdescription, "description=s", \$tgzdescription,
"keep-version|k", \$keep_version, "keep-version|k", \$keepversion,
"help|h", \$help, "help|h", \&usage,
"version|v", \$version, "version|v", \&version,
); ) || usage();
if (!$ret) { # Default to deb conversion.
Usage(); if (! %destformats) {
exit 1; $destformats{deb}=1;
} }
if ($version) { # A few sanity checks.
Version(); if ($patchfile && ! -f $patchfile) {
exit 1; die "Specified patch file, \"$patchfile\" cannot be found.\n";
} }
if ($patchfile && $nopatch) {
if ($help) { die "The options --nopatch and --patchfile cannot be used together.\n";
Usage(); }
exit; unless (@ARGV) {
} print STDERR "You must specify a file to convert.\n\n";
usage();
if ($single) {
$generate=1;
}
if ($todeb) {
$desttype='deb'
}
elsif ($torpm) {
$desttype='rpm';
}
elsif ($totgz) {
$desttype='tgz';
}
elsif ($toslp) {
$desttype='slp';
}
else {
$desttype='deb';
}
# Sanity check options.
if ($desttype ne 'deb' && $patchfile) {
Usage();
Alien::Error("You can not use --patch with --to-rpm or --to-tgz or --to-slp");
}
if (($generate || $single) && $install) {
Usage();
Alien::Error("You can not use --generate or --single with --install");
}
if ($patchfile && ! -f $patchfile) {
Alien::Error("Specified patch file, \"$patchfile\" was not be found.");
}
if ($patchfile && $nopatch) {
Alien::Error("The options --nopatch and --patchfile cannot be used together.");
}
if (!@ARGV) {
Usage();
Alien::Error("You must specify a file to convert.");
}
} }
# Check alien's working anvironment. # Check alien's working anvironment.
sub TestEnviron() { if (! -w '.') {
if (! -w '.') { die("Cannot write to current directory. Try changing to /tmp and re-running alien.\n");
Alien::Error("Cannot write to current directory. Try changing to /tmp and re-running alien."); }
} if ($> ne 0) {
if ($> ne 0) { if ($destformats{deb} && ! $generate && ! $single) {
if ($desttype eq 'deb' && ! $generate && ! $single) { die "Must run as root to convert to .deb format (or you may use fakeroot).\n";
Alien::Error("Must run as root to convert to .deb format (or you may use fakeroot).");
}
Alien::Warning("Warning: alien is not running as root!");
Alien::Warning("Ownerships of files in the generated packages will");
Alien::Warning("probably be messed up.");
} }
print STDERR "Warning: alien is not running as root!\n";
print STDERR "Ownerships of files in the generated packages will\n";
print STDERR "probably be messed up.\n";
} }
# Main program: foreach my $file (@ARGV) {
# Initialization and data collection.
GetParams();
TestEnviron();
foreach $file (@ARGV) {
if (! -f $file) { if (! -f $file) {
Alien::Error("File $file not found.\n"); die "File \"$file\" not found.\n";
}
$filetype=Alien::FileType($file);
if ($filetype eq $desttype) {
Alien::Error("There is no point in converting a $filetype into a $desttype.");
}
Alien::Status("Examining $file");
# These variables are set to let us refer to the proper packages
# to process the source and destination file types.
my $dest="To::$desttype";
my $src="From::$filetype";
my %fields=$dest->FixFields($src->GetFields($file));
# Unpack stage.
Alien::Status("Unpacking $file");
$workdir="$fields{NAME}-$fields{VERSION}";
Alien::SafeMkdir($workdir);
chdir $workdir;
$src->Unpack($file,%fields);
chdir "..";
# Conversion stage.
$dest->Convert($workdir,$nopatch,%fields);
# Build stage.
if (!$generate) {
my $packagename=$dest->GetPackageName(%fields);
Alien::Status("Building the package $packagename");
chdir $workdir;
$dest->Build(%fields);
chdir "..";
Alien::SafeSystem("rm -rf $workdir");
# The above "building $packagename..." message can get lost in the
# noise, so tell them again where the package ended up.
print "\nGeneration of $packagename complete.\n" if !$install;
} }
# Install stage. # Figure out what kind of file this is.
my $package;
if (Alien::Package::Rpm->checkfile($file)) {
$package=Alien::Package::Rpm->new(filename => $file);
}
elsif (Alien::Package::Deb->checkfile($file)) {
$package=Alien::Package::Deb->new(filename => $file);
}
elsif (Alien::Package::Tgz->checkfile($file)) {
$package=Alien::Package::Tgz->new(filename => $file);
}
elsif (Alien::Package::Slp->checkfile($file)) {
$package=Alien::Package::Slp->new(filename => $file);
}
else {
die "Unknown type of package, $file.\n";
}
foreach my $format (keys %destformats) {
# Skip conversion if package is already the correct format.
if ($package->origformat ne $format) {
# Only unpack once.
$package->unpack unless $package->unpacked_tree;
# Mutate package into desired format.
bless($package, "Alien::Package::".ucfirst($format));
$package->prep;
my $newfile=$package->build;
if ($install) { if ($install) {
my $packagename=$dest->GetPackageName(%fields); $package->install($newfile);
Alien::Status("Installing generated $desttype package"); unlink $newfile;
$dest->Install($packagename); }
unlink $packagename; else {
# Tell them where the package ended up.
print "$newfile generated\n";
}
}
elsif ($install) {
# Don't convert the package, but do install it.
$package->install($file);
# Note I don't unlink it. I figure that might annoy
# people, since it was an input file.
}
} }
} }
Alien::Status("Successfully finished");