Category: utilities
Author/Contact Info Jean-Marie Renouard<jmrenouard@gmail.com>
Description: The main problem with cpan-download perl code is that you always need 5/6 modules installed on your system to be able to download and install your favorite modules easily.

In big compagnies, access to ftp are reduced so that cpan install ... can't be used easily because it used principaly ftp as module download protocol.

This script is a mix between shell and perl.

This script is based in wget, tar from the system so that you don't need extra modules to start installing automatically new module.

In fact, this is a nasty way, to be honest but it can be used to install cpan, libwww, cpan2rpm and them it can be forgotten.

But for a brand new installed system it is a ideal module installer because it is not depending from various module but from a standard based install perl !

In order to cross proxy just set your http_proxy environnement variable.

export http_proxy=proxyIp:proxyPort perl cpan.pl cpan2rpm
#!/bin/usr/perl
use strict;

sub trim($)
{
        my $string = shift;
        $string =~ s/^\s+//;
        $string =~ s/\s+$//;
        return $string;
} 
my $packName = $ARGV[0]; $packName=~s/:/%3A/g; print $packName,"\n";

my $url = 'http://search.cpan.org/search?format=xml&query='. $packName
+; print $url,"\n";

my $url2 = `wget -q "$url" -O -`; 

if ($url2 =~ s/<link>(.*?)<\/link>/$1/)
{
        my $url2 = trim $1;
        print $url2,"\n";
        my $content = `wget -q "$url2" -O -`;
        if ($content =~ /Download: <a href="(.*?)">/)
        {
                print $1,"\n";
                my $url3 = "http://search.cpan.org$1";
                print `wget -q "$url3"`;
                my $arch = `basename $1`;
                print `tar xvzf $arch`;
                if ( $arch =~ /(.*?).tar.gz/)
                {
                        my $cur=`pwd`;
                        chdir $1;
                        print `perl ./Makefile.PL`;
                        print `make test && sudo make install`;
                        print "going to $cur";
                        chdir("..");
                        print `pwd`;
                        print `/bin/rm -Rf $1*` if ($ARGV[1] eq "-c") 
+;
                }
        }
}
Replies are listed 'Best First'.
Re: Cpan downloader with shell
by hossman (Prior) on Jul 11, 2007 at 01:14 UTC

    The entire premise of this program is very confusing to me.

    if your goal is to install modules from CPAN, and your objection to using the CPAN module is that it uses FTP but you can't access FTP servers, then why don't you just configure CPAN to only know about HTTP sources??

    The list of CPAN mirrors that CPAN fetches from is entirely under your control when you configure the url list ... if you only specify http:// urls, it will only use HTTP

    Am i missing something here?