1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#!/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}=
"set -e\n".
"mkdir /tmp/alien.\$\$\n".
qq{perl -pe '\$_=unpack("u",\$_)' << '__EOF__' > /tmp/alien.\$\$/script\n}.
pack("u",$fields{$field}).
"__EOF__\n".
"chmod 755 /tmp/alien.\$\$/script\n".
"/tmp/alien.\$\$/script \"\$@\"\n".
"rm -f /tmp/alien.\$\$/script\n".
"rmdir /tmp/alien.\$\$";
}
}
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
if (grep(m:^\Q$fn\E$:,@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)=@_;
Alien::SafeSystem("rpm -ivh $ENV{RPMINSTALLOPT} $package");
}
1
|