Skip to content

Commit

Permalink
Merge pull request #480 from timmullin/RE-502
Browse files Browse the repository at this point in the history
Create new component to handle R1Soft agent
  • Loading branch information
toddr authored Jul 26, 2024
2 parents 2ef7a18 + b2530bd commit 77eb47d
Show file tree
Hide file tree
Showing 8 changed files with 614 additions and 0 deletions.
173 changes: 173 additions & 0 deletions elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ BEGIN { # Suppress load of all of these at earliest point.
$INC{'Elevate/Components/AutoSSL.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/DatabaseUpgrade.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/ELS.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/Components/R1Soft.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/OS.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/OS/CentOS7.pm'} = 'script/elevate-cpanel.PL.static';
$INC{'Elevate/OS/CloudLinux7.pm'} = 'script/elevate-cpanel.PL.static';
Expand Down Expand Up @@ -118,6 +119,17 @@ BEGIN { # Suppress load of all of these at earliest point.

use constant ETH_FILE_PREFIX => q[/etc/sysconfig/network-scripts/ifcfg-];

use constant R1SOFT_REPO => 'r1soft';
use constant R1SOFT_REPO_FILE => '/etc/yum.repos.d/r1soft.repo';
use constant R1SOFT_MAIN_AGENT_PACKAGE => 'serverbackup-agent';
use constant R1SOFT_AGENT_PACKAGES => qw{
r1soft-getmodule
serverbackup-agent
serverbackup-async-agent-2-6
serverbackup-enterprise-agent
serverbackup-setup
};

1;

} # --- END lib/Elevate/Constants.pm
Expand Down Expand Up @@ -2661,6 +2673,7 @@ EOS
ssystem
ssystem_and_die
ssystem_capture_output
ssystem_hide_and_capture_output
remove_rpms_from_repos
};

Expand Down Expand Up @@ -5527,6 +5540,133 @@ EOS

} # --- END lib/Elevate/Components/ELS.pm

{ # --- BEGIN lib/Elevate/Components/R1Soft.pm

package Elevate::Components::R1Soft;

use cPstrict;

use Elevate::Constants ();
use Elevate::StageFile ();

use Cpanel::Pkgr ();

use File::Slurper ();

# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }

# use Elevate::Components::Base();
our @ISA;
BEGIN { push @ISA, qw(Elevate::Components::Base); }

sub pre_leapp ($self) {

my $r1soft_agent_installed = 0;
my $r1soft_repo_present = 0;
my $r1soft_repo_enabled = 0;

if ( Cpanel::Pkgr::is_installed(Elevate::Constants::R1SOFT_MAIN_AGENT_PACKAGE) ) {
$r1soft_agent_installed = 1;

my @repo_list = $self->yum->repolist_enabled();

if ( scalar grep { index( $_, Elevate::Constants::R1SOFT_REPO ) == 0 } @repo_list ) {
$r1soft_repo_present = 1;
$r1soft_repo_enabled = 1;
}
else {
@repo_list = $self->yum->repolist_all();

if ( scalar grep { index( $_, Elevate::Constants::R1SOFT_REPO ) == 0 } @repo_list ) {
$r1soft_repo_present = 1;
}
}

$self->yum->remove(Elevate::Constants::R1SOFT_AGENT_PACKAGES);
}

Elevate::StageFile::update_stage_file(
{
r1soft => {
agent_installed => $r1soft_agent_installed,
repo_present => $r1soft_repo_present,
repo_enabled => $r1soft_repo_enabled,
}
}
);

return;
}

sub post_leapp ($self) {

my $r1soft_info = Elevate::StageFile::read_stage_file('r1soft');

return unless $r1soft_info->{agent_installed};

$self->yum->install('kernel-devel');

if ( !$r1soft_info->{repo_present} ) {

$self->_create_r1soft_repo();
}
else {
$self->_enable_r1soft_repo() unless $r1soft_info->{repo_enabled};
}

$self->yum->install(Elevate::Constants::R1SOFT_AGENT_PACKAGES);

if ( !$r1soft_info->{repo_present} || !$r1soft_info->{repo_enabled} ) {
$self->_disable_r1soft_repo();
}

return;
}

sub _enable_r1soft_repo ($self) {
return $self->_run_yum_config_manager( '--enable', Elevate::Constants::R1SOFT_REPO );
}

sub _disable_r1soft_repo ($self) {
return $self->_run_yum_config_manager( '--disable', Elevate::Constants::R1SOFT_REPO );
}

sub _run_yum_config_manager ( $self, @args ) {
my $yum_config = Cpanel::Binaries::path('yum-config-manager');

my $err = $self->ssystem( $yum_config, @args );
ERROR("Error running $yum_config: $err") if $err;

return $err;
}

sub _create_r1soft_repo ($self) {

my $yum_repo_contents = <<~"EOS";
[r1soft]
name=R1Soft Repository Server
baseurl=https://repo.r1soft.com/yum/stable/\$basearch/
enabled=1
gpgcheck=0
EOS

if ( -e Elevate::Constants::R1SOFT_REPO_FILE ) {
ERROR( "Cannot create R1Soft repo. File already exists: " . Elevate::Constants::R1SOFT_REPO_FILE );
return;
}

File::Slurper::write_binary( Elevate::Constants::R1SOFT_REPO_FILE, $yum_repo_contents );

chmod 0644, Elevate::Constants::R1SOFT_REPO_FILE;

return;
}

1;

} # --- END lib/Elevate/Components/R1Soft.pm

{ # --- BEGIN lib/Elevate/OS.pm

package Elevate::OS;
Expand Down Expand Up @@ -5786,6 +5926,7 @@ EOS
qr/^jetapps-(?:stable|beta|edge)$/,
'kernelcare',
'updates',
'r1soft',
qr/^wp-toolkit-(?:cpanel|thirdparties)$/,
),
vetted_mysql_yum_repo_ids;
Expand Down Expand Up @@ -7628,6 +7769,8 @@ EOS

use cPstrict;

use Elevate::Constants ();

# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }

Expand Down Expand Up @@ -7680,6 +7823,32 @@ EOS
return;
}

sub repolist_all ($self) {
return $self->repolist("all");
}

sub repolist_enabled ($self) {
return $self->repolist("enabled");
}

sub repolist ( $self, @options ) {
my $pkgmgr = $self->pkgmgr;

my $out = $self->cpev->ssystem_hide_and_capture_output( $pkgmgr, '-q', 'repolist', @options );
my @lines = @{ $out->{stdout} };

shift @lines;

my @repos;
foreach my $line (@lines) {
my $repo = ( split( '\s+', $line ) )[0];

push @repos, $repo;
}

return @repos;
}

sub get_extra_packages ($self) {
my $pkgmgr = $self->pkgmgr;

Expand Down Expand Up @@ -7717,6 +7886,7 @@ EOS
next if $package eq 'filesystem';
next if $package eq 'basesystem';
next if $package eq 'virt-what';
next if ( scalar grep { $_ eq $package } Elevate::Constants::R1SOFT_AGENT_PACKAGES );

push @extra_packages, { package => $package, version => $version, arch => $arch };
}
Expand Down Expand Up @@ -8018,6 +8188,7 @@ use Elevate::Components::SSH ();
use Elevate::Components::AutoSSL ();
use Elevate::Components::DatabaseUpgrade ();
use Elevate::Components::ELS ();
use Elevate::Components::R1Soft ();

# - fatpack OS
use Elevate::OS ();
Expand Down Expand Up @@ -9050,6 +9221,7 @@ sub run_final_components_pre_leapp ($self) {
$self->run_component_once( 'LiteSpeed' => 'pre_leapp' );
$self->run_component_once( 'AbsoluteSymlinks' => 'pre_leapp' );
$self->run_component_once( 'ELS' => 'pre_leapp' );
$self->run_component_once( 'R1Soft' => 'pre_leapp' );
$self->run_component_once( 'RpmDB' => 'pre_leapp' ); # remove the RPMs last

return;
Expand All @@ -9076,6 +9248,7 @@ sub post_leapp_update_restore ($self) {
$self->run_component_once( 'KernelCare' => 'post_leapp' );
$self->run_component_once( 'NixStats' => 'post_leapp' );
$self->run_component_once( 'LiteSpeed' => 'post_leapp' );
$self->run_component_once( 'R1Soft' => 'post_leapp' );

return;
}
Expand Down
1 change: 1 addition & 0 deletions lib/Elevate/Components/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BEGIN {
ssystem
ssystem_and_die
ssystem_capture_output
ssystem_hide_and_capture_output
remove_rpms_from_repos
};

Expand Down
Loading

0 comments on commit 77eb47d

Please sign in to comment.