Skip to content

Commit

Permalink
Merge pull request #565 from cpanel/jb4u22
Browse files Browse the repository at this point in the history
Remove blocker for JetBackup on Ubuntu
  • Loading branch information
cPholloway authored Nov 28, 2024
2 parents f3ff03c + dbb2d87 commit da74e4b
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 63 deletions.
67 changes: 52 additions & 15 deletions elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -3074,18 +3074,29 @@ EOS
: $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.");
if ( ref Elevate::PkgMgr::instance() eq 'Elevate::PkgMgr::APT' ) {

if ( -f "/etc/apt/sources.list.d/$jetbackup_tier.list.disabled" ) {
rename( "/etc/apt/sources.list.d/$jetbackup_tier.list.disabled", "/etc/apt/sources.list.d/$jetbackup_tier.list" ) || WARN("Couldn't enable repository for $jetbackup_tier: $!");
}
}
my @reinstall = Elevate::PkgMgr::get_installed_pkgs_in_repo(qw/jetapps jetapps-stable jetapps-beta jetapps-edge/);

push @reinstall, 'jetbackup5-cpanel' if !grep { $_ eq 'jetbackup5-cpanel' } @reinstall;
unshift @reinstall, $jetbackup_tier;

if ( Elevate::OS::needs_leapp() && Cpanel::Pkgr::is_installed('jetphp81-zip') ) {
Elevate::PkgMgr::remove_no_dependencies('jetphp81-zip');
push @reinstall, 'jetphp81-zip' if !grep { $_ eq 'jetphp81-zip' } @reinstall;
}

my $data = {
tier => $jetbackup_tier,
packages => \@reinstall,
};

Elevate::StageFile::update_stage_file( { 'reinstall' => { 'jetbackup' => $data } } );

Elevate::PkgMgr::remove_no_dependencies('jetphp81-zip');

return;
}

Expand All @@ -3101,30 +3112,19 @@ EOS

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;
}

sub check ($self) {

$self->_blocker_jetbackup_is_supported();
$self->_blocker_old_jetbackup;

return;
}

sub _blocker_jetbackup_is_supported ($self) {
return unless Cpanel::Pkgr::is_installed('jetbackup');
return if Elevate::OS::supports_jetbackup();

my $name = Elevate::OS::default_upgrade_to();
return $self->has_blocker( <<~"END" );
ELevate does not currently support JetBackup for upgrades of $name.
Support for JetBackup on $name will be added in a future version of ELevate.
END
}
sub _blocker_jetbackup_is_supported { return undef }

sub _blocker_old_jetbackup ($self) {

Expand Down Expand Up @@ -7220,6 +7220,8 @@ deb-src https://repo.mysql.com/apt/ubuntu/ jammy mysql-8.0},
deb https://wp-toolkit.plesk.com/cPanel/Ubuntu-22.04-x86_64/latest/wp-toolkit/ ./
deb https://wp-toolkit.plesk.com/cPanel/Ubuntu-22.04-x86_64/latest/thirdparty/ ./},

map { my $thing = $_; "jetapps-$_.list" => "deb [arch=amd64] https://repo.jetlicense.com/ubuntu jammy/$_ main" } qw{base plugins alpha beta edge rc release stable},
};

use constant supported_cpanel_mysql_versions => qw{
Expand Down Expand Up @@ -7400,10 +7402,13 @@ deb https://wp-toolkit.plesk.com/cPanel/Ubuntu-22.04-x86_64/latest/thirdparty/ .

use cPstrict;

use File::Copy ();
use File::Copy ();
use File::Slurper ();

use Elevate::OS ();

use Cpanel::Pkgr ();

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

Expand Down Expand Up @@ -7576,6 +7581,38 @@ deb https://wp-toolkit.plesk.com/cPanel/Ubuntu-22.04-x86_64/latest/thirdparty/ .
return;
}

my %repo2filepart = (
map { my $dollar_underscore = $_; "jetapps-$dollar_underscore" => "repo.jetlicense.com_ubuntu_dists_jammy_$dollar_underscore" } qw{base plugins alpha beta edge rc release stable},
);

sub get_installed_pkgs_in_repo ( $self, @repos ) {
return unless scalar @repos;

my @apt_args = (APT_NON_INTERACTIVE_ARGS);
$self->ssystem_and_die( $Elevate::PkgMgr::APT::apt_get, @apt_args, 'update' );

my $dir2read = '/var/lib/apt/lists';
opendir( my $dh, $dir2read ) or die "Can't open $dir2read: $!";
my @pkglists = grep { m/_Packages$/ } readdir($dh);
closedir($dh);
$repos[0] = 'jetapps-base' if $repos[0] eq 'jetapps';
my @installed;
foreach my $repo (@repos) {
my $filepart = $repo2filepart{$repo};
foreach my $pkglist (@pkglists) {
if ( $pkglist =~ qr/^$filepart/ ) {
my @lines = File::Slurper::read_lines("$dir2read/$pkglist");

my %pkgs = map { substr( $_, 9 ) => 1 } grep { m/^Package: / } @lines;
push @installed, sort grep { Cpanel::Pkgr::is_installed($_) } keys %pkgs;
last;
}
}
}

return @installed;
}

1;

} # --- END lib/Elevate/PkgMgr/APT.pm
Expand Down
36 changes: 19 additions & 17 deletions lib/Elevate/Components/JetBackup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,32 @@ sub pre_distro_upgrade ($self) {
: $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.");
if ( ref Elevate::PkgMgr::instance() eq 'Elevate::PkgMgr::APT' ) {

# We need to enable that repo if possible and run apt update so that we can fetch the pkglist for it
if ( -f "/etc/apt/sources.list.d/$jetbackup_tier.list.disabled" ) {
rename( "/etc/apt/sources.list.d/$jetbackup_tier.list.disabled", "/etc/apt/sources.list.d/$jetbackup_tier.list" ) || WARN("Couldn't enable repository for $jetbackup_tier: $!");
}
}
my @reinstall = Elevate::PkgMgr::get_installed_pkgs_in_repo(qw/jetapps jetapps-stable jetapps-beta jetapps-edge/);

# Force certain things onto the list no matter what
push @reinstall, 'jetbackup5-cpanel' if !grep { $_ eq 'jetbackup5-cpanel' } @reinstall;
unshift @reinstall, $jetbackup_tier;

# Remove this package because leapp will remove it as it depends on libzip.so.2 which isn't available in 8.
if ( Elevate::OS::needs_leapp() && Cpanel::Pkgr::is_installed('jetphp81-zip') ) {
Elevate::PkgMgr::remove_no_dependencies('jetphp81-zip');
push @reinstall, 'jetphp81-zip' if !grep { $_ eq 'jetphp81-zip' } @reinstall;
}

my $data = {
tier => $jetbackup_tier,
packages => \@reinstall,
};

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.
Elevate::PkgMgr::remove_no_dependencies('jetphp81-zip');

return;
}

Expand All @@ -76,32 +89,21 @@ sub post_distro_upgrade ($self) {

my $pkgmgr_options = [ '--enablerepo=jetapps', "--enablerepo=$tier" ];

Elevate::PkgMgr::install_with_options( $pkgmgr_options, ['jetphp81-zip'] );
# Technically, this isn't possible on ubuntu, but we need it for cent.
# It falls through to just update thankfully.
Elevate::PkgMgr::update_with_options( $pkgmgr_options, \@packages );

return;
}

sub check ($self) {

$self->_blocker_jetbackup_is_supported();
$self->_blocker_old_jetbackup;

return;
}

# Support for JetBackup on Ubuntu is scheduled via RE-668
# For now, we block to reduce scope for the initial release
sub _blocker_jetbackup_is_supported ($self) {
return unless Cpanel::Pkgr::is_installed('jetbackup');
return if Elevate::OS::supports_jetbackup();

my $name = Elevate::OS::default_upgrade_to();
return $self->has_blocker( <<~"END" );
ELevate does not currently support JetBackup for upgrades of $name.
Support for JetBackup on $name will be added in a future version of ELevate.
END
}
sub _blocker_jetbackup_is_supported { return undef }

sub _blocker_old_jetbackup ($self) {

Expand Down
3 changes: 3 additions & 0 deletions lib/Elevate/OS/Ubuntu20.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ deb https://wp-toolkit.plesk.com/cPanel/Ubuntu-22.04-x86_64/latest/wp-toolkit/ .
# WP Toolkit Thirdparties
deb https://wp-toolkit.plesk.com/cPanel/Ubuntu-22.04-x86_64/latest/thirdparty/ ./},

# If you don't assign $_ it is a syntax error in this context. Can't cheat with postfix for either.
map { my $thing = $_; "jetapps-$_.list" => "deb [arch=amd64] https://repo.jetlicense.com/ubuntu jammy/$_ main" } qw{base plugins alpha beta edge rc release stable},
};

use constant supported_cpanel_mysql_versions => qw{
Expand Down
65 changes: 64 additions & 1 deletion lib/Elevate/PkgMgr/APT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ Logic wrapping the DEBIAN based package managers

use cPstrict;

use File::Copy ();
use File::Copy ();
use File::Slurper ();

use Elevate::OS ();

use Cpanel::Pkgr ();

use Log::Log4perl qw(:easy);

use parent 'Elevate::PkgMgr::Base';
Expand Down Expand Up @@ -256,4 +259,64 @@ sub remove_pkgs_from_repos ( $self, @pkg_list ) {
return;
}

=head1 get_installed_pkgs_in_repo
The "repo" in this case looks different from how it'd look in yum (name wise)
as we're ultimately just reading from /var/lib/apt/lists/ for the cached
list of packages from whatever URL.
As such i've made a small translation hash here so that callers which so far
still need this don't have to get updated.
Yeah it's a pain in the rear but I'd rather not add more abstraction around
this right now (I'd rather fix Cpanel::RepoQuery).
=cut

# So, I *could* use Cpanel::RepoQuery here, but it isn't quite suited to what
# we are doing here. First off we know more about the repos we care about,
# second of all there's a bug in RepoQuery:
# perl -MCpanel::RepoQuery -MData::Dumper -e 'print Data::Dumper::Dumper(Cpanel::RepoQuery::get_all_packages_from_repo("deb [arch=amd64] https://repo.jetlicense.com/ubuntu jammy/base main"));'
# Error open (<:unix) on '/var/lib/apt/lists/repo.jetlicense.com_ubuntu jammy_base main-mirrorlist_._Packages': No such file or directory at /usr/local/cpanel/Cpanel/RepoQuery/Apt.pm line 143.
#
# This works fine where we use it (cpanel-plugins) but isn't yet updated to be
# more generic.
#
# Also, excuse the tedious var naming. It's a syntax error to just use $_ here.
my %repo2filepart = (
map { my $dollar_underscore = $_; "jetapps-$dollar_underscore" => "repo.jetlicense.com_ubuntu_dists_jammy_$dollar_underscore" } qw{base plugins alpha beta edge rc release stable},
);

sub get_installed_pkgs_in_repo ( $self, @repos ) {
return unless scalar @repos;

# Forcibly update (not upgrade) apt so that you have the list on disk
# XXX This could mean a lot of apt update invocations. May want an extra
# caching layer here at some point if it becomes a problem.
my @apt_args = (APT_NON_INTERACTIVE_ARGS);
$self->ssystem_and_die( $Elevate::PkgMgr::APT::apt_get, @apt_args, 'update' );

my $dir2read = '/var/lib/apt/lists';
opendir( my $dh, $dir2read ) or die "Can't open $dir2read: $!";
my @pkglists = grep { m/_Packages$/ } readdir($dh);
closedir($dh);
$repos[0] = 'jetapps-base' if $repos[0] eq 'jetapps';
my @installed;
foreach my $repo (@repos) {
my $filepart = $repo2filepart{$repo};
foreach my $pkglist (@pkglists) {
if ( $pkglist =~ qr/^$filepart/ ) {
my @lines = File::Slurper::read_lines("$dir2read/$pkglist");

# Use hash to dedupe
my %pkgs = map { substr( $_, 9 ) => 1 } grep { m/^Package: / } @lines;
push @installed, sort grep { Cpanel::Pkgr::is_installed($_) } keys %pkgs;
last;
}
}
}

return @installed;
}

1;
34 changes: 20 additions & 14 deletions t/components-ElevateScript.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Exception;

use Test::MockFile 0.032;
use Test::MockFile 0.032 qw{nostrict};
use Test::MockModule qw/strict/;

use lib $FindBin::Bin . "/lib";
Expand All @@ -29,7 +29,7 @@ my $cpev = cpev->new;
my $script = $cpev->get_blocker('ElevateScript');

{
$0 = '/root/elevate-cpanel';
local $0 = '/root/elevate-cpanel';
is(
$script->_blocker_wrong_location(),
{
Expand All @@ -39,7 +39,7 @@ my $script = $cpev->get_blocker('ElevateScript');
q{We need elevate-cpanel to live in /scripts/}
);

$0 = '';
local $0 = '';
is(
$script->_blocker_wrong_location(),
{
Expand All @@ -49,9 +49,13 @@ my $script = $cpev->get_blocker('ElevateScript');
q{Handle if \$0 is broken.}
);

$0 = '/scripts/elevate-cpanel';
is( $script->_blocker_wrong_location(), 0, "\$0 can be /scripts/" );
$0 = '/usr/local/cpanel/scripts/elevate-cpanel';
# Cwd::abs_path will return undef if the file doesn't exist
SKIP: {
skip "/scripts does not exist on this host, assertion will fail due to Cwd::abs_path returning undef in that case", 1 if ( !-d '/scripts' );
local $0 = '/scripts/elevate-cpanel';
is( $script->_blocker_wrong_location(), 0, "\$0 can be /scripts/" ) || diag explain $script->_blocker_wrong_location();
}
local $0 = '/usr/local/cpanel/scripts/elevate-cpanel';
is( $script->_blocker_wrong_location(), 0, "\$0 can be /usr/local/cpanel/scripts/" );
}

Expand All @@ -68,17 +72,18 @@ my $script = $cpev->get_blocker('ElevateScript');

is(
$components->blockers,
[
{
bag {
item {
id => q[Elevate::Components::ElevateScript::_is_up_to_date],
msg => <<~'EOS',
The script could not fetch information about the latest version.
Pass the --skip-elevate-version-check flag to skip this check.
EOS

}
],
};
etc;
},
"blocks when info about latest version can't be fetched"
);

Expand All @@ -87,17 +92,18 @@ my $script = $cpev->get_blocker('ElevateScript');

is(
$components->blockers,
[
{
bag {
item {
id => q[Elevate::Components::ElevateScript::_is_up_to_date],
msg => <<~'EOS',
The script could not fetch information about the latest version.
Pass the --skip-elevate-version-check flag to skip this check.
EOS

}
],
};
etc;
},
"blocks when the installed script isn't the latest release"
);

Expand Down
Loading

0 comments on commit da74e4b

Please sign in to comment.