[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Perl help needed for kernel-package mod ... (Was: Bringing the 2.6.13 (and beyond) kernel to sid, solving ramdisk generations issues and stuff.)



On Sun, Oct 16, 2005 at 08:18:02AM +0200, Sven Luther wrote:
> On Sat, Oct 15, 2005 at 10:16:48PM +0200, Mattia Dongili wrote:
> > On Sat, Oct 15, 2005 at 08:36:11PM +0200, Sven Luther wrote:
> > > I would be extremely grateful if someone could take the time and implement
> > > this ASAP, as we need this to upload 2.6.13-2 and finish the support.
> > 
> > It's not entirely clear to me but the following might help. I'm missing
> > some bits but if you can give me more insight I'll fix the wrong stuff
> > (sorry I never played seriously with initrd :) )
> 
> Thanks Mattia, i am extremely thankful for your help. Let's me go over this
> proposed code with you to see if i understood well, and add places where it
> did not work out.
> 
> > #!/usr/bin/perl
> > use strict;
> > 
> > chomp (my $unamedashr = `uname -r`);
> 
> We get the kernel version.
> 
> > #
> > # is lexical comparison enough ?? <---------
> > # 2.6.13-rc1 will result in being greater than 2.6.13
> 
> We need to use dpkg --compare-versions here, so probably :
> 
> > #
> > my $ramdisk	= '/usr/sbin/initramfs' if ($unamedashr lt "2.6.13");
> 
> my $ramdisk	= '/usr/sbin/mkinitramfs' if (system ("dpkg --compare-versions $unamedashr lt 2.6.13 1>/dev/null 2>&1") == 0)

right

> or something such, but i suppose that this line is precedded by a more generic :
> my $ramdisk = '/usr/sbin/mkinitrd', right ? 
> 
> > $ramdisk	= "$1"  if /ramdisk\s*=\s*(\S+)/ig;
> 
> Does this one not cut at the first space ? I was told to use split instead, or
> something such.

Aaah! I see the point now. I was missing the usefullness of that
statement in fact!
Yes, the above regex assigns to $ramdisk only the first element in a
space separated list.
We might rework it this way (I'm borrowing your comments to the code)
then:

#!/usr/bin/perl
use strict;

# We get the kernel version.
chomp (my $unamedashr = `uname -r`);

# slurp the ramdisk option if present or default 'initramfs' for kernels
# prior 2.6.13 or default to 'mkinitrd' if none of the previous apply
my $ramdiskopts = (/ramdisk\s*=\s*(.+)/ig ? "$1" : 
                        (system("dpkg --compare-versions $unamedashr lt 2.6.13 1>/dev/null 2>&1") == 0 ?
                                "/usr/sbin/initramfs" : "/usr/sbin/mkinitrd"));

# Ok, so we try -x and the call, over the space separadet ramdisk list.
# The remaining list won't have those items failing the tests.
my @ramdisklist = 
	grep { 
		-x and 
		system ("$_ --supported-host-version=$unamedashr 1>/dev/null 2>&1") == 0 
	}
	split (/ /, $ramdiskopts);

# We define ramdisk to the first element of the list, and die if it is empty.
defined (my $ramdisk = shift @ramdisklist) 
	|| die "Dear user I failed to find an usable tool to create inital ram fs";

# And we do the ramdisk call, as normal.
my $ret = system("$ramdisk " .
		($mkimage ? "-m '$mkimage' " : "") .
		"-o $initrd_path.new $modules_base/$version");
 
> This sounds very nice and very near what i wanted to do, so again, i express
> my extreme thanks for you jumping in. So if the first line change is ok, and
> the ramdisk = "$1" ... thingy indeed pulls in space also, we have something
> which can be uploaded.

Take a look at the above corrected version, it should do what you want
now :)
Oh, I'm sorry for the code style, it could be made clearer by separating
some statements, but... you know perl is not for clean code ;)

-- 
mattia
:wq!

Attachment: signature.asc
Description: Digital signature


Reply to: