MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/scripts.20110531.215904.25158/checkyum
#!/usr/bin/perl
# cpanel - checkyum                               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 strict;
use Cpanel::SafeFile;
use Getopt::Long;
use Cpanel::Config::LoadCpConf ();
use Cpanel::CleanupStub        ();
use Cpanel::Logger             ();

exit if !-e '/etc/yum.conf' || -e '/etc/checkyumdisable';

my $logger = Cpanel::Logger->new();

Cpanel::CleanupStub::closefds();    # Prevent potential zombie under upcp

my $version = '20.6';
my $cpconf  = Cpanel::Config::LoadCpConf::loadcpconf();

# Configurable Exclude Values
my $kernel      = 1;
my $bind_chroot = 1;
my $perl        = 1;

my $printmsg = 1;
if (@ARGV) {
    $printmsg = 0;
}

GetOptions(
    'kernel!'      => \$kernel,
    'perl!'        => \$perl,
    'bind-chroot!' => \$bind_chroot,
);

print "checkyum version $version\n" if $printmsg;

my %excludes = (
    'ruby'         => 'ruby*',
    'courier'      => 'courier*',
    'dovecot'      => 'dovecot*',
    'nsd'          => 'nsd*',
    'apache'       => 'apache*',
    'mod_ssl'      => 'mod_ssl*',
    'httpd'        => 'httpd*',
    'mysql'        => 'mysql*',
    'squirrelmail' => 'squirrelmail*',
    'php'          => 'php*',
    'spamassassin' => 'spamassassin*',
    'exim'         => 'exim*',
    'pure-ftpd'    => 'pure-ftpd*',
    'proftpd'      => 'proftpd*'
);
my @remove;

# Kernel
if ($kernel) {
    $excludes{'kernel'} = 'kernel kernel-xen kernel-smp kernel-pae kernel-PAE kernel-SMP kernel-hugemem';    # Allow update of kernel-utils
}
elsif ( !-e '/var/cpanel/checkyum-keepkernel' ) {
    push @remove, qw( kernel kernel-smb kernel-hugemem );
}

# Perl
if ($perl) {
    $excludes{'perl'} = 'perl*';                                                                             # Prevent rpm module installs
}
else {
    push @remove, 'perl';
}

# Bind Chroot
if ($bind_chroot) {
    $excludes{'bind-chroot'} = 'bind-chroot';
}
else {
    push @remove, 'bind-chroot';
}

my $has_exclude = 0;
my $has_tol     = 0;
my @UP;

my $la = Cpanel::SafeFile::safeopen( \*YC, '<', '/etc/yum.conf' );
if ( !$la ) {
    $logger->die("Could not read from /etc/yum.conf");
}
while (<YC>) {
    push @UP, $_;
    if (/^\s*exclude\s*=/i) {
        $has_exclude = 1;
    }
    elsif (m/^\s*tolerant=/i) {
        $has_tol = 1;
    }
}
Cpanel::SafeFile::safeclose( \*YC, $la );

my $lb = Cpanel::SafeFile::safeopen( \*UPDATEW, '>', '/etc/yum.conf' );
if ( !$lb ) {
    $logger->die("Could not write to /etc/yum.conf");
}
foreach (@UP) {
    if (m/^\[main\]/i) {
        print UPDATEW;    # Conserve [main]
        if ( !$has_exclude ) {
            print UPDATEW 'exclude=' . join( ' ', values %excludes ) . "\n";
        }
        if ( !$has_tol ) {
            print UPDATEW "tolerant=1\n";
        }
    }
    elsif (m/^\s*exclude\s*=\s*(.*)/) {
        my $pkgs = $1;
        chomp $pkgs;
        $pkgs = update_excludes($pkgs);
        print UPDATEW 'exclude=' . $pkgs . "\n";
    }
    elsif (m/^\s*tolerant\s*=/) {
        print UPDATEW "tolerant=1\n";
    }
    else {
        print UPDATEW;
    }
}

Cpanel::SafeFile::safeclose( \*UPDATEW, $lb );

sub update_excludes {
    my $pkgs = shift || '';
    my @PKGS = split( /\s+/, $pkgs );

    # Clean blank entries
    @PKGS = grep( !m/^\s*$/, @PKGS );

    foreach my $excl ( keys %excludes ) {
        if ( $pkgs !~ m/$excl/ ) {
            push @PKGS, $excludes{$excl};
        }
        else {

            # Remove and readd to ensure proper exclude
            @PKGS = grep( !m/$excl/, @PKGS );
            push @PKGS, $excludes{$excl};
        }
    }
    foreach my $remove (@remove) {
        @PKGS = grep( !m/$remove/, @PKGS );
    }
    return join( ' ', sort @PKGS );
}