Perl 5.8.8 in Ubuntu 6.06

Paul Seamons paul at seamons.com
Mon Mar 19 15:17:42 MDT 2007


CPAN.pm is nice in that it handles dependencies for you.  It is awful that it 
would ever try to upgrade Perl.  You must be trying to install some bleeding 
edge stuff for it to try and upgrade your Perl.

On any ubuntu/debian based servers that I handle, I use cpan2deb by Simon 
Cozens.  I have included it below with some changes that make it work better 
on ubuntu.  That way - all third party modules that 
didn't come from your repositories is still installed by package.  It makes 
installing huge things with thousands of dependencies (such as Catalyst) a 
pain, but it is better in the long run.

I would also hope that there would be an option that said "don't freshen 
unless I say".  Perusing "man CPAN" I see:

prerequisites_policy
                            what to do if you are missing module prerequisites
                            (’follow’ automatically, ’ask’ me, or ’ignore’)

I think that it asks by default.  So be careful what you agree to.  Never, 
never let CPAN install a new version of Perl.  It has tried to on me before - 
but luckily it was over DSL and I noticed what was going on before it 
succeeded.

Paul

__________cpan2deb____________________
#!/usr/bin/perl -w

# from http://alibi.simon-cozens.org/~simon/cpan2deb

use strict;
use Cwd;
use CPAN;
use File::Spec;
use File::Temp qw(tempdir);
use File::Copy;
use LWP::Simple qw(getstore);
use File::Basename;

my $tarball = shift;
my $pwd = cwd();
die "usage: cpan2deb <tarball>\n" unless defined $tarball;
$tarball .= ".tar.gz" if -f $tarball.".tar.gz";

# Maybe they didn't even specify the version number. Try the latest one?
$tarball = (glob("$tarball*tar.gz"))[-1] if glob("$tarball*tar.gz");

# Last ditch - grab from CPAN.
if (!-f $tarball) {
    print "Trying to find $tarball on CPAN\n\n";
    $tarball = CPAN::Shell->expand("Module",$tarball)->cpan_file;
    my $newtarball = basename($tarball);
    print "Fetching authors/id/$tarball from CPAN -> $newtarball\n";
    getstore("http://squash.oucs.ox.ac.uk/CPAN/authors/id/$tarball", 
$newtarball);
    die "Couldn't download $tarball" unless -f $newtarball;
    $tarball= $newtarball;
}

print "Converting $tarball...\n";

my $dir = tempdir(CLEANUP => 1);
copy($tarball,$dir."/".$tarball);
chdir ($dir) or die "Can't move to temporary dir $dir\n";
system ("tar xvzf $tarball");
print "Untarred $tarball in $dir\n";

# We could parse the result of tar, or...
my $subdir = (grep { -d $_ } glob("*"))[0];
chdir ($subdir) or die "Urgh?";
print "Chdir'ed into $subdir\n";

if (! -f "Makefile.PL") {
    die "This isn't the sort of CPAN module I was expecting\n";
}

my @dependencies = ("perl",finddeps());

system "$^X Makefile.PL"; # Why doesn't 'do' work?

# Extract version and distribution name from Makefile - easier than
# messing about with regexps on the tarball name.
open (MK, "Makefile") or die $!;
my ($pkg, $ver);
while (<MK>) {
    $pkg = $1 if /^DISTNAME = (.*)/;
    $ver = $1 if /^VERSION = (.*)/;
    last if $pkg and $ver;
}

die "Couldn't find a package name\n" unless $pkg;
die "Couldn't find a version for $pkg\n" unless $ver;
print "\nWriting Debian files for $pkg version $ver\n";

mkdir "debian", 0700  or die "Couldn't make debian directory";
chdir "debian" or die "Couldn't enter debian directory";
print "Entered the debian directory\n";

my $debian_name = "\Llib$pkg-perl";

# Build the control files
control(@dependencies);
rules();
changelog();

chdir "..";
system("dpkg-buildpackage -rsudo -uc -us");
die "\nProblems building package in $dir?\n" if $?;

chdir("..");

# Copy the generated packages back to where we came from
for (glob("lib*perl*")) {
    copy($_,$pwd."/$_");
    print "Finished file copied to: $pwd/$_\n";
}

system("sudo rm -rf *");
print "Removed build files\n";
print "Done\n";

###----------------------------------------------------------------###


sub changelog {
    open CL, ">changelog" or die $!;
print CL <<EOF;
$debian_name ($ver-1) unstable; urgency=low

  * Automatically produced

 -- cpan2deb tool <cpan2deb\@squash.oucs.ox.ac.uk>  @{[ `822-date` ]}
EOF
    close CL;
}

sub control {
    my $arch = glob("../*.xs") ? "i386" : "all"; # Rough hack
    open CONTROL, ">control" or die $!;
    print CONTROL <<EOF;
Source: $debian_name
Maintainer: cpan2deb tool <cpan2deb\@squash.oucs.ox.ac.uk>
Priority: optional
Section: interpreters
Build-Depends-Indep: debhelper (>= 3.0.5), perl5
Standards-Version: 3.5.6.0

Package: $debian_name
Architecture: $arch
Priority: optional
Section: interpreters
Depends: @{[@_ && join ",", @_]}
Description: $pkg Perl module
 Automatically generated from $tarball
EOF
    close CONTROL;
}

sub rules {
    # A fairly generic rules file which works OK for Debian stable
    # The INSTALLMAN3DIR thing is required due to a MakeMaker bug.
    my $rules = <<EOF;
#!/usr/bin/make -f

export DH_COMPAT := 2

PERL ?= /usr/bin/perl

b := \$(shell pwd)/debian/$debian_name

arrange: arrange-stamp
arrange-stamp: install
        dh_testdir
        touch arrange-stamp

binary: binary-stamp
binary-stamp: binary-indep binary-arch
        dh_testdir
        touch binary-stamp

binary-arch: binary-arch-stamp
binary-arch-stamp: arrange
        dh_testdir
        touch binary-arch-stamp

binary-indep: binary-indep-stamp
binary-indep-stamp: arrange
        dh_testdir
        dh_testroot
        @{[ -f "../README" && "dh_installdocs README" ]}
        dh_installexamples
        @{[    (-f "../CHANGES" && "dh_installchangelogs CHANGES")
            || (-f "../Changes" && "dh_installchangelogs Changes") ]}
        dh_compress
        dh_fixperms
        dh_installdeb
        dh_perl
        dh_gencontrol
        dh_md5sums
        dh_builddeb
        touch binary-indep-stamp

build: build-stamp
build-stamp: config
        dh_testdir
        \$(MAKE)
        touch build-stamp

clean:
        dh_testdir
        dh_testroot
        if [ -e Makefile ]; then \$(MAKE) -i distclean; fi
        dh_clean arrange-stamp binary-stamp binary-arch-stamp 
binary-indep-stamp build-stamp config-stamp install-stamp

config: config-stamp
config-stamp:
        dh_testdir
        \$(PERL) Makefile.PL INSTALLDIRS=perl
        touch config-stamp

install: install-stamp
install-stamp: build
        dh_testdir
        dh_installdirs
        \$(MAKE) install PREFIX=\$(b)/usr 
INSTALLMAN3DIR=\$(b)/usr/share/man/man3
        touch install-stamp

.PHONY: arrange binary binary-arch binary-indep build clean config install
EOF
    open RULES, ">rules" or die $!;
    print RULES $rules;
    close RULES;
    chmod 0755, "rules";
}

sub finddeps {
    # This is a pile of shit.

    mkdir "ExtUtils",0700 or die "Can't make fake ExtUtils dir";
    open C, ">ExtUtils/MakeMaker.pm" or die $!;
print C <<'EOF';
package ExtUtils::MakeMaker;
use Exporter; @ISA=qw(Exporter); @EXPORT = qw(WriteMakefile);

sub WriteMakefile {
    my %args = @_;
    return unless ref $args{PREREQ_PM};
    open D, ">DEPS";
    for (keys %{$args{PREREQ_PM}}) {
        print D "$_ ".$args{$PREREQ_PM}->{$_}."\n";
    }
    close D;
}

1;
EOF
    close C;
    system "$^X -I. Makefile.PL";
    unlink "ExtUtils/MakeMaker.pm";

    my %deps;

    print "Created Dependency file\n";
    open (D, "DEPS") or do { warn "No dependencies!\n"; return; };
    while (<D>) {
        chomp;
        my ($a, $b) = split;
        $a = basename(CPAN::Shell->expand("Module",$a)->cpan_file);
        # THIS IS REALLY BUTT-UGLY
        $a =~s/-[\.\d]+.tar.gz$//;
        $a =~ s/::/-/g;
        next if $a eq "perl";
        $a =~ s/lib//; # libnet, libwww, etc.
        $b = " (>= $b)" if $b;
        $deps{"lib".lc $a."-perl"} = $b;
    }
    return join ", ", map {$_.$deps{$_}} keys %deps;
}



More information about the PLUG mailing list