Author: arkurth Date: Mon Mar 14 14:35:21 2011 New Revision: 1081397 URL: http://svn.apache.org/viewvc?rev=1081397&view=rev Log: VCL-434 Updated install_perl_libs.pl. It now attempts to install EPEL so that additional Perl packages can be installed via yum. Improved error checking.
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=1081397&r1=1081396&r2=1081397&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/bin/install_perl_libs.pl (original) +++ incubator/vcl/trunk/managementnode/bin/install_perl_libs.pl Mon Mar 14 14:35:21 2011 @@ -44,9 +44,10 @@ use strict; use warnings; use diagnostics; +use English; use Getopt::Long; use Data::Dumper; -use CPAN; +use POSIX; #///////////////////////////////////////////////////////////////////////////// @@ -54,11 +55,13 @@ use CPAN; my $AGREE; my %OPTIONS; GetOptions(\%OPTIONS, - 'y!' => \$AGREE, + 'y!' => \$AGREE, ); show_disclaimer() if !$AGREE; +my @ERRORS; + print_break('='); install_linux_packages(); @@ -66,11 +69,63 @@ print_break('='); install_perl_modules(); print_break('='); + +if (@ERRORS) { + print "WARNING: failed to install the following components:\n" . join("\n", @ERRORS) . "\n"; +} +else { + print "COMPLETE: installed all components\n"; +} + exit; #///////////////////////////////////////////////////////////////////////////// sub install_linux_packages { + # Check if yum is available + my ($which_exit_status, $which_output) = 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; + } + + my @uname = POSIX::uname(); + my $arch = $uname[4]; + my $version = $uname[2]; + + if (!$arch || !$version) { + print "WARNING: unable to determine OS architecture and version, skipping Linux package installation\n"; + return; + } + + if ($arch =~ /i686/) { + $arch = 'i386'; + } + + my $rhel_version; + if ($version =~ /el(\d+)/) { + $rhel_version = $1; + } + + if ($rhel_version) { + my $epel_url = "http://download.fedora.redhat.com/pub/epel/$rhel_version/$arch/epel-release-5-4.noarch.rpm"; + print "constructed EPEL URL:\n$epel_url\n\n"; + + my $rpm_command = "rpm -Uvh $epel_url"; + my $rpm_output = `$rpm_command 2>&1`; + my $rpm_exit_status = $? >> 8; + if ($rpm_exit_status ne '0' && $rpm_output !~ /already installed/i) { + print "WARNING: failed to install EPEL, some Perl modules may not install correctly\nrpm command: $rpm_command\nrpm exit status: $rpm_exit_status\nrpm output:\n$rpm_output\n"; + push @ERRORS, 'EPEL'; + } + else { + print "SUCCESS: installed EPEL\n"; + } + } + else { + print "OS version does not appear to be RHEL: $version, skipping EPEL installation\n"; + } + my @linux_packages = ( 'expat', 'expat-devel', @@ -82,71 +137,103 @@ sub install_linux_packages { 'nmap', 'openssl', 'openssl-devel', + 'perl-CPAN', 'perl-DBD-MySQL', + 'perl-DBI', + 'perl-Digest-SHA1', + 'perl-MailTools', + 'perl-Net-Jabber', + 'perl-RPC-XML', + 'perl-YAML', '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; - } - - 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; + for my $linux_package (@linux_packages) { + print_break('*'); + print "attempting to install Linux package using yum: $linux_package\n"; + + my $yum_command = "yum install $linux_package -y"; + print "yum command: $yum_command\n"; + + my $yum_output = `$yum_command 2>&1`; + my $yum_exit_status = $? >> 8; + + chomp $yum_output; + print "$yum_output\n\n"; + + if ($yum_exit_status ne '0') { + print "WARNING: failed to install Linux package: $linux_package, exit status: $yum_exit_status\n"; + #push @ERRORS, "Linux package: $linux_package"; + } + elsif ($yum_output =~ /$linux_package[^\n]*already installed/i) { + print "SUCCESS: Linux package is already installed: $linux_package\n"; + } + elsif ($yum_output =~ /Complete\!/i) { + print "SUCCESS: installed Linux package: $linux_package\n"; + } + else { + print "WARNING: unexpected output returned while installing Linux package: $linux_package\n"; + #push @ERRORS, "Linux package: $linux_package"; + } + } - print "successfully installed Linux packages using yum\n"; return 1; } #///////////////////////////////////////////////////////////////////////////// sub install_perl_modules { + + eval "use CPAN"; + if ($EVAL_ERROR) { + print "ERROR: CPAN Perl module is not installed, unable to install other Perl module dependencies\n"; + exit; + } + $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`; + my $cpan_directory = $ENV{HOME} . '/.cpan'; + my $config_file_path = "$cpan_directory/CPAN/MyConfig.pm"; + `mkdir -p $cpan_directory/CPAN`; $CPAN::Config = { "applypatch" => "", "auto_commit" => "1", - "build_cache" => "0", + "build_cache" => "1", "build_dir" => "$cpan_directory/build", "build_requires_install_policy" => "yes", - "bzip2" => `echo -n \`which bzip2\``, + "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\``, + "debug" => "all", + "curl" => `echo -n \`which curl\`` || "", "force" => "1", - "ftp" => `echo -n \`which ftp\``, + "ftp" => `echo -n \`which ftp\`` || "", "ftp_passive" => "1", "ftp_proxy" => "", "getcwd" => "cwd", - "gpg" => `echo -n \`which gpg\``, - "gzip" => `echo -n \`which gzip\``, + "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", + "index_expire" => "10", "inhibit_startup_message" => "1", "keep_source_where" => "$cpan_directory/sources", - "links" => `echo -n \`which links\``, - "load_module_verbosity" => "0", - "make" => `echo -n \`which make\``, + "links" => `echo -n \`which links\`` || "", + "load_module_verbosity" => "1", + "make" => `echo -n \`which make\`` || "", "make_arg" => "", "make_install_arg" => "", - "make_install_make_command" => `echo -n \`which make\``, + "make_install_make_command" => `echo -n \`which make\`` || "", "makepl_arg" => "", "mbuild_arg" => "", "mbuild_install_arg" => "", @@ -155,7 +242,7 @@ sub install_perl_modules { "ncftp" => "", "ncftpget" => "", "no_proxy" => "", - "pager" => `echo -n \`which less\``, + "pager" => `echo -n \`which less\`` || "", "perl5lib_verbosity" => "", "prefer_installer" => "MB", "prefs_dir" => "$cpan_directory/prefs", @@ -163,26 +250,37 @@ sub install_perl_modules { "proxy_user" => "", "randomize_urllist" => "1", "scan_cache" => "never", - "shell" => `echo -n \`which bash\``, + "shell" => `echo -n \`which bash\`` || "", "show_upload_date" => "0", - "tar" => `echo -n \`which tar\``, + "tar" => `echo -n \`which tar\`` || "", "tar_verbosity" => "0", "term_ornaments" => "1", "trust_test_report_history" => "1", - "unzip" => `echo -n \`which unzip\``, - "urllist" => "", + "unzip" => `echo -n \`which unzip\`` || "", + "urllist" => [q[http://www.perl.com/CPAN/]], "use_sqlite" => "0", - "wget" => `echo -n \`which wget\``, + "wget" => `echo -n \`which wget\`` || "", "yaml_load_code" => "0", }; - print Dumper($CPAN::Config); + eval { CPAN::Config->commit($config_file_path) }; + if ($EVAL_ERROR) { + print "CPAN configuration:\n"; + print Dumper($CPAN::Config) . "\n"; + + print "\nERROR: failed to create CPAN configuration file: $config_file_path\n"; + exit 1; + } + else { + print "created CPAN configuration file: $config_file_path\n"; + } + + print_cpan_configuration(); my @perl_modules = ( 'DBI', 'Digest::SHA1', 'Mail::Mailer', - 'Net::Jabber', 'Object::InsideOut', 'RPC::XML', 'YAML', @@ -191,16 +289,16 @@ sub install_perl_modules { for my $perl_module (@perl_modules) { print_break('-'); print "attempting to install Perl module using CPAN: $perl_module\n"; - CPAN::install($perl_module); + + eval { CPAN::Shell->install($perl_module) }; if (!is_perl_module_installed($perl_module)) { - exit 1; + print "ERROR: failed to install Perl module: $perl_module\n"; + push @ERRORS, "Perl module: $perl_module"; } - } print_break("*"); - print "successfully installed required Perl modules\n"; return 1; } @@ -228,8 +326,8 @@ sub is_perl_module_installed { return $version; } else { - print "$module_package Perl module is installed but the version could not be determined, output:\n$output"; - return 1; + print "Perl module $module_package appears to be installed but the version could not be determined\ncommand: $command\noutput:\n$output"; + return; } } @@ -239,10 +337,10 @@ sub run_command { my $command = shift; print "attempting to run command: $command\n"; - system $command; + my $output = `$command 2>&1`; my $exit_status = $? >> 8; print "ran command: $command, exit status: $exit_status\n"; - return $exit_status; + return ($exit_status, $output); } #///////////////////////////////////////////////////////////////////////////// @@ -286,5 +384,12 @@ EOF sub print_break { my $character = shift; $character = '-' if !defined($character); - print $character x 80 . "\n"; + print $character x 100 . "\n"; +} + +#///////////////////////////////////////////////////////////////////////////// + +sub print_cpan_configuration { + $Data::Dumper::Sortkeys = 1; + print "CPAN configuration:\n" . Dumper($CPAN::Config) . "\n"; }