Expect names of the form <prefix>-<version> when finding latest kernel

If a specific kernel version is not defined in config.yaml, the name of
the kernel is split on the first '-' to determine the prefix and the
version. If no version can be found, this is a hard error.

The latestKernel subroutine is only called if neither a kernel path nor
the kernel version is specified, which means its output will always be
split on '-' to identify a prefix and a version. Thus, in the
subroutine, only look for files of the form <prefix>-*, silently
ignoring kernels with non-conforming names. This allows for clean
operation if at least one kernel does match the expected pattern, and
also provides for more meaningful error messages if no kernels match the
expected pattern (for example, on Arch).

Fixes #128.
This commit is contained in:
Andrew J. Hesford 2021-01-06 12:25:06 -05:00
parent 798fce8389
commit ab95346f4c
1 changed files with 12 additions and 10 deletions

View File

@ -223,7 +223,7 @@ if ( nonempty $config{Kernel}{CommandLine} and !nonempty $runConf{cmdline} ) {
}
if ( nonempty $runConf{version} ) {
$runConf{version} =~ s/%current\b/%current/i;
$runConf{version} =~ s/%current\b/%{current}/i;
$runConf{version} =~ s/%\{current\}/$VERSION/i;
} else {
$runConf{version} = $VERSION;
@ -253,14 +253,16 @@ if ( nonempty $runConf{kernel} ) {
# Try to determine a kernel file when one was not provided
if ( nonempty $runConf{kernel_version} ) {
$runConf{kernel} = versionedKernel $runConf{kernel_version};
unless ( nonempty $runConf{kernel} ) {
print "Unable to find file for kernel version $runConf{kernel_version}\n";
exit 1;
}
} else {
$runConf{kernel} = latestKernel;
}
# Make sure a kernel was found
unless ( nonempty $runConf{kernel} ) {
print "Unable to choose a kernel file, cannot continue\n";
exit 1;
unless ( nonempty $runConf{kernel} ) {
print "Unable to find latest kernel; specify version or path manually\n";
exit 1;
}
}
}
@ -521,9 +523,9 @@ sub versionedKernel {
return;
}
# Finds the latest kernel in /boot
# Finds the latest kernel in /boot, based on form <prefix>-<version>
sub latestKernel {
my @prefixes = ( "vmlinux*", "vmlinuz*", "linux*", "kernel*" );
my @prefixes = ( "vmlinux*-*", "vmlinuz*-*", "linux*-*", "kernel*-*" );
for my $prefix (@prefixes) {
my $glob = join( '/', ( $runConf{bootdir}, $prefix ) );
my @kernels = glob($glob);
@ -574,7 +576,7 @@ sub createInitramfs {
push( @cmd, ( $output_file, $kver ) );
my $command = join(' ', @cmd);
my $command = join( ' ', @cmd );
Log("Executing: $command");
my @output = execute(@cmd);