Skip to content

Commit

Permalink
Merge pull request #535 from cpanel/RE-252
Browse files Browse the repository at this point in the history
Move package manager logic behind abstract class
  • Loading branch information
toddr authored Oct 30, 2024
2 parents 37feb64 + 3a44921 commit a419588
Show file tree
Hide file tree
Showing 42 changed files with 1,913 additions and 1,237 deletions.
1,682 changes: 986 additions & 696 deletions elevate-cpanel

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions lib/Elevate/Components/Acronis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Re-install the agent.
use cPstrict;

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

use Cpanel::Pkgr ();
Expand All @@ -36,7 +37,7 @@ sub pre_distro_upgrade ($self) {

return unless Cpanel::Pkgr::is_installed(Elevate::Constants::ACRONIS_BACKUP_PACKAGE);

$self->yum->remove(
Elevate::PkgMgr::remove(
Elevate::Constants::ACRONIS_BACKUP_PACKAGE,
Elevate::Constants::ACRONIS_OTHER_PACKAGES
);
Expand All @@ -50,7 +51,7 @@ sub post_distro_upgrade ($self) {

return unless Elevate::StageFile::read_stage_file('reinstall')->{'acronis'};

$self->dnf->install(Elevate::Constants::ACRONIS_BACKUP_PACKAGE);
Elevate::PkgMgr::install(Elevate::Constants::ACRONIS_BACKUP_PACKAGE);

return;
}
Expand Down
16 changes: 0 additions & 16 deletions lib/Elevate/Components/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ use Cpanel::JSON ();

use Simple::Accessor qw(
components
rpm
yum
dnf
);

use Log::Log4perl qw(:easy);
Expand All @@ -37,7 +34,6 @@ BEGIN {
ssystem_and_die
ssystem_capture_output
ssystem_hide_and_capture_output
remove_rpms_from_repos
};

foreach my $subname (@_DELEGATE_TO_CPEV) {
Expand All @@ -61,18 +57,6 @@ sub _build_components {
Carp::confess(q[Missing components]);
}

sub _build_rpm ($self) {
return Elevate::RPM->new( cpev => $self );
}

sub _build_yum ($self) {
return Elevate::YUM->new( cpev => $self );
}

sub _build_dnf ($self) {
return Elevate::DNF->new( cpev => $self );
}

sub cpev ($self) {
return $self->components->cpev;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Elevate/Components/CCS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use Cpanel::JSON ();
use Cpanel::Pkgr ();

use Elevate::Notify ();
use Elevate::PkgMgr ();
use Elevate::StageFile ();

use Log::Log4perl qw(:easy);
Expand Down Expand Up @@ -93,7 +94,7 @@ sub remove_ccs_and_dependencies ($self) {
my @ccs_dependencies;
push @ccs_dependencies, ZPUSH_PACKAGE();

$self->yum->remove( CCS_PACKAGE(), @ccs_dependencies );
Elevate::PkgMgr::remove( CCS_PACKAGE(), @ccs_dependencies );

return;
}
Expand Down Expand Up @@ -304,7 +305,7 @@ sub _install_ccs_and_dependencies ($self) {

push @packages_to_install, ZPUSH_PACKAGE() if Elevate::StageFile::read_stage_file('zpush_installed');

$self->dnf->install(@packages_to_install);
Elevate::PkgMgr::install(@packages_to_install);

return;
}
Expand Down
11 changes: 6 additions & 5 deletions lib/Elevate/Components/EA4.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use cPstrict;
use Elevate::Constants ();
use Elevate::EA4 ();
use Elevate::OS ();
use Elevate::PkgMgr ();
use Elevate::StageFile ();

use Cpanel::JSON ();
Expand Down Expand Up @@ -89,7 +90,7 @@ sub _backup_ea4_profile ($self) {
sub _cleanup_rpm_db ($self) {

# remove all ea- packages
$self->yum->remove('ea-*');
Elevate::PkgMgr::remove('ea-*');

return;
}
Expand All @@ -101,8 +102,8 @@ sub _restore_ea_addons ($self) {
INFO("Restoring ea-nginx");

# ea profile restore it in a broken state - remove & reinstall
$self->ssystem(qw{/usr/bin/rpm -e --nodeps ea-nginx});
$self->ssystem_and_die(qw{/usr/bin/yum install -y ea-nginx});
Elevate::PkgMgr::remove_no_dependencies('ea-nginx');
Elevate::PkgMgr::install('ea-nginx');

return;
}
Expand Down Expand Up @@ -145,7 +146,7 @@ sub _backup_config_files ($self) {

Elevate::StageFile::remove_from_stage_file('ea4_config_files');

my $ea4_config_files = $self->rpm->get_config_files_for_pkg_prefix('ea-');
my $ea4_config_files = Elevate::PkgMgr::get_config_files_for_pkg_prefix('ea-');

Elevate::StageFile::update_stage_file( { ea4_config_files => $ea4_config_files } );

Expand Down Expand Up @@ -174,7 +175,7 @@ sub _restore_config_files ($self) {
@config_files_to_restore = grep { !$config_files_to_ignore{$key}{$_} } @config_files_to_restore;
}

$self->rpm->restore_config_files(@config_files_to_restore);
Elevate::PkgMgr::restore_config_files(@config_files_to_restore);
}

return;
Expand Down
5 changes: 3 additions & 2 deletions lib/Elevate/Components/ELS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ noop

use cPstrict;

use Elevate::OS ();
use Elevate::OS ();
use Elevate::PkgMgr ();

use Cpanel::Pkgr ();
use Log::Log4perl qw(:easy);
Expand All @@ -46,7 +47,7 @@ sub pre_distro_upgrade ($self) {
}
}

$self->yum->remove(ELS_PACKAGE) if Cpanel::Pkgr::is_installed(ELS_PACKAGE);
Elevate::PkgMgr::remove(ELS_PACKAGE) if Cpanel::Pkgr::is_installed(ELS_PACKAGE);

return;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Elevate/Components/Imunify.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use Elevate::Constants ();
use Elevate::Fetch ();
use Elevate::Notify ();
use Elevate::OS ();
use Elevate::PkgMgr ();
use Elevate::StageFile ();

use Cwd ();
Expand Down Expand Up @@ -71,7 +72,7 @@ sub post_distro_upgrade ($self) {
sub _capture_imunify_packages ($self) {

# only capture the imunify packages
my @packages = grep { m/^imunify-/ } cpev::get_installed_rpms_in_repo(qw{ imunify imunify360 });
my @packages = grep { m/^imunify-/ } Elevate::PkgMgr::get_installed_pkgs_in_repo(qw{ imunify imunify360 });

return unless scalar @packages;

Expand All @@ -89,7 +90,7 @@ sub _restore_imunify_packages ($self) {
foreach my $pkg (@$packages) {
next unless Cpanel::Pkgr::is_installed($pkg);
INFO("Try to reinstall Imunify package: $pkg");
$self->ssystem( qw{ /usr/bin/dnf -y install }, $pkg );
Elevate::PkgMgr::install($pkg);
}

return;
Expand Down Expand Up @@ -262,7 +263,7 @@ sub _remove_imunify_360 ($self) {
Elevate::StageFile::update_stage_file( { 'reinstall' => { 'imunify360' => $product_type } } );

# Cleanup any lingering packages.
$self->remove_rpms_from_repos('imunify');
Elevate::PkgMgr::remove_pkgs_from_repos('imunify');

return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Elevate/Components/InfluxDB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Reinstall influxdb if it was installed
use cPstrict;

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

use Cpanel::Pkgr ();
Expand All @@ -48,7 +49,7 @@ sub post_distro_upgrade ($self) {
return unless Elevate::StageFile::read_stage_file('reinstall')->{'influxdb'};

INFO("Re-installing telegraf for influxdb");
$self->ssystem_and_die(qw{/usr/bin/yum -y reinstall telegraf});
Elevate::PkgMgr::reinstall('telegraf');

return;
}
Expand Down
13 changes: 8 additions & 5 deletions lib/Elevate/Components/JetBackup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use cPstrict;

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

use Cpanel::Pkgr ();
Expand All @@ -40,14 +41,14 @@ sub pre_distro_upgrade ($self) {

return unless Cpanel::Pkgr::is_installed('jetbackup5-cpanel');

my $repos = cpev::yum_list();
my $repos = Elevate::PkgMgr::pkg_list();
my $jetbackup_tier =
$repos->{'jetapps-stable'} ? 'jetapps-stable'
: $repos->{'jetapps-edge'} ? 'jetapps-edge'
: $repos->{'jetapps-beta'} ? 'jetapps-beta'
: 'jetapps-stable'; # Just give up and choose stable if you can't guess.
INFO("Jetbackup tier '$jetbackup_tier' detected. Not removing jetbackup. Will re-install it after elevate.");
my @reinstall = cpev::get_installed_rpms_in_repo(qw/jetapps jetapps-stable jetapps-beta jetapps-edge/);
my @reinstall = Elevate::PkgMgr::get_installed_pkgs_in_repo(qw/jetapps jetapps-stable jetapps-beta jetapps-edge/);
unshift @reinstall, $jetbackup_tier;

my $data = {
Expand All @@ -58,7 +59,7 @@ sub pre_distro_upgrade ($self) {
Elevate::StageFile::update_stage_file( { 'reinstall' => { 'jetbackup' => $data } } );

# Remove this package because leapp will remove it as it depends on libzip.so.2 which isn't available in 8.
$self->ssystem(qw{/usr/bin/rpm -e --nodeps jetphp81-zip});
Elevate::PkgMgr::remove_no_dependencies('jetphp81-zip');

return;
}
Expand All @@ -73,8 +74,10 @@ sub post_distro_upgrade ($self) {
my $tier = $data->{tier};
my @packages = $data->{packages}->@*;

$self->ssystem( qw{/usr/bin/yum -y install --enablerepo=jetapps}, "--enablerepo=$tier", 'jetphp81-zip' );
$self->ssystem( qw{/usr/bin/yum -y update --enablerepo=jetapps}, "--enablerepo=$tier", @packages );
my $pkgmgr_options = [ '--enablerepo=jetapps', "--enablerepo=$tier" ];

Elevate::PkgMgr::install_with_options( $pkgmgr_options, ['jetphp81-zip'] );
Elevate::PkgMgr::update_with_options( $pkgmgr_options, \@packages );

return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Elevate/Components/Kernel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use cPstrict;

use Elevate::Constants ();
use Elevate::OS ();
use Elevate::PkgMgr ();

use Cwd ();
use Log::Log4perl qw(:easy);
Expand All @@ -39,7 +40,7 @@ sub post_distro_upgrade ($self) {

sub _kernel_check ($self) {

my @kernel_rpms = $self->rpm->get_installed_rpms();
my @kernel_rpms = Elevate::PkgMgr::get_installed_pkgs();
@kernel_rpms = sort grep { m/^kernel-\S+el7/ } @kernel_rpms;

return unless @kernel_rpms;
Expand Down
3 changes: 2 additions & 1 deletion lib/Elevate/Components/KernelCare.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use cPstrict;

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

use Cwd ();
Expand Down Expand Up @@ -57,7 +58,7 @@ sub _remove_kernelcare_if_needed ($self) {

# This environment variable signals to the KernelCare RPM scriptlets not to deregister on package removal.
local $ENV{KCARE_KEEP_REGISTRATION} = '1';
$self->remove_rpms_from_repos('kernelcare');
Elevate::PkgMgr::remove_pkgs_from_repos('kernelcare');

Elevate::StageFile::update_stage_file( { 'reinstall' => { 'kernelcare' => 1 } } );

Expand Down
13 changes: 7 additions & 6 deletions lib/Elevate/Components/MySQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use Cpanel::Exception ();

use Elevate::Database ();
use Elevate::Notify ();
use Elevate::PkgMgr ();
use Elevate::StageFile ();

use parent qw{Elevate::Components::Base};
Expand Down Expand Up @@ -191,7 +192,7 @@ sub _cleanup_mysql_57_packages ($self) {
Mysql-tools-preview
};

$self->remove_rpms_from_repos(@repos);
Elevate::PkgMgr::remove_pkgs_from_repos(@repos);

return;
}
Expand All @@ -205,35 +206,35 @@ sub _cleanup_mysql_80_packages ($self) {
Mysql-tools-preview
};

$self->remove_rpms_from_repos(@repos);
Elevate::PkgMgr::remove_pkgs_from_repos(@repos);

return;
}

sub _cleanup_mysql_102_packages ($self) {

$self->remove_rpms_from_repos('MariaDB102');
Elevate::PkgMgr::remove_pkgs_from_repos('MariaDB102');

return;
}

sub _cleanup_mysql_103_packages ($self) {

$self->remove_rpms_from_repos('MariaDB103');
Elevate::PkgMgr::remove_pkgs_from_repos('MariaDB103');

return;
}

sub _cleanup_mysql_105_packages ($self) {

$self->remove_rpms_from_repos('MariaDB105');
Elevate::PkgMgr::remove_pkgs_from_repos('MariaDB105');

return;
}

sub _cleanup_mysql_106_packages ($self) {

$self->remove_rpms_from_repos('MariaDB106');
Elevate::PkgMgr::remove_pkgs_from_repos('MariaDB106');

return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Elevate/Components/PackageDupes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use cPstrict;
use Digest::SHA ();

use Elevate::Constants ();
use Elevate::PkgMgr ();

use Cpanel::SafeRun::Simple ();
use Cpanel::Version::Compare::Package ();
Expand Down Expand Up @@ -171,7 +172,7 @@ sub _select_packages_for_removal ( $self, %dupes ) {

sub _remove_packages ( $self, @packages ) {
foreach my $pkg (@packages) {
$self->rpm->remove_no_dependencies_or_scripts_and_justdb($pkg);
Elevate::PkgMgr::remove_no_dependencies_or_scripts_and_justdb($pkg);
}
return;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Elevate/Components/PackageRestore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Reinstall any packages detected pre distro upgrade

use cPstrict;

use Elevate::PkgMgr ();
use Elevate::StageFile ();

use Cpanel::Pkgr ();
Expand All @@ -48,7 +49,7 @@ sub pre_distro_upgrade ($self) {
}
}

my $config_files = $self->rpm->get_config_files( \@installed_packages );
my $config_files = Elevate::PkgMgr::get_config_files( \@installed_packages );

Elevate::StageFile::update_stage_file(
{
Expand All @@ -66,9 +67,9 @@ sub post_distro_upgrade ($self) {

foreach my $package ( keys %$package_info ) {

$self->dnf->install($package);
Elevate::PkgMgr::install($package);

$self->rpm->restore_config_files( @{ $package_info->{$package} } );
Elevate::PkgMgr::restore_config_files( @{ $package_info->{$package} } );
}

return;
Expand Down
Loading

0 comments on commit a419588

Please sign in to comment.