????

Your IP : 3.129.195.209


Current Path : /scripts/
Upload File :
Current File : //scripts/phpup

#!/usr/local/cpanel/3rdparty/bin/perl
# cpanel - phpup                                     Copyright 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, '/var/cpanel/perl/easy'; }

use strict;
use Cpanel::DataStore ();
use Cpanel::PHPINI    ();
use Getopt::Param     ();

my $last_ok_file = '/var/cpanel/easy/apache/profile/_last_success.yaml';    # case 3928 #issafe

if ( !-e $last_ok_file ) {
    print "You will need to successfully build PHP via EasyApache before you can use this tool.\n";
    exit;
}

my $prm = Getopt::Param->new(
    {
        'help_coderef' => sub {
            print <<"END_HELP";
$0 - update PHP to the latest
   --help          - this screen
   --force         - rebuild PHP even if its already the latest
   --dryrun        - don't actually do anything just report what would be done

END_HELP

            exit;
        },
    }
);

# start with an easy apache sanity check to solve case 57211
my $sanity_check = '/usr/local/cpanel/scripts/cpanel_easy_sanity_check';
system( $sanity_check, '--quiet' ) if ( -x $sanity_check );

my $last_ok_profile_hr = Cpanel::DataStore::load_ref( $last_ok_file, {} ) or exit;    # load_ref() reports the error

if ( !$last_ok_profile_hr->{'Cpanel::Easy::PHP5'} ) {                                 #issafe
    print "Your last EasyApache build did not have any PHP selected\n";
}
else {
    print "Updating PHP...\n";
    my @only;
    my $phpv = Cpanel::PHPINI::check_installed_php_binaries();

    my $have_run_sanity = 0;

    if ( !$prm->get_param('force') ) {

      PHP_MAIN_VER:
        {
            my $ns = "Cpanel::Easy::PHP5";    #issafe

            if ( eval qq{ require $ns; } ) {
                my ($ea3_latest) = reverse( $ns->versions() );
                $ea3_latest =~ s{\_}{\.}g;
                $ea3_latest = "5\.$ea3_latest";

                my $system_has = '';

              PHP_SYS_VER:
                for my $key ( sort keys %{$phpv} ) {
                    next PHP_SYS_VER if $phpv->{$key}{'version'} ne 5;
                    $system_has = $phpv->{$key}{'long_version'};
                }

                if ( !$system_has ) {
                    print "Could not determine system version of PHP 5, skipping\n";
                }
                elsif ( $system_has eq $ea3_latest ) {
                    print "PHP 5 is already the latest. Use --force to make it rebuild anyway\n";
                }
                else {
                    print "Updating PHP 5 to $ea3_latest from $system_has\n";
                    push @only, "--only=Cpanel::Easy::PHP5";    #issafe
                }
            }
            else {
                print "Could not load $ns.\n";

                if ( !$have_run_sanity ) {
                    print "Getting EasyApache...\n";
                    $have_run_sanity++;
                    system '/usr/local/cpanel/scripts/cpanel_easy_sanity_check';    #issafe
                    redo PHP_MAIN_VER;
                }
                else {
                    print "Aborting since we already tried to fetch the module and its still missing.\n";
                    exit;
                }
            }
        }
    }
    else {
        print "Building PHP 5 as per your last build\n";
        @only = ("--only=Cpanel::Easy::PHP5");                                      #issafe
    }

    if ( $prm->get_param('force') || @only ) {
        if ( $prm->get_param('dryrun') ) {
            print "Not actually running anything as per the 'dryrun' flag\n";
        }
        else {
            system qw( /usr/local/cpanel/scripts/easyapache --always_do_the_latest_phps --build ), "--profile=$last_ok_file", @only;
        }
    }
}