Mass installation of perl modules
Posted on September 13th, 2010
Sometimes I need to install number of new perl modules into my Solaris servers. This technique can be used for any unix-like system despite the fact that Linux and FreeBSD has his own perl module packages (available from ports and corresponding rpms). But every perl installation has a CPAN module which can be used when installing new modules. The main issue when doing unattended perl module installation with CPAN is that you should configure CPAN itself first, but you don’t want to bother with manually answering number of questions about local CPAN configuration. So here is quick and dirty solution of how to do unattended install of perl module using CPAN on number of server at once with no human intervention. You run the script with module name supplied as argument remotely using ssh key-based passwordless authentication. I’ll describe one of these passwordless system later, but for now here is a script I used for Solaris 9 and 10 systems (both SPARC and amd64).
#!/usr/bin/perl $module = $ARGV[0]; $CPAN::Config = { 'build_cache' => q[10], 'build_dir' => q[/.cpan/build], 'cache_metadata' => q[1], 'cpan_home' => q[/.cpan], 'dontload_hash' => { }, 'ftp' => q[/usr/bin/ftp], 'ftp_proxy' => q[http://yourproxy.com:8080], 'getcwd' => q[cwd], 'gpg' => q[], 'gzip' => q[/usr/bin/gzip], 'histfile' => q[/.cpan/histfile], 'histsize' => q[100], 'http_proxy' => q[http://yourproxy.com:8080], 'inactivity_timeout' => q[0], 'index_expire' => q[1], 'inhibit_startup_message' => q[0], 'keep_source_where' => q[/.cpan/sources], 'lynx' => q[], 'make' => q[/usr/ccs/bin/make], 'make_arg' => q[], 'make_install_arg' => q[], 'makepl_arg' => q[], 'ncftp' => q[], 'ncftpget' => q[], 'no_proxy' => q[], 'pager' => q[/usr/bin/less], 'prerequisites_policy' => q[follow], 'proxy_pass' => q[], 'proxy_user' => q[], 'scan_cache' => q[atstart], 'shell' => q[/sbin/sh], 'tar' => q[/usr/local/bin/tar], 'term_is_latin' => q[1], 'unzip' => q[/usr/bin/unzip], 'urllist' => [q[http://mirror.rol.ru/CPAN/]], 'wget' => q[/usr/local/bin/wget], 'optimize' => q[], }; require CPAN; CPAN::install($module);
Note, that you should install GNU tar and GNU wget first. Also you may want to change build_dir, cpan_home, make, urllist, proxy parameters. If CPAN still asking you about configuration, just find and remove your old CPAN Config.pm module.
Filed under Perl | No Comments »
How to install perl module into custom location
Posted on March 18th, 2010
You need to install Text::Wrapper into your home directory
wget http://search.cpan.org/CPAN/authors/id/C/CJ/CJM/Text-Wrapper-1.02.tar.gz tar zxf Text-Wrapper-1.02.tar.gz cd Text-Wrapper-1.02 perl Build.PL ./Build destdir=$HOME install_base=$HOME ./Build destdir=$HOME install_base=$HOME install
If there is only Makefile.PL
perl Makefile.PL PREFIX=$HOME make make install
If you are using perl -MCPAN -e shell then you need to change makepl_arg, destdir and install_base args
in ~/.cpan/CPAN/MyConfig.pm
.... 'destdir' => q[~/], 'install_base' => q[~/], 'makepl_arg' => q[SITELIBEXP=~/lib/perl5 LIB=~/lib/perl5 INSTALLMAN1DIR=~/share/man/man1 INSTALLMAN3DIR=~/share/man/man3 INSTALLSITEMAN1DIR=~/share/man/man1 NSTALLSITEMAN3DIR=~/share/man/man3], ...
If you need to use your home-dir-placed modules in apache mod_perl or perl cgi, add
SetEnv PERL5LIB /home/you/lib/perl5:/home/you/lib
presuming that you have placed your perl modules under /home/you/lib/perl5 and /home/you/lib directories
If you need custom build of some module requiring another module in non-standard location, just export PERL5LIB shell variable. For example, you need to build RRD::Simple, which requires RRDs.pm, but RRDs.pm is not distributed via CPAN, so you have downloaded rrdtool and unpacked it in some location.
wget http://search.cpan.org/CPAN/authors/id/N/NI/NICOLAW/RRD-Simple-1.44.tar.gz tar zxf RRD-Simple-1.44.tar.gz gunzip -cd RRD-Simple-1.44.tar.gz | tar xf - export PERL5LIB=/usr/local/rrdtool-1.2.19/lib/perl/5.8.7/i86pc-solaris perl Makefile.PL make && make install
and then dont forget to
use lib "/usr/local/rrdtool-1.2.19/lib/perl/5.8.7/i86pc-solaris";
in your perl program.
Filed under Perl | No Comments »
Automating blog posting
Posted on January 25th, 2010
Here goes little program to automate blog postings.
Filed under Perl | No Comments »