Tue 28 Feb 2012 11:08:18 PM UTC, original submission:
The following patch for GRUB 1.99 implements a bunch of enhancements and some bug fixes. The patch also creates a README file with the detailed description.
I hereby state that all code was written only by me and doesn't contain any work from others. The code in this patch may be used according to the GNU General public license version v3 or later.
I would be glad if you decide to take over this patch into GRUB 2.
This is the description for this patch:
Package: GRUB 1.99
Patch: grub-1.99-andreas_vogel_menu_and_subst.patch
Created: 28.2.2012
Author: Andreas Vogel
Description:
This patch enhances GRUB 1.99 by the following features:
*) All changes made by this patch are supposed to be backward compatible.
*) New menuentry option -S | --silent=0|1 (hiding the terminal box)
When a menuentry is a submenu or when a menuentry is created with the option --silent, then
the terminal box is not shown when this menuentry is executed.
*) Reexecution of the menu definition after a menuentry execution
After executing a menuentry and if the menu entry execution didn't end up with a booting action,
the menu definition will be reexecuted before showing the menu again.
The reason is to be able to have dynamic menus using the values of environment variables.
*) New menuentry option -l | --label=STRING
When having dynamic menuentries (e.g. localized entry names), it's quite hard to
set the 'default' variable to the entry title.
Therefore with the new menuentry --label it is possible to specify the user visible title
for a menuentry. If this option isn't set, the menuentry title will be used in order to maintain
backward compatibility.
*) New menuentry option -H | --hidden=0|1
If the --hidden option is set for a menuentry, the menuentry will not be visible. The
activation of the menuentry is only possible by use of the key defined with --hotkey.
*) New menuentry option -E | --enable=0|1
A disabled menuentry is shown but cannot be executed. In case the menuentry is a submenu, the
submenu will not open if the menuentry is disabled.
It's the responsibility of the output module to show an adequate representation of disabled
menu entries.
*) Variable substitutions in strings
This patch introduces a new general variable substitution function grub_subst() which sunstitutes
environment variables in a string. The variable syntax is similar to BASH variable handling.
Usage:
$x or ${x} expands to x
${x:-y} expands to x if x is set and nonempty, otherwise expands to y
${x:=y} expands to x if x is set and nonempty, otherwise expands to y and sets environment variable x
${x:+y} expands to x if x is unset or empty, otherwise expands to y
The use of single quotes and double quotes is supported. Single characaters may be escaped by backlash.
*) Enhanced hotkey aliases
The list of possible hotkey aliases has been extended to cover all possible keys. Case is now
insignificant when comparing key alias names.
It is now possible to specify any combination of the SHIFT and CTRL modififiers. The order of the
modifiers is irelevant.
Examples:
"F1" "<SHIFT> F1" "<CTRL> <SHIFT> F1"
*) Bug fix: normal/main.c: grub_normal_free_menu() didn't free all memory
*) Variable substitution for labels defined in theme for gfxmenu
Using the new grub_subst() function, all labels in gfxmenu are subject to variable substitution.
Therefore it's possible to create labels showing the value of an environment variable. As an example
it would be now possible to create a themed debugging screen showing the values of the basic environment
variables.
*) Variable substitution in view title defined in theme for gfxmenu
*) Variable substitutions for list entry names in gfxmenu and in text mode menu
All menuentry titels/labels are subject to variable substition in order to be able to implement
dynamic menue labels.
As the menuentry definitions are created as shell functions, unquoted variables are already substituted
when the command is executed. Therefore attention is needed because of quoting.
Example:
menuentry entry1 --silent 1 --label="Set gfxterm to 800x600 (current: $gfxterm)" {
set gfxterm=800x600
}
Open items:
*) The option parsing method implemented in lib/arg.c has IMHO a design problem.
When defining an option which takes an optional argument by specifying GRUB_ARG_OPTION_OPTIONAL, there
will be an ambiguity in a certain situation.
Let's assume the option --silent is defined with the flag GRUB_ARG_OPTION_OPTIONAL and the type ARG_TYPE_INT.
Given the command line:
myprog --silent /dev/sda
will fail because /dev/sda, which is meant to be just an argument to myprog, is treated to be the value for the
--silent option.
This is because the option parsing methods are able to handle both formats: '--silent=1' and '--silent 1'
As a consequence, options taking an optional argument can only be used if they are followed either by another option
or the string '--' which denotes the end of options. Although this is a working workaround I'm not sure
if this is really the way it should be.
Summary:
This patch make it possible to implement customizable menus by using environment variables.
It is now possible to create customisation menus, e.g. to set the language, screen resolution,
custom boot options, etc. without the need to hardcode them into different menuentries.
Hidden menus are not shown on the screen and they are opened by hotkeys, e.g. to open the
settings menu tree or to open the help system menu tree.
Exported environment variables are not only exported into the environment of a menuentry execution
context, they are furthermore exported back into the callers environment. In other means exported environment
variables are global for the menu system.
Complete example:
##########################################################################
## GRUB 1.99 configuration file
##########################################################################
set theme=$prefix/theme/theme.txt
set kbd=de
export kbd theme
menuentry linux --label "TEST: Boot linux (kbd=$kbd) [CTRL-b]" --hotkey '<CTRL> b' {
echo
echo "Booting linux with keyboard='$kbd'!"
echo
echo "Press <RETURN> to continue..."
read
}
menuentry disabled --label "TEST: Disabled entry" --enable 0 {
echo "Ooops! Why can we run a disabled menu entry??"
echo "Press <RETURN> to continue..."
read
}
function refresh_kbd_menulabels {
set curLabel="(*)"
if [ "$kbd" = de ] ; then set curDE=$curLabel ; else set curDE="" ; fi
if [ "$kbd" = us ] ; then set curUS=$curLabel ; else set curUS="" ; fi
set default="$kbd"
}
## Hidden settings menu... press CTRL-S to open it
submenu settings --label "TEST: Settings... [CTRL-s]" --hidden 1 --hotkey '<CTRL> s' {
submenu keyboard --label 'TEST: Keyboard layout...' {
refresh_kbd_menulabels
menuentry de --label 'German keyboard $curDE' --silent 1 {
set kbd=de
}
menuentry us --label 'English keyboard $curUS' --silent 1 {
set kbd=us
}
}
}
##########################################################################
## END of configuration file
##########################################################################
|