-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-install Softaculous after upgrade
Case RE-846: It was reported that the Softaculous plugin for cPanel was displaying blank pages after ELevate, and that a re-install of the plugin fixed this issue. That seems reasonable, so detect Softaculous and re-install if present. Changelog: Re-install Softaculous after upgrade.
- Loading branch information
Sloane Bernstein
committed
Nov 5, 2024
1 parent
1749bb1
commit d2637a7
Showing
5 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package Elevate::Components::Softaculous; | ||
|
||
=encoding utf-8 | ||
=head1 NAME | ||
Elevate::Components::Softaculous | ||
=head2 pre_distro_upgrade | ||
If we can query the version of Softaculous through their CLI tool, it is installed. | ||
=head2 post_distro_upgrade | ||
If Softaculous is installed, re-install it after the upgrade. | ||
NOTE: This needs to happen after cPanel is updated to work with the new OS, since Softaculous relies on cPanel PHP. | ||
=cut | ||
|
||
use cPstrict; | ||
|
||
use Elevate::Fetch (); | ||
use Elevate::StageFile (); | ||
|
||
use Cpanel::Binaries (); | ||
use Cpanel::SafeRun::Object (); | ||
|
||
use Log::Log4perl qw(:easy); | ||
|
||
use parent qw{Elevate::Components::Base}; | ||
|
||
use Simple::Accessor qw(cli_path); | ||
|
||
sub _build_cli_path { return '/usr/local/cpanel/whostmgr/docroot/cgi/softaculous/cli.php' } | ||
|
||
sub pre_distro_upgrade ($self) { | ||
|
||
return unless -r $self->cli_path; | ||
|
||
my $sr = _run_script( $self->cli_path ); | ||
|
||
return if $sr->exec_failed() || $sr->to_exception(); | ||
|
||
my $version = $sr->stdout() // ''; | ||
chomp $version; | ||
|
||
if ( length $version ) { | ||
INFO('Softaculous has been detected. The system will re-install that software after the distro upgrade.'); | ||
Elevate::StageFile::update_stage_file( { softaculous => $version } ); | ||
} | ||
|
||
return; | ||
} | ||
|
||
# split out for mocking purposes | ||
sub _run_script ($path) { | ||
return Cpanel::SafeRun::Object->new( | ||
program => Cpanel::Binaries::path('php'), | ||
args => [ $path, '--version' ], | ||
); | ||
} | ||
|
||
sub post_distro_upgrade ($self) { | ||
|
||
my $version = Elevate::StageFile::read_stage_file( 'softaculous', '' ); | ||
return unless length $version; | ||
|
||
my $path = Elevate::Fetch::script( 'https://files.softaculous.com/install.sh', 'softaculous_install' ); | ||
|
||
if ($path) { | ||
INFO('Re-installing Softaculous:'); | ||
if ( !$self->ssystem( $path, '--reinstall' ) ) { | ||
ERROR('Re-installation of Softaculous failed.'); | ||
} | ||
} | ||
else { | ||
ERROR('Failed to download Softaculous installer.'); | ||
} | ||
|
||
return; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/local/cpanel/3rdparty/bin/perl | ||
|
||
# Copyright 2024 WebPros International, LLC | ||
# All rights reserved. | ||
# copyright@cpanel.net http://cpanel.net | ||
# This code is subject to the cPanel license. Unauthorized copying is prohibited. | ||
|
||
package test::cpev::components; | ||
|
||
use FindBin; | ||
|
||
use Test2::V0; | ||
use Test2::Tools::Explain; | ||
use Test2::Plugin::NoWarnings; | ||
use Test2::Tools::Exception; | ||
use Test2::Tools::Mock; | ||
|
||
use Test::MockModule qw/strict/; | ||
|
||
use lib $FindBin::Bin . "/lib"; | ||
use Test::Elevate; | ||
|
||
use Cpanel::Exception (); | ||
use File::Temp (); | ||
|
||
use cPstrict; | ||
|
||
my $comp = cpev->new->get_component('Softaculous'); | ||
|
||
{ | ||
note "Checking pre_distro_upgrade"; | ||
|
||
ok( length $comp->cli_path, 'cli_path defaults to a reasonable string' ); | ||
|
||
my $mock_run = Test::MockModule->new('Elevate::Components::Softaculous'); | ||
|
||
$comp->cli_path('/file/does/not/exist'); | ||
$mock_run->redefine( _run_script => sub { die "I shouldn't run yet!" } ); | ||
|
||
ok( lives { $comp->pre_distro_upgrade() }, "Short-circuits if Softaculous CLI script does not exist" ); | ||
no_messages_seen(); | ||
|
||
my $tempfile = File::Temp->new(); | ||
$comp->cli_path( $tempfile->filename ); | ||
|
||
my ( $stdout, $exec_failed, $exception ); | ||
$mock_run->redefine( | ||
_run_script => sub { | ||
return mock {} => ( | ||
add => [ | ||
stdout => sub { return $stdout }, | ||
exec_failed => sub { return $exec_failed }, | ||
to_exception => sub { return $exception }, | ||
], | ||
); | ||
} | ||
); | ||
|
||
$stdout = '1.2.3'; | ||
$exec_failed = 0; | ||
$exception = undef; | ||
|
||
ok( lives { $comp->pre_distro_upgrade() }, "Runs correctly with no errors" ); | ||
message_seen( INFO => 'Softaculous has been detected. The system will re-install that software after the distro upgrade.' ); | ||
no_messages_seen(); | ||
|
||
$exec_failed = 1; | ||
ok( lives { $comp->pre_distro_upgrade() }, "Short-circuits if SafeRun could not exec()" ); | ||
no_messages_seen(); | ||
|
||
$exec_failed = 0; | ||
$exception = Cpanel::Exception::create( 'ProcessFailed::Error' => [ error_code => 1 ] ); | ||
ok( lives { $comp->pre_distro_upgrade() }, "Short-circuits if script exits with error" ); | ||
no_messages_seen(); | ||
|
||
$exception = undef; | ||
$stdout = undef; | ||
ok( lives { $comp->pre_distro_upgrade() }, "Runs correctly but returns no data (can this even happen?)" ); | ||
no_messages_seen(); | ||
} | ||
|
||
done_testing(); |