Professional Web Applications Themes

CPAN install from a local directory of module sources - PERL Beginners

Hi, I've been using Perl for quite awhile, but to be honest, I've always installed manually. Part of the reason is I don't like being online as root, running something. The other being I like to keep all my module sources in a single directory, for easy viewing. CPAN installed everything under obscure author names as directory structure. So my question is this: Say I have a directory of 200 modules, all in tgz packages, and I want to install them into my freshly built new Perl version. Up to now, I just did it manually as a way of ...

  1. #1

    Default CPAN install from a local directory of module sources

    Hi,

    I've been using Perl for quite awhile, but to be honest, I've
    always installed manually. Part of the reason is I don't like being
    online as root, running something. The other being I like to keep all
    my module sources in a single directory, for easy viewing. CPAN
    installed everything under obscure author names as directory structure.

    So my question is this: Say I have a directory of 200 modules, all in
    tgz packages, and I want to install them into my freshly built new Perl
    version.

    Up to now, I just did it manually as a way of refreshing myself with
    each module, but I'm doing a bunch of parallel system builds, and want
    to automate it.

    I don't need to be told to read perldoc CPAN, because I did, and it
    wasn't very clear on how to do what I want. That's why I'm asking.

    I'm considering just making a perl script to run thru a series of system
    calls, for tar -zxvf, perl Makefile.pl, make and make install. But I
    guess CPAN would take care of checking for dependent modules
    if the perl Makefile.pl part fails.

    Is it possible to put a dirlist of my module sources into a file, and
    feed the file to CPAN and let it install each one?

    Thanks.


    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
    Zentara Guest

  2. #2

    Default Re: CPAN install from a local directory of module sources

    zentara wrote:
     

    [off the top of my head, untested]
    Inside the directory of TGZ modules -

    #! /usr/local/bin/perl -w
    eval 'exec /usr/local/bin/perl -S $0 ${1+"$"}'
    if 0; #$running_under_some_shell

    use strict;
    use warnings;

    # Hmmm....
    # die "cannot un-gtar files"
    # if ((system("gtar zxvf *.t*z") / 256));

    use File::Find ();

    use vars qw/*name *dir *prune targets/;
    *name = *File::Find::name;
    *dir = *File::Find::dir;
    *prune = *File::Find::prune;

    sub wanted;

    File::Find::find({wanted => \&wanted}, '.');

    sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);

    push targets, (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _ &&
    /^Makefile\.PL\z/s &&
    sprintf("%s",$name);
    }

    # Do something with targets -
    print argets;
    # foreach, while, season to taste...

    __END__
    Wc Guest

  3. #3

    Default Re: CPAN install from a local directory of module sources

    WC -Sx- Jones wrote:
    push targets, (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && 


    Or ...

    push targets, (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _ &&
    /^.*\.t.*gz\z/s &&
    sprintf("%s",$name);


    HTH;
    -Sx-
    Wc Guest

  4. #4

    Default Re: CPAN install from a local directory of module sources

    zentara wrote:
     


    If CPAN is properly confiured to start with;
    on the OLD system - do:

    perl -MCPAN -e 'autobundle'

    After a LOT of stuff ...
    it will write something like:

    Wrote bundle file
    /Root/.cpan/Bundle/Snapshot_2004_04_03_00.pm

    Inside that file you can get -

    perl -MCPAN -e 'install Bundle::Snapshot_2004_04_03_00'

    Which tells you how to duplicate that particular
    installtions... Thbis is NOT recommended...

    I would suggest you go back and install all 200
    by hand again ...

    -Sx-

    Wc Guest

  5. #5

    Default Re: CPAN install from a local directory of module sources

    WC -Sx- Jones wrote: 
    >
    >
    >
    > If CPAN is properly confiured to start with;
    > on the OLD system - do:
    >
    > perl -MCPAN -e 'autobundle'[/ref]

    If you want to automate installation, I'd recomend taking a look a
    CPANPLUS <http://search.cpan.org/dist/CPANPLUS/>.
    Randy Guest

  6. #6

    Default Re: CPAN install from a local directory of module sources

    On Sat, 03 Apr 2004 13:24:31 -0500, org (Wc -Sx- Jones)
    wrote:
     [/ref]
     

    Thanks for the tips, code and ideas. :-)

    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
    Zentara Guest

  7. #7

    Default Re: CPAN install from a local directory of module sources

    Peter Scott wrote: 
     
    >
    >
    > Why?
    >
    > Granted, it is somewhat different from what the OP asked
    > for. He had a list of tgz files to install. Autobundle
    > lists all the modules that are installed on a given perl.[/ref]

    The OP may no longer have access to the original installation.
     

    Writing an appropriate Perl script to automate this process will get the
    installation up to speed just as fast -- then the OP could use
    autobundle to get those module more up-to-date.
     

    I have used autobundle many times (probably thousands - which, granted,
    is probably not as much as others) and in more than 80% of the
    installations there were dependencies which broke the automatic
    unattended installation.

    But, this is all based upon personal experience - so your mileage may
    vary. I am sure many Perl developers have no trouble with CPAN and I am
    sure that statistically these issues are all more or less platform
    related - environment related - not having appropriate settings and what
    not - not having all the "needed" OpSys programs, RDBMS, or GUI of the
    week installed.

    At any rate - with ~200 modules - this procedure is not trivial;
    especially if the more "hard-headed" modules are needed (Storable, DBI,
    et al.) I suggested several procedures to attack the problem -- I
    myself use CPAN frequently and I also install modules by hand when CPAN
    fails to install a module - like GD -- it has always failed to install
    GD on my Solaris 9 system even though I have all the pre-requisites.

    Not all software will work 100% on all ported systems.

    Cheers :)
    -Sx-
    Wc Guest

  8. #8

    Default Re: CPAN install from a local directory of module sources

    On 4 Apr 2004 14:52:37 -0000, com (Peter Scott) wrote:
     [/ref][/ref]
     

    Thanks for all the ideas, but I think the main problem with using
    autobundle, is that I like to keep all my sources in a single directory.
    CPAN likes to intall everything under the authors
    sub-directory-structure, although I may just not see how to specify
    that I want all sources kept and installed from a single directory.

    Anyways.....this is what I came up with. It unpacks all the sources,
    uses Module::Depends::Intrusive to "fake test" installing. Then if
    I find dependencies or errors, I set those modules into a bad or
    dependent arrays.

    Then I install all the non-dependent sources first, then process the
    dependent array. It isn't perfect, but it works fairly well in my
    situation where I have a bunch of module sources, which I know install
    well, and just want to "move" them to a new version"

    Any suggestions or criticisms are welcome.
    WATCH WORD WRAP!!!!!
    #################################################
    #!/usr/local/bin/perl
    use warnings;
    use strict;
    use Module::Depends::Intrusive;

    # linux only,
    # needs at least perl5.8.0 to use i/o to \$var,
    # attempts to automate module installation from
    # a directory full of module source tarballs.
    # Just put the script in a directory full of module
    # sources and run. You can set a non-standard install
    # dir by the $prefixdir variable immediately below.

    # requires Module::Depends->which needs File::chdir,
    # Class::Accessor, and Class::Accessor::Chained

    my $prefixflag = 0;

    # a dir to install to for testing or
    # a homedir install
    #my $prefixdir = '';
    my $prefixdir = '/home/zentara/ztest';
    if ( length $prefixdir > 0 ) { $prefixflag = 1 }

    open( LOG, "> $0.log" ) or die $!;

    my tarballs = <*.tar.gz>;

    #extract all tarballs
    foreach my $tarball (tarballs) {
    system( 'tar', '-zxvf', $tarball );
    }

    #get a list of all newly created directories
    # which probably don't correspond with tarball names
    opendir my $dh, '.' or die "Error: $!";
    my sourcedirs = grep !/^\.\.?$/, readdir $dh;
    closedir $dh;
    sourcedirs = grep { -d } sourcedirs; #only directories

    my bad; #module sources which need manual attention
    my dependent; #modules which are dependent and need to be

    #done last

    #check dependencies and adjust build order

    foreach my $testdir (sourcedirs) {

    my needs = ();
    my $output = '';
    my $error = '';
    my $depends = undef;

    #capture output of module to test for failures
    {
    local *STDOUT;
    open STDOUT, '+>', \$output or die $!;

    $depends =

    Module::Depends::Intrusive->new->dist_dir($testdir)->find_modules;
    }

    my $deps = $depends->requires;

    #check if error was generated
    $error = $depends->error;
    if ( length $error > 0 ) {
    sourcedirs = grep { !/^\Q$testdir\E$/ } sourcedirs;
    push bad, $testdir;
    }
    next if length $error > 0;

    needs = keys %{$deps};
    if ( ( scalar needs ) > 0 ) {

    #move to end of install list so that dependent
    #modules can install first...not efficient, but easy :-)
    sourcedirs = grep { !/^\Q$testdir\E$/ } sourcedirs;
    push dependent, $testdir;
    }

    #check for "failed" messages in output from Module::Depends
    #and send those to dependent for later install
    if ( $output =~ /failed/i ) {
    sourcedirs = grep { !/^\Q$testdir\E$/ } sourcedirs;
    push dependent, $testdir;
    }

    print LOG '#' x 25, "\n";
    print LOG '#' x 25, "\n";
    print LOG "DIR-> $testdir\n";
    print LOG "OUTPUT $output\n";
    print LOG "needs -> needs\n";
    print LOG "ERROR-> $error\n";
    }

    print "\n\nSourcedirs-> sourcedirs\n";
    print "\n\nDependent-> dependent\n";
    print "\n\nBad-> bad\n";

    print LOG "\n\nSourcedirs-> sourcedirs\n";
    print LOG "\n\nDependent-> dependent\n";
    print LOG "\n\nBad-> bad\n";

    ################################################## #################
    #start the install
    #do the first run on error free source dirs
    foreach my $installdir (sourcedirs) {

    chdir $installdir;

    if ($prefixdir) {
    system( 'perl', 'Makefile.PL', "PREFIX=$prefixdir" );
    }
    else {
    system( 'perl', 'Makefile.PL' );
    }
    system( 'make', 'install' );

    chdir '../';
    }

    ################################################## ###################
    #now process the dependent sourcedirs. Hopefully, most
    #dependencies were installed above, if not, and some of the dependent
    #modules are dependent on each other, we will just install what we
    #can.

    foreach my $installdir (dependent) {

    chdir $installdir;

    if ($prefixdir) {
    system( 'perl', 'Makefile.PL', "PREFIX=$prefixdir" );
    }
    else {
    system( 'perl', 'Makefile.PL' );
    }
    system( 'make', 'install' );

    chdir '../';
    }

    ################################################## ###################

    print "\e[1;31mDone!...be sure to check list of \bad modules at the end
    of
    $0.log....which need manual installation.\e[0m\n";

    print "Uninstallable modules are:\n";

    print "\e[1;31m";
    print join "\n", bad;
    print "\e[0m\n";
    __END__










    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
    Zentara Guest

Similar Threads

  1. Question CPAN: Failing to Install Benchmark module
    By emgachimu in forum Brainstorming Area
    Replies: 0
    Last Post: March 23rd, 07:13 AM
  2. CPAN module local installation question
    By Ronald Fischer in forum PERL Modules
    Replies: 8
    Last Post: July 17th, 10:11 AM
  3. Replies: 0
    Last Post: July 9th, 05:25 PM
  4. Replies: 0
    Last Post: May 10th, 08:51 PM
  5. newbie trying to install a cpan module
    By Brian McCauley in forum PERL Modules
    Replies: 0
    Last Post: August 20th, 11:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139