File manager - Edit - /usr/local/cpanel/install/MariaDBRhel.pm
Back
package Install::MariaDBRhel; # cpanel - install/MariaDBRhel.pm # Copyright 2026 WebPros International, LLC # All rights reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited. use cPstrict; use base qw( Cpanel::Task ); use Cpanel::OS (); our $VERSION = '1.0'; =encoding utf8 =head1 NAME Install::MariaDBRhel - Repoint existing MariaDB yum repositories at the rhel tree. =head1 SYNOPSIS use Install::MariaDBRhel (); Install::MariaDBRhel->new->perform; =head1 DESCRIPTION MariaDB pruned the CentOS 7 and 8 paths out of C<mariadb-10.6/yum/centos/> on C<archive.mariadb.org>, leaving only C<9/>. Any EL8 server whose MariaDB repository was written from the old C<Cpanel::OS/mariadb_repo_template> now has a C<baseurl> that returns C<404>, which breaks MariaDB installs, upgrades, and ELevate runs. This task runs once and rewrites any existing yum repository file that still points at the C<centos> tree so that it uses the C<rhel> tree instead. New installations already receive the corrected URL from L<Cpanel::OS/mariadb_repo_template>; this task fixes servers that were configured before that change. The C<rhel> tree is used rather than C<almalinux> because it is the only one that exists for every MariaDB version cPanel ships: C<almalinux> has no structured tree at all for 10.3 or 10.5, so repointing there would turn two working repositories into C<404>s. The trees serve byte-identical packages, so the C<gpgkey> lines need no change. Every C<.repo> file is rewritten, not only the one for the running version. C<Cpanel::Repos::_remove_obsoletes> disables superseded repositories rather than deleting them, so a server can carry several stale MariaDB files that would break again if they were ever re-enabled. =over 1 =item Type: Bugfix =item Frequency: once =item EOL: 11.142 =back =cut use constant YUM_REPOS_DIR => q[/etc/yum.repos.d]; # Persistent do_once flag so the existing repositories are repaired a single time. use constant DO_ONCE_FLAG => q[mariadb_rhel_centos_to_rhel]; exit __PACKAGE__->runtask() unless caller; sub new ($proto) { my $self = $proto->SUPER::new; $self->set_internal_name('mariadbrhel'); return $self; } =head2 perform() Repairs the existing MariaDB yum repositories a single time on yum-based systems. Returns true. =cut sub perform ($self) { # Fresh installs get the corrected template directly, so there is nothing to repair. return 1 if $ENV{'CPANEL_BASE_INSTALL'}; return 1 unless Cpanel::OS::is_yum_based(); $self->do_once( version => DO_ONCE_FLAG, eol => '11.142', code => sub { $self->_repoint_existing_repos() }, ); return 1; } =head2 _repoint_existing_repos() Scans the yum repository directory for the MariaDB repository files cPanel generates and rewrites any that reference the retired C<centos> tree on C<archive.mariadb.org> to use the C<rhel> tree. Clears the package manager cache when anything changed. Returns true. =cut sub _repoint_existing_repos ($self) { my $dir = YUM_REPOS_DIR; return 1 unless -d $dir; opendir( my $dh, $dir ) or do { warn "Unable to read “$dir”: $!\n"; return 1; }; # Match only the files we generate. Cpanel::Repo::Install names these # "MariaDB" followed by the version with the dots stripped, so 10.11 # becomes MariaDB1011.repo. Other repositories, and the .rpmnew/.rpmsave # variants the package manager ignores, are left alone. my @repo_files = sort grep { m/\AMariaDB[0-9]+[.]repo\z/ } readdir $dh; closedir $dh; my $changed = 0; foreach my $file (@repo_files) { $changed += $self->_repair_repo_file("$dir/$file"); } $self->_clear_package_cache() if $changed; return 1; } =head2 _repair_repo_file($path) Rewrites a single yum repository file in place when it references the retired C<centos> tree. Returns true when the file was rewritten and false when it was left untouched. =cut sub _repair_repo_file ( $self, $path ) { return 0 unless -f $path; require Cpanel::LoadFile; my $content = eval { Cpanel::LoadFile::load($path) }; return 0 unless defined $content; my $new_content = $self->_rewrite_repo_content($content); return 0 unless defined $new_content; print "Updating MariaDB yum repository “$path” to use the archive.mariadb.org rhel tree.\n"; require Cpanel::FileUtils::Write; eval { Cpanel::FileUtils::Write::overwrite( $path, $new_content, 0644 ); 1 } or warn "Failed to update “$path”: $@\n"; return 1; } =head2 _rewrite_repo_content($content) Given the contents of a yum repository file, returns the rewritten contents if it referenced the retired C<centos> tree, or C<undef> if no change was needed. Only the distribution segment is touched. Everything else in the file -- C<enabled=0> on superseded repositories, priorities, and any administrator edits -- is preserved verbatim. =cut sub _rewrite_repo_content ( $self, $content ) { my $original = $content; # Repoint the retired centos tree at the rhel tree, preserving both the # MariaDB version and the distro major. Anchored on the host and the # mariadb-<version>/yum/ prefix so nothing else can match. $content =~ s{ ( archive[.]mariadb[.]org / mariadb-[0-9]+[.][0-9]+ / yum / ) centos ( / ) } {$1rhel$2}xmsg; return if $content eq $original; return $content; } =head2 _clear_package_cache() Clears the package manager's cached repository metadata so the corrected C<baseurl> is used on the next transaction. Writing the file directly bypasses the post-install hook C<Cpanel::Repos> would normally trigger. Returns true. =cut sub _clear_package_cache ($self) { require Cpanel::Repos::Utils; eval { Cpanel::Repos::Utils::post_install(); 1 } or warn "Failed to clear the package manager cache: $@\n"; return 1; } 1;
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Generation time: 0.05 |
proxy
|
phpinfo
|
Settings