2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-04 20:17:55 +00:00

refactor(genimage): reuse shared OS version parser

Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com>
This commit is contained in:
Vinícius Ferrão
2026-08-26 14:53:49 -03:00
parent b2ad18137b
commit e685d7e0ec
2 changed files with 42 additions and 34 deletions
@@ -11,6 +11,42 @@ use File::Path;
use Cwd qw(realpath);
use xCAT::SvrUtils;
sub el_major_version {
my $version = shift;
return if !defined($version);
my ($os_family, $os_major) = xCAT::SvrUtils::parseosver($version);
return
if !defined($os_family)
|| $os_family !~ /^(?:rhels?|rhelc|rhelhpc|centos(?:-stream)?|rocky|alma(?:linux)?|ol)$/;
return $os_major if length($os_major);
return;
}
sub rpm_installroot_command {
my ( $osver, $rootimg_dir, $non_interactive, $dnf_available ) = @_;
$non_interactive ||= "";
$dnf_available = -x "/usr/bin/dnf" unless defined($dnf_available);
my $majorrel = el_major_version($osver);
my $pkgmgr = "yum";
# EL8 and newer are dnf-native. Keep yum as the fallback for legacy
# systems and minimal environments that still provide only yum.
if (defined($majorrel) && $majorrel > 7 && $dnf_available) {
$pkgmgr = "dnf";
}
my $cmd = "$pkgmgr $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
if (defined($majorrel) && $majorrel > 7) {
$cmd .= "--releasever=" . $majorrel . " ";
$cmd .= "--setopt=module_platform_id=platform:el" . $majorrel . " ";
}
return $cmd;
}
sub varsubinline{
my $line=shift;
my $refvardict=shift;
+6 -34
View File
@@ -92,38 +92,6 @@ sub majversion {
return $majorrel;
}
sub el_major_version {
my $version = shift;
if (defined($version)
&& $version =~ /^(?:rhels?|centos|rocky|alma(?:linux)?|ol)\D*(\d+)/)
{
return $1;
}
return;
}
sub rpm_installroot_command {
my $non_interactive = shift || "";
my $majorrel = el_major_version($osver);
my $pkgmgr = "yum";
# EL8 and newer are dnf-native. Keep yum as the fallback for legacy
# systems and minimal environments that still provide only yum.
if (defined($majorrel) && $majorrel > 7 && -x "/usr/bin/dnf") {
$pkgmgr = "dnf";
}
my $cmd = "$pkgmgr $non_interactive -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
if (defined($majorrel) && $majorrel > 7) {
$cmd .= "--releasever=" . $majorrel . " ";
$cmd .= "--setopt=module_platform_id=platform:el" . $majorrel . " ";
}
return $cmd;
}
sub mount_chroot {
my $rootimage_dir = shift;
@@ -406,7 +374,9 @@ if($onlyinitrd){
my $non_interactive;
if (!$prompt) { $non_interactive = "-y"; }
my $yumcmd = rpm_installroot_command($non_interactive);
my $yumcmd = imgutils::rpm_installroot_command(
$osver, $rootimg_dir, $non_interactive
);
foreach (0 .. $repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
@@ -572,7 +542,9 @@ if($onlyinitrd){
}
close($yumconfig);
$index--;
my $yumcmd_base = rpm_installroot_command($non_interactive);
my $yumcmd_base = imgutils::rpm_installroot_command(
$osver, $rootimg_dir, $non_interactive
);
#yum/rpm/zypper has defect on calculating diskspace usage when installing rpm on a NFS mounted installroot
if (isNFSdir("$rootimg_dir")) {