mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-23 10:52:29 +00:00
fix(ubuntu): publish the newest kernel of a root image
genimage took the last kernel of a sorted file list. When an image held 6.8.0-99-generic and 6.8.0-100-generic, it published -99 and built the initrds for it. The uname of the image build also reported -99 to the package scripts, and it ignored an explicit kernelver. genimage and that uname now compare kernel releases number by number, so both choose -100. An explicit kernelver decides for both.
This commit is contained in:
@@ -249,6 +249,43 @@ sub disable_auto_profiles {
|
||||
return;
|
||||
}
|
||||
|
||||
# A kernel release compares number by number, so 6.8.0-100-generic is newer than 6.8.0-99-generic.
|
||||
sub newest_kernel_version {
|
||||
my @releases = @_;
|
||||
my $compare = sub {
|
||||
my @left = split(/(\d+)/, $_[0]);
|
||||
my @right = split(/(\d+)/, $_[1]);
|
||||
while (@left && @right) {
|
||||
my ($l, $r) = (shift(@left), shift(@right));
|
||||
my $order = ($l =~ /^\d+$/ && $r =~ /^\d+$/) ? $l <=> $r : $l cmp $r;
|
||||
return $order if $order;
|
||||
}
|
||||
return @left <=> @right;
|
||||
};
|
||||
my ($newest) = sort { $compare->($b, $a) } @releases;
|
||||
return $newest;
|
||||
}
|
||||
|
||||
# Package scripts run this uname in the image, so -r names the kernel that genimage publishes.
|
||||
sub uname_script {
|
||||
my ($kernelver) = @_;
|
||||
my $release = $kernelver ? "echo \"$kernelver\"" : 'ls /lib/modules | sort -V | tail -n 1';
|
||||
return "#!/bin/bash \n"
|
||||
. "case \"\$1\" in \n"
|
||||
. "\"-m\") \n"
|
||||
. " ARCH=\"\$(dpkg --print-architecture || \n"
|
||||
. " rpm -q kernel-\$(\"\$0\" -r) --qf '%{arch}')\" \n"
|
||||
. " case \"\$ARCH\" in \n"
|
||||
. " \"amd64\") ARCH=\"x86_64\" ;; \n"
|
||||
. " \"ppc64el\") ARCH=\"ppc64le\" ;; \n"
|
||||
. " esac \n"
|
||||
. " echo \"\$ARCH\" ;; \n"
|
||||
. "\"-r\") $release ;; \n"
|
||||
. "\"-s\"|\"\") echo \"Linux\" ;; \n"
|
||||
. "esac \n"
|
||||
. "exit 0 \n";
|
||||
}
|
||||
|
||||
sub varsubinline{
|
||||
my $line=shift;
|
||||
my $refvardict=shift;
|
||||
|
||||
@@ -733,7 +733,7 @@ foreach (@KVERS) {
|
||||
|
||||
@KVERS = <$rootimg_dir/lib/modules/*> unless (scalar(@KVERS));
|
||||
|
||||
$basekernelver = basename(pop @KVERS) if (scalar(@KVERS));
|
||||
$basekernelver = imgutils::newest_kernel_version(map { basename($_) } @KVERS) if (scalar(@KVERS));
|
||||
|
||||
$basekernelver = `uname -r` unless ($basekernelver);
|
||||
|
||||
@@ -2269,20 +2269,7 @@ sub use_hackuname {
|
||||
# write the hacked uname script
|
||||
my $unamefile;
|
||||
open($unamefile, ">", "$rootimg_dir/bin/uname");
|
||||
print $unamefile "#!/bin/bash \n";
|
||||
print $unamefile "case \"\$1\" in \n";
|
||||
print $unamefile "\"-m\") \n";
|
||||
print $unamefile " ARCH=\"\$(dpkg --print-architecture || \n";
|
||||
print $unamefile " rpm -q kernel-\$(\"\$0\" -r) --qf '%{arch}')\" \n";
|
||||
print $unamefile " case \"\$ARCH\" in \n";
|
||||
print $unamefile " \"amd64\") ARCH=\"x86_64\" ;; \n";
|
||||
print $unamefile " \"ppc64el\") ARCH=\"ppc64le\" ;; \n";
|
||||
print $unamefile " esac \n";
|
||||
print $unamefile " echo \"\$ARCH\" ;; \n";
|
||||
print $unamefile "\"-r\") cd /lib/modules && for d in * ; do : ; done && echo \$d ;; \n";
|
||||
print $unamefile "\"-s\"|\"\") echo \"Linux\" ;; \n";
|
||||
print $unamefile "esac \n";
|
||||
print $unamefile "exit 0 \n";
|
||||
print $unamefile imgutils::uname_script($kernelver);
|
||||
close $unamefile;
|
||||
chmod(0755, "$rootimg_dir/bin/uname");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user