help-grub
[Top][All Lists]
Advanced

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

Re: String functions


From: Jordan Uggla
Subject: Re: String functions
Date: Mon, 2 Apr 2012 15:15:41 -0700

Please keep help-grub CCd so that others can benefit from the conversation.

On Mon, Apr 2, 2012 at 4:03 AM, Arbiel Perlacremaz
<address@hidden> wrote:
>> regexp --set=drive "(.*)," "$root"
>
> I'll try it, even if I don't really understand the command

The --set=drive option says that the result should be stored in the
variable $drive, the "(.*)," is a regular expression. If it were just
".*," then it would be more clear that it's matching any characters
which come before a ',' (comma) character. The parentheses around the
'.*' indicate that that's what we want to capture  (we don't want the
',' at the end). This is all standard regular expression syntax. The
last option is the string that we're using the regexp to manipulate,
our input string. In my example I used "$root", but you can have
regexp read from any variable you want, and search write to any
variable you want so you could do 'search --set=drive_and_partition
--fs-uuid UUID_HERE;  regexp --set=drive "(.*),"
"$drive_and_partition" '.

> As an exemple, let's suppose I have got a directory with some .iso files and
> a second directory with Grub configuration files. These configuration files
> countain menuentries for booting the PC with the .iso files. But I may have
> more iso than cfg files, or conversely, more cfg than iso files.

First, I would check if the iso files you're using already contain a
loopback.cfg, or if they're iso files you're generating yourself you
might want to consider adding a loobpack.cfg to them :
http://www.supergrubdisk.org/wiki/Loopback.cfg

>
> I would be glad to be able to generated a "loopback ... file.iso" and a
> "source .... file.cfg" if and only if both files, file.iso and file.cfg
> exist in their respective directories. For doing that, I suppose I can loop
> on the file names found in a directory, let's say the iso directory, and
> then lookup into the cfg directory to check for the cfg file, after having
> substituted "iso" for "cfg" in the file name.
>

Let's assume that the directories are "/boot-isos/" for the iso files
and "/boot-cfgs/" for the grub.cfg files. Then you could do something
like this:


insmod regexp # Needed to allow the use of globs.

for iso in /boot-isos/*.iso; do
  # $stripped_name is the name of the iso with the path and extension
stripped away
  regexp --set=stripped_name '^/boot-isos/(.*)\.iso$' "$iso"

  cfg="/boot-cfgs/${stripped_name}.cfg"

  # If a file exists at the path contained in $cfg
  if [ -e "$cfg" ]; then
    source "$cfg"
  fi
done

> I don't know yet exactly which code I should write, maybe an "empty"
> menuentry and then use Grub's chosen variable to have only one "loopback" et
> one "source" command, or a succession of "loopbck" and "source" statements.

I'm not sure if I understand correctly, but if you're asking what your
.cfg files corresponding to each iso file should look like, I would
say that they should either contain simple literal menu entry commands
like:

menuentry "GenBuntu" {
  loopback loop /boot-isos/grml.iso

  linux (loop)/vmlinuz some kernel arguments here
  initrd (loop)/initrd

  loopback --delete loop
}

Or if you want them to be slightly more flexible, so that the path to
the iso isn't hard coded, you can use the the $iso variable from the
earlier code (the for loop) (since this code is being sourced it can
access (and modify, so be careful) any variables from the context it
was sourced from). for example:

menuentry "GenBuntu (${iso})" {
  loopback loop "$iso"

  linux (loop)/vmlinuz some kernel arguments here
  initrd (loop)/initrd

  loopback --delete loop
}

-- 
Jordan Uggla (Jordan_U on irc.freenode.net)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]