* 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 \ $$_="\tmy \$$version_string=\"$(VER)\";" if /VERSION_AUTOREPLACE/' alien \
> $(DESTDIR)/$(PREFIX)/bin/alien > $(DESTDIR)/$(PREFIX)/bin/alien
chmod 755 $(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 $(DESTDIR)/var/lib/alien
cp -fr lib/* $(DESTDIR)/$(PREFIX)/lib/alien cp -fr lib/* $(DESTDIR)/$(PREFIX)/share/alien
cp -f patches/* $(DESTDIR)/$(PREFIX)/lib/alien/patches/ cp -f patches/* $(DESTDIR)/$(PREFIX)/share/alien/patches/
-rm -f $(DESTDIR)/$(PREFIX)/lib/alien/patches/*.gz -rm -f $(DESTDIR)/$(PREFIX)/share/alien/patches/*.gz
gzip -qf9 $(DESTDIR)/$(PREFIX)/lib/alien/patches/* gzip -qf9 $(DESTDIR)/$(PREFIX)/share/alien/patches/*
install -d $(DESTDIR)/$(PREFIX)/share/man/man1 install -d $(DESTDIR)/$(PREFIX)/share/man/man1
cp -f alien.1 $(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. * 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 #!/usr/bin/perl
# Script to handle alien packages under Debian
# #
# Options: # Script to convert dpkg, rpm, tgz packages.
# -p<Patch> Manually specify a patch # Original author:
# -n Install an alien package using heuristics # Christoph Lameter, <clameter@debian.org> October 30, 1996
# -g Prepare directories for development # The deb -> rpm conversion code was written by:
# Randoph Chung <rc42@cornell.edu>
# Current maintainer:
# Joey Hess <joeyh@master.debian.org>
# #
# Christoph Lameter, <clameter@debian.org> October 30, 1996 # 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 BEGIN {
case $1 in $prefix="/usr"; # PREFIX_AUTOREPLACE done by Makefile, do not edit.
-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
if [ "$NOPATCH" -a "$PATCHFILE" ]; then # Directory where alien templates, etc, are stored.
echo "Cannot handle -n and -p options simultaneously" $libdir="$prefix/share/alien";
exit 1 push @INC, $libdir;
fi }
FILE=$1 # Directories where alien patches are stored.
@patchdirs=('/var/lib/alien',"$prefix/lib/alien/patches");
if [ "$FILE" = "" ]; then use Getopt::Long;
echo "Usage: alien [-n] [-g] [-p<patchfile>] <filename>"
exit 1
fi
if [ ! -f $FILE ]; then # Load up all of alien's modules.
echo "File $FILE not found" use Alien;
exit 1 use Fromrpm;
fi 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 # Display usage help.
if echo $FILE|grep -q "/"; then sub Usage {
X=`expr $FILE : '.*/\(.*\)'` print <<eof;
else Usage: alien [options ...] file [...]
X="$FILE" file [...] Package file or files to convert.
fi -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 eof
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
if [ "$NOPATCH" = "" ]; then # Process parameters.
if [ "$PATCHFILE" = "" ]; then # Sets some global variables.
PATCHFILE=/var/lib/alien/$X.diff.gz sub GetParams {
fi my ($todeb, $torpm, $totgz, $toslp, $help, $version);
if [ ! -f $PATCHFILE -a "$GENERATE" = "" ]; then # Get options.
echo "Patchfile $PATCHFILE not found." my $ret=GetOptions(
exit 1 "to-deb|d", \$todeb,
fi "to-rpm|r", \$torpm,
if [ ! -f $PATCHFILE ]; then "to-tgz|t", \$totgz,
PATCHFILE= "to-slp", \$toslp,
fi "generate|g", \$generate,
fi "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 if (!$ret) {
# Analyze the FILE name Usage();
PACKAGE=`expr $X : '\(.*\)-.*-.*\..*'` exit 1;
VERSION=`expr $X : '.*-\(.*\)-.*\..*'` }
DELTA=`expr $X : '.*-.*-\(.*\)\..*'`
ARCHIT=`expr $X : '.*-.*-.*\..\(.*\)'`
if [ "$DELTA" = "" -o "$VERSION" = "" -o "$PACKAGE" = "" ]; then if ($version) {
echo "Filename must have the form Package-Version-Release.Architecture.rpm" Version();
exit 1 exit 1;
fi }
if [ "$ARCHIT" = "386" ]; then if ($help) {
ARCHIT=i386 Usage();
fi exit;
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 [ "$VERSION" = "" -o "$PACKAGE" = "" ]; then if ($single) {
echo "Filename must have the form Package-Version.tgz" $generate=1;
exit 1 }
fi
ARCHIT=i386 if ($todeb) {
DELTA=1 $desttype='deb'
CDIR=tgz }
fi elsif ($torpm) {
$desttype='rpm';
}
elsif ($totgz) {
$desttype='tgz';
}
elsif ($toslp) {
$desttype='slp';
}
else {
$desttype='deb';
}
mkdir $PACKAGE-$VERSION # Sanity check options.
cd $PACKAGE-$VERSION if ($desttype ne 'deb' && $patchfile) {
mkdir debian 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 (!@ARGV) {
if [ "$RPM" ]; then Usage();
(cd ..;rpm2cpio $FILE) | cpio --extract --make-directories --no-absolute-filenames Alien::Error("You must specify a file to convert.");
# 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 [ "$GENERATE" ]; then # Check alien's working anvironment.
cd .. sub TestEnviron() {
cp -a $PACKAGE-$VERSION $PACKAGE-$VERSION.orig if (! -w '.') {
echo "Directories $PACKAGE-$VERSION.orig + $PACKAGE-$VERSION prepared." Alien::Error("Cannot write to current directory. Try changing to /tmp and re-running alien.");
cd $PACKAGE-$VERSION }
fi 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! # Initialization and data collection.
if [ "$PATCHFILE" ]; then GetParams();
echo "-- Patching in $PATCHFILE" TestEnviron();
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`
if [ "$USERNAME" = "" -a -x /usr/bin/ypmatch ]; then foreach $file (@ARGV) {
# Give NIS a try if (! -f $file) {
USERNAME=`ypmatch $USER passwd.byname|awk -F: '{ print $5; }'` Alien::Error("File $file not found.\n");
fi }
$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 # These variables are set to let us refer to the proper packages
X=`expr index "$USERNAME" ","` # to process the source and destination file types.
X=`expr $X - 1` my $dest="To::$desttype";
USERNAME=`expr substr "$USERNAME" 1 $X` my $src="From::$filetype";
fi
cd debian my %fields=$dest->FixFields($src->GetFields($file));
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
if [ "$RPM" ]; then # Unpack stage.
(cd ../..;rpm -qpi $FILE) >>copyright Alien::Status("Unpacking $file");
fi $workdir="$fields{NAME}-$fields{VERSION}";
Alien::SafeMkdir($workdir);
chdir $workdir;
$src->Unpack($file,$nopatch,%fields);
chdir "..";
cd .. # Conversion stage.
# Assume all files in etc are conffiles $dest->Convert($workdir,$nopatch,%fields);
if [ -d etc ]; then
find etc -type f -printf "/%p\n" >debian/conffiles
fi
fi
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 # Install stage.
echo "-- Building the package $PACKAGE-$VERSION-$DELTA.deb" if ($install) {
debian/rules binary my $packagename=$dest->GetPackageName(%fields);
cd .. Alien::Status("Installing generated $desttype package");
rm -rf $PACKAGE-$VERSION $dest->Install($packagename);
echo "-- Installing generated .deb package" unlink $packagename;
dpkg -i $PACKAGE*.deb }
rm $PACKAGE\_$VERSION-$DELTA*.deb }
fi
echo "-- Successfully finished" Alien::Status("Successfully finished");
exit 0

192
alien.1
View File

@@ -1,68 +1,164 @@
.TH alien 1L "Debian Utilities" "DEBIAN" \" -*- nroff -*- .TH alien 1L "Debian Utilities" "DEBIAN" \" -*- nroff -*-
.SH NAME .SH NAME
alien \- Install / Patch an alien binary package alien \- Convert or install an alien binary package
.SH SYNOPSIS .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 .br
\fBalien\fP \fB\-ppatch\fP \fBalien-package-file\fP \fBalien\fP --to-rpm [\fBoptions\fP] \fBfile\fP [\fB...\fP]
.br .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 .SH DESCRIPTION
alien allows foreign packages to be installed under the debian package To build Debian packages,
manager. .I alien
.br is simply called with a parameter giving the
Commonly alien is simply called with a parameter giving the alien packagename name of the alien package to be converted. A look up will then be done in
to be installed. A look up will then be done in .B /var/lib/alien/packagename*.diff.gz
.B /var/lib/alien/packagename*.diff.gz . and then in
If such a diff exists then the alien .B /usr/lib/alien/patches/packagename*.diff.gz .
package is unpacked, the patch is applied, a temporary .deb package If such a diff exists then the alien package is unpacked and the patch is
generated and finally installed. If there is no such diff then alien will applied to debianize the package. If there is no such diff then
fail (unless the -n option is given). .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 .PP
With the -n option the optimistic assumption is made that the alien package To build Red Hat packages, alien must be called with the --to-rpm parameter,
will work without any changes under the Debian scheme of things. If things and the name of the alien package to be converted.
break then you can simply uninstall the package using the debian package .I Alien
manager. will then generate a spec file, and call rpm to build the package.
.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.
.PP .PP
This tool probably needs to be run as superuser. Make sure that there is This tool probably needs to be run as superuser. Make sure that there is
enough room in the current directory since enough room in the current directory since
.B alien .I alien
will build a debian package in that location. will build the package in that location.
.SH ALIEN PACKAGE FORMATS .SH ALIEN PACKAGE FORMATS
alien supports the Red Hat .rpm format, Slackware .tgz formant and the .I Alien
generic .tar.gz format. For the rpm format the Red Hat Package Manager must can input and output packages in the Red Hat .rpm format, the Debian .deb
be installed (See format, the Stampede .slp format, the Slackware .tgz format and the
.B rpm(8) 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 .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 .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 .SH OPTIONS
.TP .TP
.I -n .I file [...]
Assume the alien package can be installed without any patches. The list of files to convert.
.TP .TP
.I -g .I -d, --to-deb
Generate a source package suitable for patching and moving binaries around The output package will be a debian package. This is the default.
.TP .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 Specify the patch to be used instead of automatically looking the patch up
in in
.B /var/lib/alien .B /var/lib/alien/ .
This is only allowed with --to-deb.
.SS AUTHOR .TP
Alien was written by Christoph Lameter <clameter@debian.org> .I --nopatch
It is now being maintained by Joey Hess <joeyh@master.debian.org> 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 alien (6.48) unstable; urgency=low
* Patch from Benjamin Cant <ben@aegis.hands.com> to make it work even if * 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 Section: admin
Priority: extra Priority: extra
Maintainer: Joey Hess <joeyh@master.debian.org> Maintainer: Joey Hess <joeyh@master.debian.org>
Standards-Version: 3.0.1.1 Standards-Version: 3.1.0.0
Package: alien Package: alien
Architecture: all Architecture: all

View File

@@ -28,16 +28,20 @@ sub GetFields { my ($self,$file)=@_;
# These fields need no translation. # These fields need no translation.
my $field; my $field;
foreach $field ('NAME','VERSION','RELEASE','ARCH','CHANGELOGTEXT','SUMMARY', foreach $field ('NAME','VERSION','RELEASE','ARCH','CHANGELOGTEXT','SUMMARY',
'DESCRIPTION', 'COPYRIGHT', 'DEFAULTPREFIX') { 'DESCRIPTION', 'COPYRIGHT', 'PREFIXES') {
$fieldtrans{$field}=$field; $fieldtrans{$field}=$field;
} }
# Use --queryformat to pull out all the fields we need. # Use --queryformat to pull out all the fields we need.
foreach $field (keys(%fieldtrans)) { foreach $field (keys(%fieldtrans)) {
$_=`rpm -qp $file --queryformat \%{$field}`; $_=`LANG=C rpm -qp $file --queryformat \%{$field}`;
$fields{$fieldtrans{$field}}=$_ if $_ ne '(none)'; $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) { if ($main::scripts) {
# Fix up the scripts - they are always shell scripts, so make them so. # Fix up the scripts - they are always shell scripts, so make them so.
foreach $field ('PREINST','POSTINST','PRERM','POSTRM') { foreach $field ('PREINST','POSTINST','PRERM','POSTRM') {
@@ -46,13 +50,14 @@ sub GetFields { my ($self,$file)=@_;
} }
# Get the conffiles list. # 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`; $fields{CONFFILES}=`rpm -qcp $file`;
# Include the output of rpm -qi in the copyright file. # Include the output of rpm -qi in the copyright file.
$fields{COPYRIGHT_EXTRA}=`rpm -qpi $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. # Sanity check fields.
if (!$fields{SUMMARY}) { if (!$fields{SUMMARY}) {
# Older rpms will have no summary, but will have a # Older rpms will have no summary, but will have a
@@ -89,6 +94,17 @@ sub GetFields { my ($self,$file)=@_;
$fields{ARCH}='all'; $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}) { if ($fields{RELEASE} eq undef || $fields{VERSION} eq undef|| !$fields{NAME}) {
Alien::Error("Error querying rpm file."); Alien::Error("Error querying rpm file.");
} }
@@ -103,26 +119,63 @@ sub GetFields { my ($self,$file)=@_;
sub Unpack { my ($self,$file,%fields)=@_; sub Unpack { my ($self,$file,%fields)=@_;
Alien::SafeSystem("(cd ..;rpm2cpio $file) | cpio --extract --make-directories --no-absolute-filenames --preserve-modification-time", Alien::SafeSystem("(cd ..;rpm2cpio $file) | cpio --extract --make-directories --no-absolute-filenames --preserve-modification-time",
"Error unpacking $file\n"); "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. # If the package is relocatable. We'd like to move it to be under the
# First, get a list of files to move. # 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('*'); my $filelist=join ' ',glob('*');
# Now, make the destination directory. # Now, make the destination directory.
my $collect=undef; 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. if ($_ ne undef) { # this keeps us from using anything but relative paths.
$collect.="$_/"; $collect.="$_/";
mkdir $collect,0755 || Alien::Error("Unable to make directory: $collect: $!"); mkdir $collect,0755 || Alien::Error("Unable to make directory: $collect: $!");
} }
} }
# Now move all files in the package to the directory we made. # 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"); "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 1

View File

@@ -14,6 +14,17 @@ sub FixFields { my ($self,%fields)=@_;
$fields{NAME} =~ tr/_/-/; $fields{NAME} =~ tr/_/-/;
$fields{NAME} =~ s/[^a-z0-9-\.\+]//g; $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 # Fix up the description field to Debian standards (indented at
# least one space, no empty lines.) # least one space, no empty lines.)
my $description=undef; my $description=undef;
@@ -36,7 +47,7 @@ sub FixFields { my ($self,%fields)=@_;
} }
# Create debian/* files, either from a patch, or automatically. # 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) { if ($main::generate && !$main::single) {
Alien::SafeSystem("cp -fa $workdir $workdir.orig", "Error creating $workdir.orig"); 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"); || Alien::Error("Unable to make debian directory");
my $patchfile=$main::patchfile; my $patchfile=$main::patchfile;
$patchfile=Alien::GetPatch($fields{NAME},$fields{VERSION},$fields{RELEASE}) if !$patchfile; $patchfile=Alien::GetPatch($fields{NAME},$fields{VERSION},$fields{RELEASE}) if !$patchfile;
if ($patchfile) { if ($patchfile && ! $nopatch) {
Alien::Patch($patchfile,$workdir); Alien::Patch($patchfile,$workdir);
} }
else { else {
@@ -87,7 +98,7 @@ sub AutoDebianize { my ($self,$workdir,%fields)=@_;
foreach $script ('postinst','postrm','preinst','prerm') { foreach $script ('postinst','postrm','preinst','prerm') {
if ($fields{uc($script)}) { if ($fields{uc($script)}) {
open (OUT,">$workdir/debian/$script") || open (OUT,">$workdir/debian/$script") ||
Alien::Error("$workdir/debian/$script: $!");; Alien::Error("$workdir/debian/$script: $!");
print OUT $fields{uc($script)}; print OUT $fields{uc($script)};
close OUT; close OUT;
} }