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: //scripts.20110531.215904.25158/ensurepkg
#!/usr/bin/perl

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

use IPC::Open3;
use Cpanel::OSSys;

my ( $system, $release, $machine ) = ( Cpanel::OSSys::uname() )[ 0, 2, 4 ];

$| = 1;
require '/scripts/HTTPreq.pm';
require '/scripts/pkgmap.pl';
require '/scripts/installport.pl';

my $safe     = 0;
my $quiet    = 0;
my $usecache = 0;
my $force    = 0;

while ( $#ARGV != -1 ) {
    $_ = $ARGV[0];
    if (/^\-\-/) {
        my $arg = shift(@ARGV);
        $arg =~ s/^\-\-//g;
        $arg =~ tr/[A-Z]/[a-z]/;
        if ( $arg eq "safe" )     { $safe     = 1; }
        if ( $arg eq "quiet" )    { $quiet    = 1; }
        if ( $arg eq "usecache" ) { $usecache = 1; }
        if ( $arg eq "force" )    { $force    = 1; }
    }
    else {
        last;
    }
}

foreach my $pkgarg (@ARGV) {

    if ( $system =~ /freebsd/i ) {
        my @PKGVERSIONS;

        if ( !-e "/root/.cpbsdpkgs" ) {
            mkdir( "/root/.cpbsdpkgs", 0700 );
        }

        my %PKG;
        if ( -e "/root/.cpbsdpkgs/pkg_version" ) {
            my $umtime;
            ( undef, undef, undef, undef, undef, undef, undef, undef, undef, $umtime, undef, undef, undef ) = stat("/root/.cpbsdpkgs/pkg_version");
            if ( ( $umtime + 500 ) > time() ) {
                open( PKGVERSION, "/root/.cpbsdpkgs/pkg_version" );
                while (<PKGVERSION>) {
                    chomp();
                    push( @PKGVERSIONS, $_ );
                }
                close(PKGVERSION);
            }
            else {
                print "Creating package version list....(cached version is too old)...";
                @PKGVERSIONS = split( /\n/, `pkg_version` );
                print "Done\n";
            }
        }
        else {
            print "Creating package version list....(no cached version)...";
            @PKGVERSIONS = split( /\n/, `pkg_version` );
            print "Done\n";
        }

        open( PKGV, ">/root/.cpbsdpkgs/pkg_version" );
        foreach (@PKGVERSIONS) {
            print PKGV;
            print PKGV "\n";
        }
        close(PKGV);

        foreach (@PKGVERSIONS) {
            if (/^(\S+)[\s\t]*(\S+)/) {
                my $pkgname = $1;
                my $pkgver  = $2;
                if ( $PKG{$pkgname} eq "=" ) { next; }
                if ( $PKG{$pkgname} eq ">" ) { next; }
                $pkgname =~ s/-${machine}$//g;
                $PKG{$pkgname} = $pkgver;
            }
        }

        my $hasexim4 = 0;

        if ( $pkgarg =~ /exim/i ) {
            @exims = split( /\n/, getpkginfo("exim") );
            @exims = grep( /^exim-\d+/, @exims );
            foreach (@exims) {
                if (/^exim-4/) { $hasexim4 = 1; }
            }
            if ( $hasexim4 == 0 ) { $PKG{'exim'} = ""; }
        }

        if ( $force || !$PKG{$pkgarg} ) {
            installport( $pkgarg, undef, $force );
            if ( length($pkgarg) >= 3 && $#PKGVERSIONS > -1 ) {
                @PKGVERSIONS = grep( !/^\Q${pkgarg}\E/, @PKGVERSIONS );
                open( PKGV, ">/root/.cpbsdpkgs/pkg_version" );
                foreach (@PKGVERSIONS) {
                    print PKGV;
                    print PKGV "\n";
                }
                print PKGV `pkg_version -s ${pkgarg} 2>/dev/null`;
                close(PKGV);
            }
        }
        else {
            if ( !$quiet ) { print "$pkgarg is installed\n"; }
        }

        next();
    }

}

sub saferunnoerror {
    my (@PROGA) = @_;
    my ($output);
    open( WNULL, ">/dev/null" );
    open( RNULL, "</dev/null" );
    open3( "<&RNULL", \*MPROG, ">&WNULL", @PROGA );
    while (<MPROG>) { $output .= $_; }
    close(MPROG);
    close(RNULL);
    close(WNULL);
    return ($output);
}