Hello,
as I sent you yesterday my proposition for a kernel check, today I'm sending a
new simplified function of the same check:
sub kernel_version {
my $autoconf_path = shift;
my $required_version = shift;
my $build_version = 0;
my $build_patchlevel = 0;
my $build_sublevel = 0;
my $build_extraversion = 0;
# add autoconf to the path
$autoconf_path .= 'include/linux/autoconf.h';
my @version = split /\./, $required_version;
my $current_version = 0;
if ( -f $autoconf_path ) {
# open the autoconf.h to feth VERSION, PATCHLEVEL and SUBLEVEL, if needed
I can add EXTRAVERSION too
open AUTOCONF, '<', $autoconf_path;
while (<AUTOCONF>) {
if ($_ =~ /CONFIG_KERNELVERSION/) {
$current_version = $_;
# we don't need to check any thing else in this file so we are
stopping the read
last;
}
}
close AUTOCONF;
# leaving only the numbers from the lines
# this is faster then split and doesn't alocate useless arrays
$current_version =~ s/.*"(.*)"\n/$1/;
$current_version =~ s/.*"(.*)"\n/$1/;
# parse the kernel version into the variables
if ($current_version =~ /\-/) {
my @line = split /\-/, $current_version;
my @ver = split /\./, $line[0];
$build_version = $ver[0];
$build_patchlevel = $ver[1];
$build_sublevel = $ver[2];
$build_extraversion = $line[1];
print "Note: You are using unstable kernel version!\n";
} else {
my @kernel = split /\./, $current_version;
$build_version = $kernel[0];
$build_patchlevel = $kernel[1];
$build_sublevel = $kernel[2];
$build_extraversion = $kernel[3];
}
# checking VERSION, PATCHLEVEL and SUBLEVEL for the supplied kernel
# if needed I can add also EXTRAVERSION to the check
if ($build_version >= $version[0] &&
$build_patchlevel >= $version[1] &&
$build_sublevel >= $version[2]) {
print 'Current kernel version is OK',"\n";
return 1;
} else {
print 'Current kernel version: ',$build_version.'.'.
$build_patchlevel.'.'.$build_sublevel,"\nMinimum version: ".$version[0].'.'.
$version[1].'.'.$version[2],"\n";
return 0;
}
} else {
print "Unable to find ($autoconf_path)!\n";
return 0;
}
}
# the options to this function are:
# source path
# minimum kernel version
kernel_version('/usr/src/linux/','2.6.22');
Best regards,
Marian Marinov(HackMan)