#!/usr/bin/perl
# cpanel - autofixer2/scalarutil                   Copyright(c) 2013 cPanel, Inc.
#                                                            All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use strict;

BEGIN { unshift @INC, "/usr/local/cpanel"; }

open( STDERR, ">", "/dev/null" ) or 1;

open( my $sysinfo, "<", "/var/cpanel/sysinfo.config" ) or exit 0;
my @si = <$sysinfo>;
close($sysinfo);

exit 0 if !grep { /^rpm_dist_ver\s*=\s*5/ } @si;

system( "/usr/bin/perl", '-MList::Util', '-e', '1' );
exit 0 unless $?;

my @lutils = `for f in \$(find /usr/lib /usr/lib64 -wholename '*/List/Util.pm' 2>/dev/null); do grep -l 'package List::Util;' \$f; done`;
chomp @lutils;

my $interesting = 0;
foreach my $util (@lutils) {
    my $response = `rpm -qf '$util'`;
    if ( $response =~ /is not owned by any package/ ) {
        rename $util, "$util.off";
        $interesting++;
        print "Found unexpected List::Util at $util.";
    }
}

if ($interesting) {
    system( "/usr/local/cpanel/scripts/perlinstaller", "--force", "List::Util" );
}

exit 0;
