savedefault
PATCH 1/1 savedefault
Hello. Here is a long-awaited savedefault patch. Works correctly only if my scripting fix is applied
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
include/grub/menu.h +1 -1
@@ -81,7 +81,7 @@ typedef struct grub_menu_execute_callbackgrub_menu_entry_t grub_menu_get_entry (grub_menu_t menu,int no);int grub_menu_get_timeout (void );void grub_menu_set_timeout (int timeout); -void grub_menu_execute_entry (grub_menu_entry_t entry); +void grub_menu_execute_entry (grub_menu_t menu,grub_menu_entry_t entry); void grub_menu_execute_with_fallback (grub_menu_t menu, grub_menu_entry_t entry, grub_menu_execute_callback_t callback,
normal/menu.c +17 -3
@@ -122,8 +122,22 @@ get_and_remove_first_entry_number (const char *name)/* Run a menu entry. */ void -grub_menu_execute_entry (grub_menu_entry_t entry) +grub_menu_execute_entry (grub_menu_t menu,grub_menu_entry_t entry) { +grub_menu_entry_t e; +int no =0 ; +char buf[64 ]; + +for (e = menu->entry_list; e && e != entry; e = e->next, no++); + +if (e) + { +grub_sprintf (buf,"%d" , no); +grub_env_set ("chosen_entry" , buf); + } +else +grub_env_unset ("chosen_entry" ); +grub_parser_execute ((char *) entry->sourcecode);if (grub_errno ==GRUB_ERR_NONE &&grub_loader_is_loaded ())
@@ -145,7 +159,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu, callback->notify_booting (entry, callback_data); -grub_menu_execute_entry (entry); +grub_menu_execute_entry (menu, entry);/* Deal with fallback entries. */ while ((fallback_entry = get_and_remove_first_entry_number ("fallback"))
@@ -156,7 +170,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu, entry =grub_menu_get_entry (menu, fallback_entry); callback->notify_fallback (entry, callback_data); -grub_menu_execute_entry (entry); +grub_menu_execute_entry (menu, entry);/* If the function call to execute the entry returns at all, then this is taken to indicate a boot failure. For menu entries that do something other than actually boot an operating system, this could assume
normal/menu_text.c +1 -1
@@ -580,7 +580,7 @@ show_text_menu (grub_menu_t menu, int nested)else { grub_errno =GRUB_ERR_NONE ; -grub_menu_execute_entry (e); +grub_menu_execute_entry (menu, e);if (grub_errno !=GRUB_ERR_NONE ) {grub_print_error ();
util/grub.d/00_header.in +3 -0
@@ -32,10 +32,13 @@ for i in ${GRUB_PRELOAD_MODULES} ; do done if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi +if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi + if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi cat << EOF +load_env set default=${GRUB_DEFAULT} set timeout=${GRUB_TIMEOUT} EOF
util/grub.d/10_freebsd.in +2 -0
@@ -57,6 +57,8 @@ if [ "x$kfreebsd" != "x" ] ; then cat << EOF menuentry "${OS}" { + saved_entry=\${chosen_entry} + save_env saved_entry EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOF
util/grub.d/10_hurd.in +2 -0
@@ -70,6 +70,8 @@ fi cat << EOF menuentry "${OS}" { + saved_entry=\${chosen_entry} + save_env saved_entry EOF prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" cat << EOF
util/grub.d/10_linux.in +2 -0
@@ -97,6 +97,8 @@ linux_entry () { cat << EOF menuentry "$1" { + saved_entry=\${chosen_entry} + save_env saved_entry EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOF
util/grub.d/10_windows.in +2 -0
@@ -71,6 +71,8 @@ for dir in $dirlist ; do echo "Found $OS on $dir ($dev)" >&2 cat << EOF menuentry "$OS" { + saved_entry=\${chosen_entry} + save_env saved_entry EOF prepare_grub_to_access_device "$dev" | sed 's,^,\t,'
util/grub.d/30_os-prober.in +6 -0
@@ -45,6 +45,8 @@ for OS in ${OSPROBED} ; do cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { + saved_entry=\${chosen_entry} + save_env saved_entry set root=${CHAINROOT} chainloader +1 }
@@ -69,6 +71,8 @@ EOF cat << EOF menuentry "${LLABEL} (on ${DEVICE})" { + saved_entry=\${chosen_entry} + save_env saved_entry set root=${LINUXROOT} linux ${LKERNEL} ${LPARAMS} EOF
@@ -88,6 +92,8 @@ EOF OSXDISK=disk"`echo ${OSXROOT} | awk -F , '{ print $1 ; }' | sed 's/(hd//;'`"s"`echo ${OSXROOT} | awk -F , '{ print $2 ; }' | sed 's/)//;'`" cat << EOF menuentry "${LONGNAME} (on ${DEVICE})" { + saved_entry=\${chosen_entry} + save_env saved_entry set root=${OSXROOT} insmod vbe insmod gfxterm
util/i386/pc/grub-install.in +5 -0
@@ -39,6 +39,7 @@ else fi grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}` grub_probe=${sbindir}/`echo grub-probe | sed ${transform}` +grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}` rootdir= grub_prefix=`echo /boot/grub | sed ${transform}` modules=
@@ -230,6 +231,10 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then done fi +if ! test -f ${grubdir}/grubenv; then + $grub_editenv ${grubdir}/grubenv create +fi + # Write device to a variable so we don't have to traverse /dev every time. grub_device=`$grub_probe --target=device ${grubdir}`
Am Montag, den 01.06.2009, 12:48 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 2 lines
Hello. Here is a long-awaited savedefault patch. Works correctly only if my scripting fix is applied
What happens if this is used on RAID?
Especially when the grubenv file is wrapped by the chunksize? We should consider this if we use saven_env by default.
Signature · 1 line
Felix Zielcke
Quoted 6 lines · Felix Zielcke
Am Montag, den 01.06.2009, 12:48 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 2 lines
Hello. Here is a long-awaited savedefault patch. Works correctly only if my scripting fix is applied
What happens if this is used on RAID?
Then writing is handled by raid module which always return GRUB_ERR_NOT_IMPLEMENTED_YET which would make save_env fail. If users circumvent raid module they do a faulty install and it's their fault if their RAID gets desynchronised
Quoted 12 lines
Especially when the grubenv file is wrapped by the chunksize? We should consider this if we use
saven_envby default. --
Felix Zielcke_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Hi,
Actually, I'm thinking about a more generic method to implement this feature with events. The menu viewer fire events at certain circumstance, and we can configure the commands to execute. For example, we could have a menu.select event fire when a menu item is selected, and use something like this in grub.cfg:
event add menu.select save_env saved_entry
Command "save_env saved_entry" would be run automatically, no need to patch up the menu items.
One advantage with the event model is that it can handle password at the same time, for example, we could write something like this:
event add menu.select_check password
event add menu.commandline_check password
password command is run when user tries to select the menu item or enter command line.
Quoted 13 lines · Vladimir 'phcoder' Serbinenko
Hello. Here is a long-awaited savedefault patch. Works correctly only if my scripting fix is applied
--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
Hello. Welcome back
Quoted 8 lines · Bean
Hi,
Actually, I'm thinking about a more generic method to implement this feature with events. The menu viewer fire events at certain circumstance, and we can configure the commands to execute. For example, we could have a menu.select event fire when a menu item is selected, and use something like this in grub.cfg:
Quoted 4 lines
event add menu.select
save_envsaved_entryCommand "
save_envsaved_entry" would be run automatically, no need to patch up the menu items.
Often user doesn't want some entries to be saved as default. E.g. "single user" entries. I know that it's easy to revert to other method but if nearly everyone does your work will be effort for nothing
Quoted 37 lines
One advantage with the event model is that it can handle password at the same time, for example, we could write something like this:
event add menu.select_check password
event add menu.commandline_check passwordpassword command is run when user tries to select the menu item or enter command line.
Quoted 13 lines · Vladimir 'phcoder' Serbinenko
Hello. Here is a long-awaited savedefault patch. Works correctly only if my scripting fix is applied
--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Bean_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Quoted 11 lines · Vladimir 'phcoder' Serbinenko
Hello. Welcome back
Quoted 8 lines · Bean
Hi,
Actually, I'm thinking about a more generic method to implement this feature with events. The menu viewer fire events at certain circumstance, and we can configure the commands to execute. For example, we could have a menu.select event fire when a menu item is selected, and use something like this in grub.cfg:
Quoted 7 lines
Quoted 4 lines
event add menu.select
save_envsaved_entryCommand "
save_envsaved_entry" would be run automatically, no need to patch up the menu items.Often user doesn't want some entries to be saved as default. E.g. "single user" entries. I know that it's easy to revert to other method but if nearly everyone does your work will be effort for nothing
Hi,
Now the menuitem support attributes, perhaps we could utilize it to store parameters for the event handler, for example, "save/nosave" for savedefault, "lock/unlock" for password, etc.
Quoted 50 lines
Quoted 28 lines
One advantage with the event model is that it can handle password at the same time, for example, we could write something like this:
event add menu.select_check password
event add menu.commandline_check passwordpassword command is run when user tries to select the menu item or enter command line.
Quoted 13 lines · Vladimir 'phcoder' Serbinenko
Hello. Here is a long-awaited savedefault patch. Works correctly only if my scripting fix is applied
--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 9 lines
--
Bean_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
Hello
Quoted 21 lines · Bean
Quoted 11 lines · Vladimir 'phcoder' Serbinenko
Hello. Welcome back
Quoted 8 lines · Bean
Hi,
Actually, I'm thinking about a more generic method to implement this feature with events. The menu viewer fire events at certain circumstance, and we can configure the commands to execute. For example, we could have a menu.select event fire when a menu item is selected, and use something like this in grub.cfg:
Quoted 7 lines
Quoted 4 lines
event add menu.select
save_envsaved_entryCommand "
save_envsaved_entry" would be run automatically, no need to patch up the menu items.Often user doesn't want some entries to be saved as default. E.g. "single user" entries. I know that it's easy to revert to other method but if nearly everyone does your work will be effort for nothing
Quoted 6 lines
Hi,
Now the menuitem support attributes, perhaps we could utilize it to store parameters for the event handler, for example, "save/nosave" for savedefault, "lock/unlock" for password, etc.
Difficult to say whether such addition would be useful. I feel like it's over-engineering. I may be wrong however. Fell free to expose what you have in your head about this idea.
Meanwhile could we merge my patch? We can add fancy handlers later
Quoted 62 lines
Quoted 45 lines
Quoted 28 lines
One advantage with the event model is that it can handle password at the same time, for example, we could write something like this:
event add menu.select_check password
event add menu.commandline_check passwordpassword command is run when user tries to select the menu item or enter command line.
Quoted 13 lines · Vladimir 'phcoder' Serbinenko
Hello. Here is a long-awaited savedefault patch. Works correctly only if my scripting fix is applied
--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 9 lines
--
Bean_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Regards
Vladimir 'phcoder' SerbinenkoQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Bean_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Hi!
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
cat << EOF
+load_env
set default=${GRUB_DEFAULT}
Does the "set" line override the settings in load_env? It looks like it would.
Quoted 29 lines
util/grub.d/10_freebsd.in +2
-0@@ -57,6 +57,8 @@ if [ "x$kfreebsd" != "x" ] ; then cat << EOF menuentry "${OS}" { + saved_entry=\${chosen_entry} + save_env saved_entry EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOFutil/grub.d/10_hurd.in +2
-0@@ -70,6 +70,8 @@ fi cat << EOF menuentry "${OS}" { + saved_entry=\${chosen_entry} + save_env saved_entry EOF prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" cat << EOFutil/grub.d/10_linux.in +0
-0
util/grub.d/10_linux.in linux_entry () · line 104
Quoted 8 lines
util/grub.d/10_linux.in +2
-0@@ -97,6 +97,8 @@ linux_entry () { cat << EOF menuentry "$1" { + saved_entry=\${chosen_entry} + save_env saved_entry EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOF
I think it'd really be a good idea to either factorize this into a function (ala prepare_grub_to_access_device), or make it part of the scripting engine. I'm afraid of the possibility that later we want to change something and can't because 3rd party scripts depend on it (this happened with disk selection before we had prepare_grub_to_access_device).
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoting Robert Millan <[email protected]>:
Quoted 8 lines
util/grub.d/10_freebsd.in if [ "x$kfreebsd" != "x" ] ; then · line 64
Quoted 5 lines
util/grub.d/10_freebsd.in +2
-0+ saved_entry=\${chosen_entry} + save_env saved_entry EOF prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/" cat << EOFI think it'd really be a good idea to either factorize this into a function (ala
prepare_grub_to_access_device), or make it part of the scripting engine.
I already mentioned the possibility of having an argument to save_env to allow saving a variable under a different name, e.g.:
save_env --as saved_entry chosen_entry
Another approach would be to allow saving text from the command line:
save_env saved_entry="$chosen_entry"
Quoted 4 lines
I'm afraid of the possibility that later we want to change something
and can't
because 3rd party scripts depend on it (this happened with disk selection before we hadprepare_grub_to_access_device).
I think we would want to use text, not numbers. We have enough space in the environment for that. It's more reliable.
Signature · 2 lines
Regards, Pavel Roskin