Author: arkurth
Date: Thu Mar  3 17:09:34 2011
New Revision: 1076686

URL: http://svn.apache.org/viewvc?rev=1076686&view=rev
Log:
VCL-434
Updated install_perl_libs.pl to use CPAN.pm to automatically install the 
required modules and their dependencies rather than specifying several URLs.  
This should allow the script to work indefinitely.  Added code to this script 
to also install the required Linux packages using yum and updated the license 
disclaimer.

Modified:
    incubator/vcl/trunk/managementnode/bin/install_perl_libs.pl

Modified: incubator/vcl/trunk/managementnode/bin/install_perl_libs.pl
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/bin/install_perl_libs.pl?rev=1076686&r1=1076685&r2=1076686&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/bin/install_perl_libs.pl (original)
+++ incubator/vcl/trunk/managementnode/bin/install_perl_libs.pl Thu Mar  3 
17:09:34 2011
@@ -46,233 +46,247 @@ use strict;
 use warnings;
 use diagnostics;
 
-my $disclaimer .= <<"EOF";
-*** NOTICE ***
+use Getopt::Long;
+use Data::Dumper;
+use CPAN;
+
+#/////////////////////////////////////////////////////////////////////////////
+
+# Store the command line options in hash
+my $AGREE;
+my %OPTIONS;
+GetOptions(\%OPTIONS,
+                       'y!' => \$AGREE,
+);
 
-This script will download and install Perl modules distributed under
-the following licenses:
-- The "Artistic License"
-- GNU General Public License (GPL)
-- GNU Library or "Lesser" General Public License (LGPL)
+show_disclaimer() if !$AGREE;
 
-See the README file for more information.
-EOF
+print_break('=');
+install_linux_packages();
 
-print '=' x 76 . "\n";
-print $disclaimer;
-print '=' x 76 . "\n";
-
-while (1) {
-       print 'Type YES to proceed, type NO to abort: ';
-       my $input = <>;
-       if ($input =~ /^\s*YES\s*$/i) {
-               last;
-       }
-       elsif ($input =~ /^\s*NO\s*$/i) {
-               exit;
+print_break('=');
+install_perl_modules();
+
+print_break('=');
+exit;
+
+#/////////////////////////////////////////////////////////////////////////////
+
+sub install_linux_packages {
+       my @linux_packages = (
+               'expat',
+               'expat-devel',
+               'gcc',
+               'krb5-libs',
+               'krb5-devel',
+               'libxml2',
+               'libxml2-devel',
+               'nmap',
+               'openssl',
+               'openssl-devel',
+               'perl-DBD-MySQL',
+               'xmlsec1-openssl',
+       );
+       
+       my $which_exit_status = run_command("which yum");
+       if ($which_exit_status ne '0') {
+               print "yum is not available on this OS, skipping Linux package 
installation\n";
+               return 0;
        }
-       else {
-               next;
+       
+       my $yum_exit_status = run_command("yum install -y " . join(" ", 
@linux_packages));
+       print "yum installation exit status: $yum_exit_status\n";
+       if ($yum_exit_status ne '0') {
+               print "failed to install all Linux packages using yum, exit 
status: $yum_exit_status\n";
+               exit 1;
        }
+       
+       print "successfully installed Linux packages using yum\n";
+       return 1;
 }
 
-print '=' x 76 . "\n";
+#/////////////////////////////////////////////////////////////////////////////
 
-my $download_directory= '/tmp/perl-modules';
-mkdir $download_directory;
-
-my @module_urls = (
-       # MailTools is used to send email messages
-       
'http://search.cpan.org/CPAN/authors/id/M/MA/MARKOV/MailTools-2.06.tar.gz',
-       
-       # Object-InsideOut is used by DataStructure.pm for data encapsulation
-       # The other modules listed are dependencies for Object-InsideOut
-       
'http://search.cpan.org/CPAN/authors/id/T/TM/TMTM/Class-Data-Inheritable-0.08.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/Test-Simple-0.96.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/ExtUtils-MakeMaker-6.56.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/D/DR/DROLSKY/Devel-StackTrace-1.25.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/D/DR/DROLSKY/Exception-Class-1.32.tar.gz',
-       'http://search.cpan.org/CPAN/authors/id/R/RO/ROBIN/Want-0.18.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/J/JD/JDHEDDEN/Math-Random-MT-Auto-6.15.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/J/JD/JDHEDDEN/Object-InsideOut-3.67.tar.gz',
-       
-       # YAML is used to serialize data stored in the database
-       'http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/YAML-0.72.tar.gz',
-       
-       # RPC-XML is used to interact with the scheduling interface provided by 
the web frontend
-       # The other modules listed are dependencies for RPC-XML
-       'http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/URI-1.55.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/libwww-perl-5.836.tar.gz',
-       'http://search.cpan.org/CPAN/authors/id/R/RJ/RJRAY/RPC-XML-0.73.tar.gz',
-       'http://www.cpan.org/modules/by-module/XML/XML-Parser-2.36.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/N/NA/NANIS/Crypt-SSLeay-0.58.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/P/PE/PETDANCE/HTML-Tagset-3.20.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/HTML-Parser-3.68.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/P/PM/PMQS/Compress-Raw-Bzip2-2.030.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/P/PM/PMQS/Compress-Raw-Zlib-2.030.tar.gz',
-       
'http://search.cpan.org/CPAN/authors/id/P/PM/PMQS/IO-Compress-2.030.tar.gz',
-       
-       # DBI is used to communicate with the database
-       'http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.613.tar.gz',
-       
-       # SHA1 is used when creating new local VCL accounts
-       
'http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/Digest-SHA1-2.13.tar.gz',
-);
-
-# Loop through each URL
-URL: for my $url (@module_urls) {
-       print '-' x 76 . "\n";
-       #print "URL: $url\n";
-       
-       my ($module_filename) = $url =~ /([^\/]+)$/;
-       #print "Module filename: $module_filename\n";
-       
-       my ($module_name) = $url =~ /([^\/]+)\.tar\.gz$/;
-       #print "Module name: $module_name\n";
-       
-       my ($module_package) = $module_name =~ /([^\/]+)-[\d\.]+$/;
-       $module_package =~ s/-/::/g;
-       
-       # Fix module package names and set arguments as necessary
-       if ($module_name =~ /libwww-perl/) {
-               $module_package = "LWP";
-       }
-       elsif ($module_name =~ /MailTools/) {
-               $module_package = "Mail::Mailer";
-       }
-       elsif ($module_name =~ /IO-Compress/) {
-               $module_package = "Compress::Zlib";
-       }
-       elsif ($module_name =~ /InsideOut/) {
-               $module_package = "Object::InsideOut::Util";
-       }
-       #print "Module package: $module_package\n";
-       
-       my ($module_version) = $url =~ /(\d[\d\.]+\d)/;
-       print "Perl module: $module_package $module_version\n";
-       
-       #print "Module version: $module_version\n";
-       
-       my $install_module = 0;
-       
-       my $installed_version = module_installed($module_package);
-       if ($installed_version) {
-               print "$module_package $installed_version is installed\n";
+sub install_perl_modules {
+       $ENV{PERL_MM_USE_DEFAULT} = 1; 
+       $ENV{PERL_MM_NONINTERACTIVE} = 1; 
+       $ENV{AUTOMATED_TESTING} = 1;
+       $ENV{FTP_PASSIVE} = 1;
+       
+       my $cpan_directory = '/tmp/cpan';
+       `rm -rf $cpan_directory`;
+       
+       $CPAN::Config = {
+               "applypatch" => "",
+               "auto_commit" => "1",
+               "build_cache" => "0",
+               "build_dir" => "$cpan_directory/build",
+               "build_requires_install_policy" => "yes",
+               "bzip2" => `echo -n \`which bzip2\``,
+               "cache_metadata" => "1",
+               "check_sigs" => "0",
+               "connect_to_internet_ok" => "1",
+               "cpan_home" => "$cpan_directory",
+               "curl" => `echo -n \`which curl\``,
+               "force" => "1",
+               "ftp" => `echo -n \`which ftp\``,
+               "ftp_passive" => "1",
+               "ftp_proxy" => "",
+               "getcwd" => "cwd",
+               "gpg" => `echo -n \`which gpg\``,
+               "gzip" => `echo -n \`which gzip\``,
+               "halt_on_failure" => "0",
+               "histfile" => "$cpan_directory/histfile",
+               "histsize" => "1000",
+               "http_proxy" => "",
+               "inactivity_timeout" => "60",
+               "index_expire" => "1",
+               "inhibit_startup_message" => "1",
+               "keep_source_where" => "$cpan_directory/sources",
+               "links" => `echo -n \`which links\``,
+               "load_module_verbosity" => "0",
+               "make" => `echo -n \`which make\``,
+               "make_arg" => "",
+               "make_install_arg" => "",
+               "make_install_make_command" => `echo -n \`which make\``,
+               "makepl_arg" => "",
+               "mbuild_arg" => "",
+               "mbuild_install_arg" => "",
+               "mbuild_install_build_command" => "./Build",
+               "mbuildpl_arg" => "",
+               "ncftp" => "",
+               "ncftpget" => "",
+               "no_proxy" => "",
+               "pager" => `echo -n \`which less\``,
+               "perl5lib_verbosity" => "",
+               "prefer_installer" => "MB",
+               "prefs_dir" => "$cpan_directory/prefs",
+               "prerequisites_policy" => "follow",
+               "proxy_user" => "",
+               "randomize_urllist" => "1",
+               "scan_cache" => "never",
+               "shell" => `echo -n \`which bash\``,
+               "show_upload_date" => "0",
+               "tar" => `echo -n \`which tar\``,
+               "tar_verbosity" => "0",
+               "term_ornaments" => "1",
+               "trust_test_report_history" => "1",
+               "unzip" => `echo -n \`which unzip\``,
+               "urllist" => "",
+               "use_sqlite" => "0",
+               "wget" => `echo -n \`which wget\``,
+               "yaml_load_code" => "0",
+       };
+       
+       print Dumper($CPAN::Config);
+       
+       my @perl_modules = (
+               'DBI',
+               'Digest::SHA1',
+               'Mail::Mailer',
+               'Net::Jabber',
+               'Object::InsideOut',
+               'RPC::XML',
+               'YAML',
+       );
+       
+       for my $perl_module (@perl_modules) {
+               print_break('-');
+               print "attempting to install Perl module using CPAN: 
$perl_module\n";
+               CPAN::install($perl_module);
                
-               my @module_version_sections = split(/\./, $module_version);
-               #print "Module version sections:    @module_version_sections\n";
-               
-               my @installed_version_sections = split(/\./, 
$installed_version);
-               #print "Installed version sections: 
@installed_version_sections\n";
-               
-               for (my $i=0; $i<scalar(@module_version_sections); $i++) {
-                       if (!defined($installed_version_sections[$i])) {
-                               print "Module installed appears to be a newer 
sub version: $installed_version > $module_version\n";
-                               next URL;
-                       }
-                       
-                       my $module_version_section = 
$module_version_sections[$i];
-                       my $installed_version_section = 
$installed_version_sections[$i];
-                       
-                       if ($module_version_section !~ /^\d+$/ || 
$installed_version_section !~ /^\d+$/) {
-                               print "Unable to compare versions: 
'$installed_version' '$module_version'\n";
-                               last;
-                       }
-                       
-                       $module_version_section =~ s/0+$//g;
-                       $installed_version_section =~ s/0+$//g;
-                       
-                       #print "Module version section: 
$module_version_section\n";
-                       #print "Installed version section: 
$installed_version_section\n";
-                       
-                       $module_version_section = 0 if !$module_version_section;
-                       $installed_version_section = 0 if 
!$installed_version_section;
-                       
-                       if ($module_version_section < 
$installed_version_section) {
-                               print "Module installed appears to be a newer 
version: $installed_version > $module_version\n";
-                               $install_module = 0;
-                               last;
-                       }
-                       
-                       if ($module_version_section > 
$installed_version_section) {
-                               print "Module installed appears to be an older 
version: $installed_version < $module_version\n";
-                               $install_module = 1;
-                               last;
-                       }
+               if (!is_perl_module_installed($perl_module)) {
+                       exit 1;
                }
+               
        }
        
-       if ($installed_version && !$install_module) {
-               print "$module_package $module_version does not need to be 
installed\n";
-               next;
-       }
-       
-       print "Attempting to install module: $module_package $module_version\n";
-       
-       run_command("rm -rf $download_directory/*$module_name*");
-       
-       my ($wget_exit_status, $wget_output) = run_command("wget 
--directory-prefix=$download_directory $url");
-       if ($wget_exit_status ne '0') {
-               print "$module_name installation failed, unable to download 
module: $module_package\nURL: $url\noutput:\n---\n$wget_output\n---\n";
-               exit 1;
-       }
-       
-       run_command("tar -xzf $download_directory/$module_filename -C 
$download_directory");
-       
-       my ($makefile_exit_status, $makefile_output) = run_command("cd 
$download_directory/$module_name && perl Makefile.PL");
-       if ($makefile_exit_status ne '0') {
-               print "failed to create makefile for $module_name, 
output:\n---\n$makefile_output\n---\n";
-               exit 1;
-       }
-       
-       run_command("cd $download_directory/$module_name && make");
-       ##run_command("cd $download_directory/$module_name && make test");
-       
-       my ($install_exit_status, $install_output) = run_command("cd 
$download_directory/$module_name && make install");
-       if ($install_exit_status ne '0') {
-               print "output:\n---\n$install_output\n---\n$module_name 
installation failed, make install exit status is $install_exit_status, output 
is above\n";
-               exit 1;
-       }
-       print "Installed $module_package $module_version\n";
+       print_break("*");
+       print "successfully installed required Perl modules\n";
+       return 1;
 }
 
-print '=' x 76 . "\n";
-exit  0;
+#/////////////////////////////////////////////////////////////////////////////
 
-sub module_installed {
+sub is_perl_module_installed {
        my $module_package = shift;
        
-       #print "Checking if $module_package is installed\n";
+       print "checking if $module_package Perl module is installed...\n";
        
-       my $command = "perl -M$module_package -e \"print \\\$" . 
$module_package . "::VERSION\" 2>&1";
-       #print "Command: $command\n";
+       my $command = "perl -e \"eval \\\"use $module_package\\\"; print \\\$" 
. $module_package . "::VERSION\" 2>&1";
        my $output = `$command`;
        
-       #my $output = `perl -M$module_package -e '$command' 2>&1`;
        my $exit_status = $? >> 8;
-       #print "Checked if $module_package is installed, 
output:\n---\n$output\n---\n";
+       #print "checked if $module_package is installed, version check 
output:\n$output\n";
        
        if ($output =~ /Can't locate/i) {
-               print "Module is NOT already installed: $module_package\n";
+               print "$module_package Perl module is NOT installed\n";
                return;
        }
        
        my ($version) = $output =~ /^(\d[\d\.]+\d)$/;
        if (defined($version)) {
+               print "$module_package $version Perl module is installed\n";
                return $version;
        }
        else {
-               print "$module_package is installed but the version could not 
be determined\n";
-               return 0;
+               print "$module_package Perl module is installed but the version 
could not be determined, output:\n$output";
+               return 1;
        }
 }
 
+#/////////////////////////////////////////////////////////////////////////////
+
 sub run_command {
        my $command = shift;
        
-       #print "--------------------------------------------------\n";
-       print "Running command: $command\n";
-       my $output = `$command 2>&1`; 
+       print "attempting to run command: $command\n";
+       system $command; 
        my $exit_status = $? >> 8;
-       return ($exit_status, $output);
+       print "ran command: $command, exit status: $exit_status\n";
+       return $exit_status;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+sub show_disclaimer {
+       my $disclaimer .= <<"EOF";
+*** NOTICE ***
+
+This script will download and install Linux packages and Perl modules
+distributed under the following licenses:
+- The "Artistic License"
+- BSD License
+- GNU General Public License (GPL)
+- GNU Library or "Lesser" General Public License (LGPL)
+- MIT License
+
+See the README file for more information.
+EOF
+
+       print '=' x 76 . "\n";
+       print $disclaimer;
+       print '=' x 76 . "\n";
+       
+       while (1) {
+               print 'Type YES to proceed, type NO to abort: ';
+               my $input = <>;
+               if ($input =~ /^\s*YES\s*$/i) {
+                       last;
+               }
+               elsif ($input =~ /^\s*NO\s*$/i) {
+                       exit;
+               }
+               else {
+                       next;
+               }
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+sub print_break {
+       my $character = shift;
+       $character = '-' if !defined($character);
+       print $character x 80 . "\n";
 }


Reply via email to