File: //proc/self/root/scripts.20110531.215904.25158/after_perl_upgrade
#!/usr/bin/perl
# cpanel - after_perl_upgrade Copyright(c) 2010 cPanel, Inc.
# All Rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use Cpanel::Usage ();
my $force = 0;
my $test = 0;
Cpanel::Usage::wrap_options( \@ARGV, \&usage, { 'force' => \$force, 'test' => \$test } );
usage() unless ( $force || $test );
if ( $test && !perl_upgraded() ) {
store_perlversion();
exit 0;
}
print "****Beginning Perl bootstrapping****\n";
reinstall_perlmods();
upgrade_binaries();
store_perlversion();
print "****Finished Perl bootstrapping****\n";
exit 0;
sub perl_upgraded {
# If this script has run before, we have an easy way of testing
if ( -e '/var/cpanel/version/last_perl_version' ) {
if ( open my $ver_fh, '<', '/var/cpanel/version/last_perl_version' ) {
my $last_version = readline($ver_fh);
chomp $last_version;
close $ver_fh;
return 1 if ( $last_version != $] );
}
}
# If the stored previous version looks correct, it's still no guarantee Perl is working properly
my $pid = fork();
if ( !defined $pid ) {
die "Failed to fork new process!\n";
}
elsif ( $pid == 0 ) {
# child
open STDOUT, '>', '/dev/null';
open STDERR, '>', '/dev/null';
# Load several modules to verify they're in place
require DBD::mysql;
require Tie::IxHash;
require Net::DAV::Server;
require XML::LibXML;
require YAML::Syck;
require GDBM_File;
# Test for missing libperl.so on exim binary
exit 1 if ( $^O =~ /freebsd/i && exim_broken() );
exit 0;
}
waitpid( $pid, 0 );
return ( $? != 0 );
}
sub store_perlversion {
if ( !-d '/var/cpanel/version' ) {
mkdir '/var/cpanel/version', 0755;
}
if ( open my $ver_fh, '>', '/var/cpanel/version/last_perl_version' ) {
print $ver_fh $] . "\n";
close $ver_fh;
}
}
sub upgrade_binaries {
# Test exim
if ( $^O =~ /freebsd/i && exim_broken() ) {
print "****Exim appears to be broken...Attempting repair****\n";
system( '/scripts/eximup', '--force' );
}
# Reinstall mysql modules
system '/scripts/perlinstaller', '--force', 'DBD::mysql';
}
sub reinstall_perlmods {
print "****Bootstrapping Perl modules****\n";
# This follows the scheme laid out in the Perl 5.8.8 installer
# We're skipping the version and MD5 cleanups
system( '/scripts/perlinstaller', 'Expect' );
system( '/scripts/perlinstaller', 'CPAN' );
# Also skipping the static list of modules (it just duplicates checkperlmodules)
# Twice just in case
for ( 0 .. 1 ) {
if ( -x '/scripts/checkperlmodules' ) {
system '/scripts/checkperlmodules', '--bootstrap';
system '/scripts/checkperlmodules', '--full';
}
elsif ( -x '/usr/local/cpanel/bin/checkperlmodules' ) {
system '/usr/local/cpanel/bin/checkperlmodules';
}
}
if ( -x '/usr/local/cpanel/bin/rrdtoolcheck' ) {
system '/usr/local/cpanel/bin/rrdtoolcheck';
}
if ( -x '/scripts/magicloader' ) {
system '/scripts/magicloader';
}
}
sub exim_broken {
if ( -e '/usr/sbin/exim' ) {
my $ldd_output = `ldd /usr/sbin/exim`;
if ( $ldd_output =~ /libperl.so\S*\s=>\s*not found/m ) {
return 1;
}
}
return 0;
}
sub usage {
print <<EO_USAGE;
Usage: after_perl_upgrade [options]
Options:
--force Run even if perl has not been upgraded
--test Run only if Perl has been upgraded
--help Brief help information
EO_USAGE
exit 0;
}