@@ -92,6 +92,38 @@ sub majversion {
9292 return $majorrel ;
9393}
9494
95+ sub el_major_version {
96+ my $version = shift ;
97+
98+ if (defined ($version )
99+ && $version =~ / ^(?:rhels?|centos|rocky|alma(?:linux)?|ol)\D *(\d +)/ )
100+ {
101+ return $1 ;
102+ }
103+
104+ return ;
105+ }
106+
107+ sub rpm_installroot_command {
108+ my $non_interactive = shift || " " ;
109+ my $majorrel = el_major_version($osver );
110+ my $pkgmgr = " yum" ;
111+
112+ # EL8 and newer are dnf-native. Keep yum as the fallback for legacy
113+ # systems and minimal environments that still provide only yum.
114+ if (defined ($majorrel ) && $majorrel > 7 && -x " /usr/bin/dnf" ) {
115+ $pkgmgr = " dnf" ;
116+ }
117+
118+ my $cmd = " $pkgmgr $non_interactive -c /tmp/genimage.$$ .yum.conf --installroot=$rootimg_dir / --disablerepo=* " ;
119+ if (defined ($majorrel ) && $majorrel > 7) {
120+ $cmd .= " --releasever=" . $majorrel . " " ;
121+ $cmd .= " --setopt=module_platform_id=platform:el" . $majorrel . " " ;
122+ }
123+
124+ return $cmd ;
125+ }
126+
95127sub mount_chroot {
96128 my $rootimage_dir = shift ;
97129
@@ -374,15 +406,7 @@ if($onlyinitrd){
374406 my $non_interactive ;
375407 if (!$prompt ) { $non_interactive = " -y" ; }
376408
377- my $yumcmd = " yum $non_interactive -c /tmp/genimage.$$ .yum.conf --installroot=$rootimg_dir / --disablerepo=* " ;
378-
379- if ($osver =~ / ^(?:rhel|rocky|alma|ol)\D *(\d *)[.\d ]*.*$ / ) {
380- $majorrel = $1 ;
381- if ($majorrel > 7) {
382- $yumcmd .= " --releasever=" . $majorrel . " " ;
383- $yumcmd .= " --setopt=module_platform_id=platform:el" . $majorrel . " " ;
384- }
385- }
409+ my $yumcmd = rpm_installroot_command($non_interactive );
386410
387411 foreach (0 .. $repnum ) {
388412 $yumcmd .= " --enablerepo=$osver -$arch -$_ " ;
@@ -479,7 +503,7 @@ if($onlyinitrd){
479503 print " $envlist $yumcmd install $pkgnames \n " ;
480504 my $rc = system (" $envlist $yumcmd install $pkgnames " );
481505 if ($rc ) {
482- print " yum invocation failed\n " ;
506+ print " RPM package manager invocation failed\n " ;
483507 umount_chroot($rootimg_dir );
484508 exit 1;
485509 }
@@ -548,7 +572,7 @@ if($onlyinitrd){
548572 }
549573 close ($yumconfig );
550574 $index --;
551- my $yumcmd_base = " yum $non_interactive -c /tmp/genimage. $$ .yum.conf --installroot= $rootimg_dir / --disablerepo=* " ;
575+ my $yumcmd_base = rpm_installroot_command( $non_interactive ) ;
552576
553577 # yum/rpm/zypper has defect on calculating diskspace usage when installing rpm on a NFS mounted installroot
554578 if (isNFSdir(" $rootimg_dir " )) {
@@ -609,7 +633,7 @@ if($onlyinitrd){
609633 print " $envlist $yumcmd \n " ;
610634 my $rc = system (" $envlist $yumcmd " );
611635 if ($rc ) {
612- print " yum invocation failed\n " ;
636+ print " RPM package manager invocation failed\n " ;
613637
614638 # remove the hacked uname file
615639 unuse_hackuname();
@@ -2588,4 +2612,3 @@ sub usage {
25882612
25892613 return 0;
25902614}
2591-
0 commit comments