File: //proc/self/root/scripts.20110531.215904.25158/patch_xml_libxml
#!/usr/bin/perl
# cpanel - patch_xml_libxml 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::SafeFile ();
use Cpanel::LoadFile ();
use Cpanel::SafeRun::Simple ();
use Cpanel::Logger ();
eval 'local $SIG{__DIE__}; use XML::LibXML;';
my $module_path = $INC{'XML/LibXML.pm'};
my $logger = Cpanel::Logger->new();
my $txt = Cpanel::LoadFile::loadfile($module_path);
if ( $txt !~ /(require|use) DynaLoader/ ) { exit; }
if ( $txt =~ /XSLoader/ ) { exit; }
print "Removing bloated DynaLoader Dep from XML::LibXML.\n";
my $mod_fh = Cpanel::SafeFile::safeopen( \*ER, '+<', $module_path );
if ( !$mod_fh ) {
$logger->warn("Could not edit $module_path");
}
else {
my @EN = <ER>;
seek( ER, 0, 0 );
my $inconfig = 0;
foreach (@EN) {
s/require DynaLoader/use XSLoader/g;
s/use DynaLoader/use XSLoader/g;
s/DynaLoader/XSLoader/g;
s/^\s*bootstrap.*/XSLoader::load 'XML::LibXML', \$VERSION\;/g;
print ER $_;
}
truncate( ER, tell(ER) );
Cpanel::SafeFile::safeclose( \*ER, $mod_fh );
}
my $is_ok = Cpanel::SafeRun::Simple::saferun( ( -e '/usr/local/cpanel/scripts/check_xml_libxml' ? '/usr/local/cpanel/scripts/check_xml_libxml' : '/scripts/check_xml_libxml' ) );
chomp($is_ok);
if ( !$is_ok || $is_ok ne 'ok' ) {
print "Patching Failed, restoring previous XML::LibXML!\n";
my $mod_fh2 = Cpanel::SafeFile::safeopen( \*ER, '>', $module_path );
if ( !$mod_fh2 ) {
$logger->warn("Could not write to $module_path");
}
else {
print ER $txt;
Cpanel::SafeFile::safeclose( \*ER, $mod_fh2 );
}
}
$ENV{XML::LibXML_PUREPERL} = 1;
$is_ok = Cpanel::SafeRun::Simple::saferun( ( -e '/usr/local/cpanel/scripts/check_xml_libxml' ? '/usr/local/cpanel/scripts/check_xml_libxml' : '/scripts/check_xml_libxml' ) );
chomp($is_ok);
if ( !$is_ok || $is_ok ne 'ok' ) {
print "Patching Failed, restoring previous XML::LibXML!\n";
my $mod_fh3 = Cpanel::SafeFile::safeopen( \*ER, '>', $module_path );
if ( !$mod_fh3 ) {
$logger->warn("Could not write to $module_path");
}
else {
print ER $txt;
Cpanel::SafeFile::safeclose( \*ER, $mod_fh3 );
}
}
$is_ok = Cpanel::SafeRun::Simple::saferun( ( -e '/usr/local/cpanel/scripts/check_xml_libxml' ? '/usr/local/cpanel/scripts/check_xml_libxml' : '/scripts/check_xml_libxml' ) );
chomp($is_ok);
if ( !$is_ok || $is_ok ne 'ok' ) {
system '/scripts/perlinstaller', '--force', 'XML::LibXML';
}