[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

help please with perl module automatic installer

I'm still working with my attempt to automate building and installing perl
modules under Red Hat. I seriously want to be able to get this very, very

I've made progress. The current iteration seems to work correctly for at least
a few modules on at least Red Hat 6.0 with the (stock) 5.005_03 and with Red
Hat 6.1 with 5.005_63.

I really think I must be taking the wrong approach to attempting to compute
all the variables I need to set, and the values I need to set them to. I
wasn't able to find any way to compute both INSTALLSITELIB and INSTALLSITEARCH
correctly that worked for both settings; I ended up giving up and using the
last match in grep /site_perl/ @INC for both, which must be wrong, but seems
to work.

Is there any hash I can lay my hands on that has the desired values for these

My current version is attached. When one layer of quoting has been stripped
out by the here-doc interpolation, what's left (in the icky bit) looks
something like:

  d=$RPM_BUILD_ROOT`perl -le 'print ((sort grep{m#/site_perl/#} @INC)[-1])'`
  mkdir -p $d
       INSTALLMAN1DIR=$RPM_BUILD_ROOT/usr/man/man1 \
       INSTALLMAN3DIR=$RPM_BUILD_ROOT/usr/man/man3 \

  find $RPM_BUILD_ROOT -name perllocal.pod | perl -lne unlink

#!/usr/bin/perl -w
# perlmod2rpm 1.1 Bennett Todd <bet@mordor.net> Freely Redistributable
# 1.1 Worked with RH6.1+perl5.005_63 and RH6.0+perl5.005_03
# 1.0 Worked with RH6.1+perl5.005_63, had the latter wired in

=head1 NAME

    perlmod2rpm --- wrap, or re-wrap, a perl module in RPM clothing


    perlmod2rpm [-n] [-d] tarball-or-rpm [tarball-or-rpm ...]


B<perlmod2rpm> takes one or more perl modules and wraps them with rpm
dressing. It can be fed either the tar.gz file as downloaded from CPAN, or a
previously-wrapped rpm. It will ask the answers to any questions it can't
deduce, then write a spec file. Then it runs "rpm -ba" on the spec file unless
B<-n> is specified.

B<-d> enables a debugging dump of the variables right before it writes the
spec file.

=head1 PATHS

You _must_ place the tarballs, if any, in /usr/src/redhat/SOURCES/. The spec
files will be written in /usr/src/redhat/SPECS/.


use strict;
use IO::File;
use Term::ReadLine;
use File::Basename;
use Data::Dumper;
use Getopt::Std;
use Cwd;
use Fatal qw(IO::File::new close);
$0 = basename $0;

use vars qw($opt_n $opt_d);
$opt_n = $opt_d = 0;
die "syntax: $0 [-n] [-d] filename [...]\n" unless getopts('nd') and @ARGV;

my $oldcwd = cwd;
chdir '/usr/src/redhat/SOURCES/' or die;

my ($mday,$mon,$year,$wday) = (localtime(time))[3..6];
my @M = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my @D = qw(Sun Mon Tue Wed Thu Fri Sat);
$mon = $M[$mon];
$wday = $D[$wday];
$year += 1900;

my $th;

for (@ARGV) {
	$_ = "$oldcwd/$_" unless m#^/#;
	die "no such file $_" unless -f;
	my %d;
	if (/\.src\.rpm$/) {
		my $old = $_;
		($_) = grep { /\.tar\.gz$/ }
			`rpm2cpio $old|cpio -iuv \\*.tar.gz 2>&1`;
		die "cannot find src in $old" if $?;
		$d{summ} = `rpm -qp --queryformat '%{SUMMARY}' $old`;
		$d{desc} = `rpm -qp --queryformat '%{DESCRIPTION}' $old`;
		$d{rels} = `rpm -qp --queryformat '%{RELEASE}' $old`;
		$d{vers} = `rpm -qp --queryformat '%{VERSION}' $old`;
		$d{name} = `rpm -qp --queryformat '%{NAME}' $old`;
	die "$_: only feed me src rpms or tarballs" unless /\.tar\.gz$/;
	$d{vers} = $1 if s/-([^-]+)\.tar\.gz$// and !defined $d{vers};
	$d{name} = $_ unless defined $d{vers};
	($d{cpan}) = /^([^-]+)/;
	$d{summ} = "perl module $d{name}" unless defined $d{summ};
	$d{desc} = "perl module $d{name}" unless defined $d{desc};
	$d{rels} = 0 unless defined $d{rels};
	for (@d{qw(summ desc)}) { s/^\s+//; s/\s+$//; s/\s+/ /g; }
	print Data::Dumper->Dump([\%d], [qw(%d)]) if $opt_d;
	for (qw(name vers cpan)) {
		if (!defined($d{$_})) {
			$th = Term::ReadLine->new($0) unless defined $th;
			$d{$_} = $th->readline("$_: ");
Summary: $d{summ}
Name: $d{name}
Version: $d{vers}
Release: $d{rels}
Copyright: Freely Redistributable
Packager: Bennett Todd <bet\@mordor.net>
Group: Utilities/Text
Source: http://www.cpan.org/modules/by-module/$d{cpan}/$d{name}-$d{vers}.tar.gz
Requires: perl >= 5.004
BuildRoot: /var/tmp/$d{name}-rpmroot




perl Makefile.PL PREFIX=\$RPM_BUILD_ROOT/usr && make

d=\$RPM_BUILD_ROOT`perl -le 'print ((sort grep{m#/site_perl/#} \@INC)[-1])'`
mkdir -p \$d
     INSTALLMAN1DIR=\$RPM_BUILD_ROOT/usr/man/man1 \\
     INSTALLMAN3DIR=\$RPM_BUILD_ROOT/usr/man/man3 \\

find \$RPM_BUILD_ROOT -name perllocal.pod | perl -lne unlink


* $wday $mon $mday $year <bet\@mordor.net>
  - Initial Wrap
	system "rpm -ba /usr/src/redhat/SPECS/$d{name}.spec" and die unless $opt_n;

PGP signature

Follow-Ups from:
Andy Dougherty <doughera@lafayette.edu>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]