[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 12:35:29PM +0200, Mattia Dongili wrote:
> 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:
> > 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

Ok.

> > 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.

Indeed.

> 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 seems nicer in fact than my solution.

> > 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 ;)

No problem, the code needs to be split in three and sprinkled all over the
postinst and co files anyway :)

Friendly,

Sven Luther



Reply to: