* Removed an obsolete note from the man page.

* Set locale to C while using rpm to pick at the .rpm file we are going to
     convert, Closes: #42282
   * Moved /usr/lib/alien to /usr/share/alien
   * Added --nopatch option, Closes: #47069
This commit is contained in:
joey
1999-11-18 21:43:35 +00:00
parent 0259be747e
commit 4f2f17d67a
8 changed files with 438 additions and 258 deletions

View File

@@ -15,12 +15,12 @@ install:
$$_="\tmy \$$version_string=\"$(VER)\";" if /VERSION_AUTOREPLACE/' alien \
> $(DESTDIR)/$(PREFIX)/bin/alien
chmod 755 $(DESTDIR)/$(PREFIX)/bin/alien
install -d $(DESTDIR)/$(PREFIX)/lib/alien/patches \
install -d $(DESTDIR)/$(PREFIX)/share/alien/patches \
$(DESTDIR)/var/lib/alien
cp -fr lib/* $(DESTDIR)/$(PREFIX)/lib/alien
cp -f patches/* $(DESTDIR)/$(PREFIX)/lib/alien/patches/
-rm -f $(DESTDIR)/$(PREFIX)/lib/alien/patches/*.gz
gzip -qf9 $(DESTDIR)/$(PREFIX)/lib/alien/patches/*
cp -fr lib/* $(DESTDIR)/$(PREFIX)/share/alien
cp -f patches/* $(DESTDIR)/$(PREFIX)/share/alien/patches/
-rm -f $(DESTDIR)/$(PREFIX)/share/alien/patches/*.gz
gzip -qf9 $(DESTDIR)/$(PREFIX)/share/alien/patches/*
install -d $(DESTDIR)/$(PREFIX)/share/man/man1
cp -f alien.1 $(DESTDIR)/$(PREFIX)/share/man/man1

4
TODO
View File

@@ -1 +1,5 @@
* handling postinst script when converting to/from .slp packages.
* alien needs to be reorganized somewhat, so it doesn't use any global
variables. The lib/ files are mostly ok, but should probably be regular OO
modules, and should be installed where regular perl modules are. Make it
-w safe, too.

384
alien
View File

@@ -1,220 +1,226 @@
#!/bin/sh
# Script to handle alien packages under Debian
#
# Options:
# -p<Patch> Manually specify a patch
# -n Install an alien package using heuristics
# -g Prepare directories for development
#!/usr/bin/perl
#
# Script to convert dpkg, rpm, tgz packages.
# Original author:
# Christoph Lameter, <clameter@debian.org> October 30, 1996
# The deb -> rpm conversion code was written by:
# Randoph Chung <rc42@cornell.edu>
# Current maintainer:
# Joey Hess <joeyh@master.debian.org>
#
# Copyright: GPL
set -e
use strict;
LIB=/usr/lib/alien
# Globals.
use vars qw($desttype $file $filetype $generate $install $workdir $libdir
$keep_version $scripts $tgzdescription $patchfile $nopatch $single
$prefix @patchdirs);
while expr "$1" : '-.*' >/dev/null; do
case $1 in
-n) NOPATCH=1
;;
-g) GENERATE=1
;;
-p*) PATCHFILE=`expr "$1" : '-p\(.*\)'`
if [ ! -f "$PATCHFILE" ]; then
echo "$PATCHFILE not found"
exit 1
fi
;;
*) echo "Bad option $1"
exit 1
;;
esac
shift
done
BEGIN {
$prefix="/usr"; # PREFIX_AUTOREPLACE done by Makefile, do not edit.
if [ "$NOPATCH" -a "$PATCHFILE" ]; then
echo "Cannot handle -n and -p options simultaneously"
exit 1
fi
# Directory where alien templates, etc, are stored.
$libdir="$prefix/share/alien";
push @INC, $libdir;
}
FILE=$1
# Directories where alien patches are stored.
@patchdirs=('/var/lib/alien',"$prefix/lib/alien/patches");
if [ "$FILE" = "" ]; then
echo "Usage: alien [-n] [-g] [-p<patchfile>] <filename>"
exit 1
fi
use Getopt::Long;
if [ ! -f $FILE ]; then
echo "File $FILE not found"
exit 1
fi
# 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;
DATE="`822-date`"
# Display alien's version number.
sub Version {
my $version_string='unknown'; # VERSION_AUTOREPLACE done by Makefile, do not edit.
print "Alien version $version_string\n";
}
# Cut off the directory name
if echo $FILE|grep -q "/"; then
X=`expr $FILE : '.*/\(.*\)'`
else
X="$FILE"
fi
# Display usage help.
sub Usage {
print <<eof;
Usage: alien [options ...] file [...]
file [...] Package file or files to convert.
-d, --to-deb Generate a Debian deb package. (default)
Enables the following options:
--patch=<patch> Specify patch file to use instead of automatically
looking for patch in /var/lib/alien.
--nopatch Do not use patches.
-r, --to-rpm Generate a RedHat rpm package.
-t, --to-tgz Generate a Slackware tgz package.
--to-slp Generate a Stampede .slp package.
-i, --install Install generated 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.
-k, --keep-version Do not change version of generated package.
--description=<desc> Specify package description.
-h, --help Display this help message.
-v, --version Display alien's version number.
if expr $X : '.*\.rpm' >/dev/null; then
RPM=1
if [ ! -f /etc/rpmrc ]; then
echo "RPM Package Manager not installed"
exit 1
fi
X=`expr $X : '\(.*\)\.rpm'`
else
case $X in
*.tgz) X=`expr $X : '\(.*\).tgz'` ;;
*.tar.gz) X=`expr $X : '\(.*\).tar.gz'` ;;
*) echo "Format of filename bad $FILE" ;;
esac
fi
eof
}
if [ "$NOPATCH" = "" ]; then
if [ "$PATCHFILE" = "" ]; then
PATCHFILE=/var/lib/alien/$X.diff.gz
fi
# Process parameters.
# Sets some global variables.
sub GetParams {
my ($todeb, $torpm, $totgz, $toslp, $help, $version);
if [ ! -f $PATCHFILE -a "$GENERATE" = "" ]; then
echo "Patchfile $PATCHFILE not found."
exit 1
fi
if [ ! -f $PATCHFILE ]; then
PATCHFILE=
fi
fi
# Get options.
my $ret=GetOptions(
"to-deb|d", \$todeb,
"to-rpm|r", \$torpm,
"to-tgz|t", \$totgz,
"to-slp", \$toslp,
"generate|g", \$generate,
"install|i", \$install,
"single|s", \$single,
"scripts|c", \$scripts,
"patch|p=s", \$patchfile,
"nopatch", \$nopatch,
"description=s", \$tgzdescription,
"keep-version|k", \$keep_version,
"help|h", \$help,
"version|v", \$version,
);
if [ "$RPM" ]; then
# Analyze the FILE name
PACKAGE=`expr $X : '\(.*\)-.*-.*\..*'`
VERSION=`expr $X : '.*-\(.*\)-.*\..*'`
DELTA=`expr $X : '.*-.*-\(.*\)\..*'`
ARCHIT=`expr $X : '.*-.*-.*\..\(.*\)'`
if (!$ret) {
Usage();
exit 1;
}
if [ "$DELTA" = "" -o "$VERSION" = "" -o "$PACKAGE" = "" ]; then
echo "Filename must have the form Package-Version-Release.Architecture.rpm"
exit 1
fi
if ($version) {
Version();
exit 1;
}
if [ "$ARCHIT" = "386" ]; then
ARCHIT=i386
fi
CDIR=rpm
else
# Generic handling for slackware and tar.gz packages
if echo $X | grep -q "-"; then
PACKAGE=`expr $X : '\(.*\)-.*'`
VERSION=`expr $X : '.*-\(.*\)'`
else
PACKAGE=$X
VERSION=1
fi
if ($help) {
Usage();
exit;
}
if [ "$VERSION" = "" -o "$PACKAGE" = "" ]; then
echo "Filename must have the form Package-Version.tgz"
exit 1
fi
if ($single) {
$generate=1;
}
ARCHIT=i386
DELTA=1
CDIR=tgz
fi
if ($todeb) {
$desttype='deb'
}
elsif ($torpm) {
$desttype='rpm';
}
elsif ($totgz) {
$desttype='tgz';
}
elsif ($toslp) {
$desttype='slp';
}
else {
$desttype='deb';
}
mkdir $PACKAGE-$VERSION
cd $PACKAGE-$VERSION
mkdir debian
# 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.");
}
echo "-- Unpacking $FILE"
if [ "$RPM" ]; then
(cd ..;rpm2cpio $FILE) | cpio --extract --make-directories --no-absolute-filenames
# install script could be located here.
else
# Must be a tar file
tar zxpf ../$FILE
# Make install script to postinst
if [ -e install/doinst.sh ]; then
mv install/doinst.sh debian/postinst
if ! rmdir install; then
echo "Other files besides doinst.sh present in install directory"
echo "Install script cannot be used as postinst script!"
mv debian/postinst install/doinst.sh
fi
fi
fi
if (!@ARGV) {
Usage();
Alien::Error("You must specify a file to convert.");
}
}
if [ "$GENERATE" ]; then
cd ..
cp -a $PACKAGE-$VERSION $PACKAGE-$VERSION.orig
echo "Directories $PACKAGE-$VERSION.orig + $PACKAGE-$VERSION prepared."
cd $PACKAGE-$VERSION
fi
# Check alien's working anvironment.
sub TestEnviron() {
if (! -w '.') {
Alien::Error("Cannot write to current directory. Try changing to /tmp and re-running alien.");
}
if ($> ne 0) {
if ($desttype eq 'deb' && ! $generate && ! $single) {
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.");
}
}
# Main program:
# Now lets patch it!
if [ "$PATCHFILE" ]; then
echo "-- Patching in $PATCHFILE"
zcat $PATCHFILE | patch -p1
X=`find . -name "*.rej"`
if [ "$X" ]; then
echo "Patch failed: giving up"
exit 1
fi
rm `find . -name "*.orig"`
else
echo "-- Automatic package debianization"
# Generate all the values we need
if [ "$EMAIL" = "" ]; then
EMAIL="$USER@`cat /etc/mailname`"
fi
USERNAME=`awk -F: -vUSER=$USER '$1 == USER { print $5; }' /etc/passwd`
# Initialization and data collection.
GetParams();
TestEnviron();
if [ "$USERNAME" = "" -a -x /usr/bin/ypmatch ]; then
# Give NIS a try
USERNAME=`ypmatch $USER passwd.byname|awk -F: '{ print $5; }'`
fi
foreach $file (@ARGV) {
if (! -f $file) {
Alien::Error("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");
if echo $USERNAME | grep -q "\,"; then
X=`expr index "$USERNAME" ","`
X=`expr $X - 1`
USERNAME=`expr substr "$USERNAME" 1 $X`
fi
# 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";
cd debian
X=`(cd $LIB/$CDIR;ls)`
for i in $X; do
sed <$LIB/$CDIR/$i >$i -e "s/#PACKAGE#/$PACKAGE/g" \
-e "s/#VERSION#/$VERSION/g" \
-e "s/#DELTA#/$DELTA/g" \
-e "s/#ARCHIT#/$ARCHIT/g" \
-e "s/#EMAIL#/$EMAIL/g" \
-e "s/#USERNAME#/$USERNAME/g" \
-e "s/#DATE#/$DATE/g"
done
my %fields=$dest->FixFields($src->GetFields($file));
if [ "$RPM" ]; then
(cd ../..;rpm -qpi $FILE) >>copyright
fi
# Unpack stage.
Alien::Status("Unpacking $file");
$workdir="$fields{NAME}-$fields{VERSION}";
Alien::SafeMkdir($workdir);
chdir $workdir;
$src->Unpack($file,$nopatch,%fields);
chdir "..";
cd ..
# Assume all files in etc are conffiles
if [ -d etc ]; then
find etc -type f -printf "/%p\n" >debian/conffiles
fi
fi
# Conversion stage.
$dest->Convert($workdir,$nopatch,%fields);
chmod a+x debian/rules
# 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;
}
if [ "$GENERATE" = "" ]; then
echo "-- Building the package $PACKAGE-$VERSION-$DELTA.deb"
debian/rules binary
cd ..
rm -rf $PACKAGE-$VERSION
echo "-- Installing generated .deb package"
dpkg -i $PACKAGE*.deb
rm $PACKAGE\_$VERSION-$DELTA*.deb
fi
echo "-- Successfully finished"
exit 0
# Install stage.
if ($install) {
my $packagename=$dest->GetPackageName(%fields);
Alien::Status("Installing generated $desttype package");
$dest->Install($packagename);
unlink $packagename;
}
}
Alien::Status("Successfully finished");

190
alien.1
View File

@@ -1,68 +1,164 @@
.TH alien 1L "Debian Utilities" "DEBIAN" \" -*- nroff -*-
.SH NAME
alien \- Install / Patch an alien binary package
alien \- Convert or install an alien binary package
.SH SYNOPSIS
\fBalien\fP [\fB\-n\fP] \fBalien-package-file\fP
\fBalien\fP [\fB--to-deb\fP] [\fB--patch=file\fP] [\fBoptions\fP] \fBfile\fP [\fB...\fP]
.br
\fBalien\fP \fB\-ppatch\fP \fBalien-package-file\fP
\fBalien\fP --to-rpm [\fBoptions\fP] \fBfile\fP [\fB...\fP]
.br
\fBalien\fP \fB\-g\fP [\fB\-ppatch\fP] \fBalien-package-file\fP
\fBalien\fP --to-tgz [\fBoptions\fP] \fBfile\fP [\fB...\fP]
.br
\fBalien\fP --to-slp [\fBoptions\fP] \fBfile\fP [\fB...\fP]
.SH DESCRIPTION
alien allows foreign packages to be installed under the debian package
manager.
.br
Commonly alien is simply called with a parameter giving the alien packagename
to be installed. A look up will then be done in
.B /var/lib/alien/packagename*.diff.gz .
If such a diff exists then the alien
package is unpacked, the patch is applied, a temporary .deb package
generated and finally installed. If there is no such diff then alien will
fail (unless the -n option is given).
To build Debian packages,
.I alien
is simply called with a parameter giving the
name of the alien package to be converted. A look up will then be done in
.B /var/lib/alien/packagename*.diff.gz
and then in
.B /usr/lib/alien/patches/packagename*.diff.gz .
If such a diff exists then the alien package is unpacked and the patch is
applied to debianize the package. If there is no such diff then
.I alien
will attempt to automatically debianize the package. After this, alien will
build the debian binary package, and it will be saved to the current
directory.
.PP
With the -n option the optimistic assumption is made that the alien package
will work without any changes under the Debian scheme of things. If things
break then you can simply uninstall the package using the debian package
manager.
.PP
With the -g option a package layout suitable for the development of patches
is created from the alien package. A directory packagename.orig and a
directory <packagename> is generated. Changes can be made to the packagename
directory and all commonly used tools for sourcepackages will work on the
packet. For example a .deb file can be generated using
.B debian/rules binary
and can then be installed in a regular way. Even
.B dpkg-buildpackage
will generate the usual files.
To build Red Hat packages, alien must be called with the --to-rpm parameter,
and the name of the alien package to be converted.
.I Alien
will then generate a spec file, and call rpm to build the package.
.PP
This tool probably needs to be run as superuser. Make sure that there is
enough room in the current directory since
.B alien
will build a debian package in that location.
.I alien
will build the package in that location.
.SH ALIEN PACKAGE FORMATS
alien supports the Red Hat .rpm format, Slackware .tgz formant and the
generic .tar.gz format. For the rpm format the Red Hat Package Manager must
be installed (See
.I Alien
can input and output packages in the Red Hat .rpm format, the Debian .deb
format, the Stampede .slp format, the Slackware .tgz format and the
generic .tar.gz format.
.PP
For converting from and to .rpm format the Red Hat Package Manager must be
installed (See
.B rpm (8)
).
.SH LIMITATIONS
Installation scripts for rpm packages are not supported.
.PP
You must specify a full path for the -p option.
For converting to (but not from) .deb format, the gcc, make, debmake, dpkg-dev,
and dpkg packages must be installed.
.PP
All files in /etc are assumed to be configuration files.
Note that for the .tar.gz format,
.I alien
will simply generate a .deb or .rpm package that has the same files in it as
are in the tar file. This only works well if the tar file has precompiled
binaries in it in a 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 directory when you install the package!
.SH OPTIONS
.TP
.I -n
Assume the alien package can be installed without any patches.
.I file [...]
The list of files to convert.
.TP
.I -g
Generate a source package suitable for patching and moving binaries around
.I -d, --to-deb
The output package will be a debian package. This is the default.
.TP
.I -ppatch
.I -r, --to-rpm
The output package will be a rpm package.
.TP
.I -t, --to-tgz
The output will be a slackware tgz package.
.TP
.I --to-slp
The output will be a stampede slp package.
.TP
.I -i, --install
Automatically install the output package, and remove the package file
after it has been installed.
.TP
.I -g, --generate
Generate a temporary directory suitable for building a package from, but do
not actually create the package. This is useful if you want to move files
around in the package before building it. The package can be built from this
temporary directory by running "debian/rules binary", if you were creating a
Debian package, or by running "rpm -bb <packagename>.spec" if you were
creating a Red Hat package.
.TP
.I -s, --single
Like -g, but do not generate the packagename.orig directory. This is only
useful when you are very low on disk space and are generating a debian
package.
.TP
.I --patch=patch
Specify the patch to be used instead of automatically looking the patch up
in
.B /var/lib/alien
.SS AUTHOR
Alien was written by Christoph Lameter <clameter@debian.org>
It is now being maintained by Joey Hess <joeyh@master.debian.org>
.B /var/lib/alien/ .
This is only allowed with --to-deb.
.TP
.I --nopatch
Do not use any patch files.
.TP
.I --description=desc
Specifiy a description for the package. This can only be used when
converting from slackware tgz packages, which lack descriptions. If it is
not used when converting from slackware tgz packages, a generic description
is used.
.TP
.I -c, --scripts
Try to convert the scripts that are meant to be run when the
package is installed and removed. Use this with caution, becuase these
scripts might be designed to work on a system unlike your own, and could
cause problems. It is reccommended that you examine the scripts by hand
and check to see what they do before using this option.
.TP
.I -k, --keep-version
By default, alien adds one to the minor version number. If this option
is given, alien will not do this.
.TP
.I -h, --help
Display a short usage summary.
.SH EXAMPLES
Here are some examples of the use of alien:
.TP
.I alien --to-deb package.rpm
Convert the package.rpm into a package.deb
.TP
.I alien --to-rpm package.deb
Convert the package.deb into a package.rpm
.TP
.I alien -i package.rpm
Convert the package.rpm into a package.deb (converting to a .deb package is
default, so you need not specify --to-deb), and install the generated
package.
.SH ENVIRONMENT
Alien recognizes the following environemnt variables:
.TP
.I RPMBUILDOPT
Options to pass to rpm when it is building a package.
.TP
.I RPMINSTALLOPT
Options to pass to rpm when it is installing a package.
.SH LIMITATIONS
When running alien on a tar file, all files in /etc in are assumed to be
configuration files.
.PP
Alien does not account for differences in configuration between different
linux distributions. So don't use it to replace something essential like
sysvinit. You could destroy your system by doing so. In general, if you
can't uninstall the package without breaking your system, don't try to
replace it with an alien version.
.PP
If alien is not run as root, the files in the generated package will have
incorrect owners and permissions.
.SH AUTHOR
Alien was written by Christoph Lameter.
.br
<clameter@debian.org>
.PP
Deb to rpm conversion code was taken from the Martian program by
Randolph Chung.
.br
<rc42@cornell.edu>
.PP
Alien has been extensively rewritten and is now maintained by Joey Hess.
.br
<joeyh@master.debian.org>

10
debian/changelog vendored
View File

@@ -1,3 +1,13 @@
alien (6.49) unstable; urgency=low
* Removed an obsolete note from the man page.
* Set locale to C while using rpm to pick at the .rpm file we are going to
convert, Closes: #42282
* Moved /usr/lib/alien to /usr/share/alien
* Added --nopatch option, Closes: #47069
-- Joey Hess <joeyh@master.debian.org> Thu, 18 Nov 1999 12:42:00 -0800
alien (6.48) unstable; urgency=low
* Patch from Benjamin Cant <ben@aegis.hands.com> to make it work even if

2
debian/control vendored
View File

@@ -2,7 +2,7 @@ Source: alien
Section: admin
Priority: extra
Maintainer: Joey Hess <joeyh@master.debian.org>
Standards-Version: 3.0.1.1
Standards-Version: 3.1.0.0
Package: alien
Architecture: all

View File

@@ -28,16 +28,20 @@ sub GetFields { my ($self,$file)=@_;
# These fields need no translation.
my $field;
foreach $field ('NAME','VERSION','RELEASE','ARCH','CHANGELOGTEXT','SUMMARY',
'DESCRIPTION', 'COPYRIGHT', 'DEFAULTPREFIX') {
'DESCRIPTION', 'COPYRIGHT', 'PREFIXES') {
$fieldtrans{$field}=$field;
}
# Use --queryformat to pull out all the fields we need.
foreach $field (keys(%fieldtrans)) {
$_=`rpm -qp $file --queryformat \%{$field}`;
$_=`LANG=C rpm -qp $file --queryformat \%{$field}`;
$fields{$fieldtrans{$field}}=$_ if $_ ne '(none)';
}
# DEFAULTPREFIX is special because it only exists in old versions of rpm.
$_=`rpm -qp $file --queryformat \%{PREFIXES} 2>/dev/null`;
$fields{PREFIXES}=$_ if $_ ne '' && $_ ne '(none)';
if ($main::scripts) {
# Fix up the scripts - they are always shell scripts, so make them so.
foreach $field ('PREINST','POSTINST','PRERM','POSTRM') {
@@ -46,13 +50,14 @@ sub GetFields { my ($self,$file)=@_;
}
# 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`;
# Get the filelist, it's used in the parent directory check in Unpack().
$fields{FILELIST}=`rpm -qpl $file`;
# Sanity check fields.
if (!$fields{SUMMARY}) {
# Older rpms will have no summary, but will have a
@@ -89,6 +94,17 @@ sub GetFields { my ($self,$file)=@_;
$fields{ARCH}='all';
}
# Treat 486, 586, etc, as 386.
if ($fields{ARCH}=~m/i\d86/) {
$fields{ARCH}='i386';
}
# Treat ppc as powerpc.
if ($fields{ARCH} eq 'ppc') {
$fields{ARCH} = 'powerpc';
}
if ($fields{RELEASE} eq undef || $fields{VERSION} eq undef|| !$fields{NAME}) {
Alien::Error("Error querying rpm file.");
}
@@ -103,26 +119,63 @@ sub GetFields { my ($self,$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.
# If the package is relocatable. We'd like to move it to be under the
# 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 PREFIXES directory already.
if ($fields{PREFIXES} ne undef && ! -e "./$fields{PREFIXES}") {
print "Moving unpacked files into $fields{PREFIXES}\n";
# Get the files to move.
my $filelist=join ' ',glob('*');
# Now, make the destination directory.
my $collect=undef;
foreach (split(m:/:,$fields{DEFAULTPREFIX})) {
foreach (split(m:/:,$fields{PREFIXES})) {
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}",
Alien::SafeSystem("mv $filelist ./$fields{PREFIXES}",
"Error moving unpacked files into the default prefix directory\n");
}
# When cpio extracts the file, any child directories that are present, but
# whose parent directories are not, end up mode 700. This next block corrects
# that to 755, which is more reasonable.
#
# Of course, this whole thing assumes we get the filelist in sorted order.
my $lastdir=undef;
foreach $file (split(/\n/,$fields{FILELIST})) {
$file=~s/^\///;
if (($lastdir && $file=~m:^\Q$lastdir\E/[^/]*$: eq undef) || !$lastdir) {
# We've found one of the nasty directories. Fix it up.
#
# Note that I strip the trailing filename off $file here, for two
# reasons. First, it makes the loop easier, we don't need to fix the
# perms on the last file, after all! Second, it makes the -d test below
# fire, which saves us from trying to fix a parent directory twice.
($file)=$file=~m:(.*)/.*?:;
my $dircollect=undef;
my $dir;
foreach $dir (split(/\//,$file)) {
$dircollect.="$dir/";
chmod 0755,$dircollect; # TADA!
}
}
if (-d "./$file") {
$lastdir=$file;
}
}
}
1

View File

@@ -14,6 +14,17 @@ sub FixFields { my ($self,%fields)=@_;
$fields{NAME} =~ tr/_/-/;
$fields{NAME} =~ s/[^a-z0-9-\.\+]//g;
# make sure the version contains digets.
if ($fields{VERSION} !~ m/[0-9]/) {
# drat. well, add some. dpkg-deb won't work
# on a version w/o numbers.
$fields{VERSION}.="0";
}
# same with revision.
if ($fields{RELEASE} !~ m/[0-9]/) {
$fields{RELEASE}.="-1";
}
# Fix up the description field to Debian standards (indented at
# least one space, no empty lines.)
my $description=undef;
@@ -36,7 +47,7 @@ sub FixFields { my ($self,%fields)=@_;
}
# Create debian/* files, either from a patch, or automatically.
sub Convert { my ($self,$workdir,%fields)=@_;
sub Convert { my ($self,$workdir,$nopatch,%fields)=@_;
if ($main::generate && !$main::single) {
Alien::SafeSystem("cp -fa $workdir $workdir.orig", "Error creating $workdir.orig");
}
@@ -46,7 +57,7 @@ sub Convert { my ($self,$workdir,%fields)=@_;
|| Alien::Error("Unable to make debian directory");
my $patchfile=$main::patchfile;
$patchfile=Alien::GetPatch($fields{NAME},$fields{VERSION},$fields{RELEASE}) if !$patchfile;
if ($patchfile) {
if ($patchfile && ! $nopatch) {
Alien::Patch($patchfile,$workdir);
}
else {
@@ -87,7 +98,7 @@ sub AutoDebianize { my ($self,$workdir,%fields)=@_;
foreach $script ('postinst','postrm','preinst','prerm') {
if ($fields{uc($script)}) {
open (OUT,">$workdir/debian/$script") ||
Alien::Error("$workdir/debian/$script: $!");;
Alien::Error("$workdir/debian/$script: $!");
print OUT $fields{uc($script)};
close OUT;
}