File: //scripts.20110531.215904.25158/updatenow
#!/usr/bin/perl
# cpanel - updatenow 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::OSSys ();;
use Cpanel::Update ();
use Cpanel::Config::Sources ();
unless ( @ARGV && $ARGV[0] =~ m/manual/i ) {
print <<'EOM';
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Running updatenow manually may cause /scripts to become
out of sync with the cPanel installation. This can cause
a variety of problems.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
EOM
exit 1;
}
my $updateconf_ref = Cpanel::Update::loadupdateconfig();
if ( $updateconf_ref->{'CPANEL'} =~ m/never/i ) {
die "Not updating scripts because updates are set to NEVER.\n";
}
my $updatepath = Cpanel::Update::getupdatepath( $updateconf_ref->{'CPANEL'} );
my %CPSRC = Cpanel::Config::Sources::loadcpsources();
# Make sure cpanelsync.static exists
if ( !-e '/scripts' ) {
mkdir '/scripts';
}
if ( !-e '/scripts/cpanelsync.static' || -z _ ) {
system( 'wget', '-O', '/scripts/cpanelsync.static', "http://$CPSRC{'HTTPUPDATE'}/cpanelsync/$updatepath/scripts/cpanelsync.static" );
if ( !-e '/scripts/cpanelsync.static' || -z _ ) {
system( 'curl', '-o', '/scripts/cpanelsync.static', "http://$CPSRC{'HTTPUPDATE'}/cpanelsync/$updatepath/scripts/cpanelsync.static" );
}
if ( !-e '/scripts/cpanelsync.static' || -z _ ) {
system( 'fetch', '-o', '/scripts/cpanelsync.static', "http://$CPSRC{'HTTPUPDATE'}/cpanelsync/$updatepath/scripts/cpanelsync.static" );
}
if ( !-e '/scripts/cpanelsync.static' || -z _ ) {
die "Unable to sync: $!";
}
}
my $cpanelsync = -e '/scripts/cpanelsync' ? '/scripts/cpanelsync' : '/scripts/cpanelsync.static';
if ( !-x $cpanelsync ) {
chmod 0700, $cpanelsync;
if ( !-x $cpanelsync ) {
die "Unable to update scripts. $cpanelsync is not executable: $!";
}
}
my $current_updatenow_mtime = ( stat('/scripts/updatenow') )[9] || 0;
print "Sync Source: http://$CPSRC{'HTTPUPDATE'}/$updatepath/Cpanel\n";
if ( !-e '/usr/local/cpanel/Cpanel' ) {
system 'mkdir', '-p', '/usr/local/cpanel/Cpanel';
}
system $cpanelsync, $CPSRC{'HTTPUPDATE'}, "/cpanelsync/${updatepath}/Cpanel", '/usr/local/cpanel/Cpanel';
if ( $? >> 8 != 0 ) {
if ( $cpanelsync !~ m/\.static/ && grep { $_ ne 'retry' } @ARGV ) {
print "Trying again with $cpanelsync.static\n";
unlink $cpanelsync;
exec '/scripts/updatenow.static', @ARGV, 'retry';
}
die "Failed to execute $cpanelsync\n";
}
print "Sync Source: http://$CPSRC{'HTTPUPDATE'}/$updatepath/scripts\n";
if ( !-e '/scripts' ) {
system 'mkdir', '/scripts';
}
system $cpanelsync, $CPSRC{'HTTPUPDATE'}, "/cpanelsync/${updatepath}/scripts", '/scripts';
if ( $? >> 8 != 0 ) {
if ( $cpanelsync !~ m/\.static/ && grep { $_ ne 'retry' } @ARGV ) {
print "Trying again with $cpanelsync.static\n";
unlink $cpanelsync;
exec '/scripts/updatenow.static', @ARGV, 'retry';
}
die "Failed to execute $cpanelsync\n";
}
my $new_updatenow_mtime = ( stat('/scripts/updatenow') )[9];
# If we received a new updatenow, then run it
if ( $new_updatenow_mtime && $new_updatenow_mtime ne $current_updatenow_mtime ) {
print "Resyncing due to update of /scripts/updatenow\n";
exec '/scripts/updatenow', @ARGV;
}