From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>,
Colin Watson <cjwatson@ubuntu.com>
Subject: Re: [PATCH] Add submenu support to 10_linux (grub-mkconfig)
Date: Sat, 03 Mar 2012 15:41:37 +0100 [thread overview]
Message-ID: <4F522DA1.4020705@gmail.com> (raw)
In-Reply-To: <4F5228C0.2020409@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 209 bytes --]
> Right now I believe that (1) is the most reasonable
>
Somethine like in the attached patch. I haven't tested it yet in real
migration scenario though
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: menu.diff --]
[-- Type: text/x-diff, Size: 4621 bytes --]
=== modified file 'util/grub-mkconfig.in'
--- util/grub-mkconfig.in 2012-03-03 12:05:08 +0000
+++ util/grub-mkconfig.in 2012-03-03 14:39:52 +0000
@@ -40,6 +40,7 @@
self=`basename $0`
grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`"
+grub_editenv="${bindir}/`echo grub-editenv | sed "${transform}"`"
grub_script_check="${bindir}/`echo grub-script-check | sed "${transform}"`"
export TEXTDOMAIN=@PACKAGE@
@@ -165,6 +166,11 @@
esac
done
+GRUB_ACTUAL_DEFAULT="$GRUB_DEFAULT"
+
+if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
+
+
# These are defined in this script, export them here so that user can
# override them.
export GRUB_DEVICE \
@@ -173,7 +179,8 @@
GRUB_DEVICE_BOOT_UUID \
GRUB_FS \
GRUB_FONT \
- GRUB_PRELOAD_MODULES
+ GRUB_PRELOAD_MODULES \
+ GRUB_ACTUAL_DEFAULT
# These are optional, user-defined variables.
export GRUB_DEFAULT \
=== modified file 'util/grub.d/10_linux.in'
--- util/grub.d/10_linux.in 2012-03-03 12:12:41 +0000
+++ util/grub.d/10_linux.in 2012-03-03 14:38:30 +0000
@@ -70,18 +70,39 @@
{
os="$1"
version="$2"
- recovery="$3"
+ type="$3"
args="$4"
- if ${recovery} ; then
- title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
- else
- title="$(gettext_quoted "%s, with Linux %s")"
- fi
+
if [ -z "$boot_device_id" ]; then
boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
fi
- printf "menuentry '${title}' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$recovery-$boot_device_id' {\n" "${os}" "${version}"
- if ! ${recovery} ; then
+ if [ x$type != xsimple ] ; then
+ case $type in
+ recovery)
+ title="$(gettext_quoted "%s, with Linux %s (recovery mode)")" ;;
+ *)
+ title="$(gettext_quoted "%s, with Linux %s")" ;;
+ esac
+ full_title="$(printf '${title}' "${os}" "${version}")"
+ if [ x"$full_title" = x"$GRUB_ACTUAL_DEFAULT" ] ; then
+ quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | sed "s/'/'\\\\\\\\''/g")"
+ suffix="${suffix}if [ \"x\$default\" = '$quoted' ]; then
+default='gnulinux-$version-$type-$boot_device_id'
+fi
+"
+ fi
+ if [ x"Previous Linux versions>$full_title" = x"$GRUB_ACTUAL_DEFAULT" ] ; then
+ quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | sed "s/'/'\\\\\\\\''/g")"
+ suffix="${suffix}if [ \"x\$default\" = '$quoted' ]; then
+default='gnulinux-$version-$type-$boot_device_id'
+fi
+"
+ fi
+ echo "menuentry '${full_title}' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {"
+ else
+ echo "menuentry '${os}' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {"
+ fi
+ if [ x$type != xrecovery ] ; then
save_default_entry | sed -e "s/^/\t/"
fi
@@ -155,7 +176,13 @@
prepare_boot_cache=
prepare_root_cache=
boot_device_id=
-
+suffix=
+
+# Extra indentation to add to menu entries in a submenu. We're not in a submenu
+# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
+submenu_indentation=""
+
+is_first_entry=true
while [ "x$list" != "x" ] ; do
linux=`version_find_latest $list`
gettext_printf "Found linux image: %s\n" "$linux" >&2
@@ -200,12 +227,37 @@
linux_root_device_thisversion=${GRUB_DEVICE}
fi
- linux_entry "${OS}" "${version}" false \
- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
+ if [ "x$is_first_entry" = xtrue ]; then
+ linux_entry "${OS}" "${version}" simple \
+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
+
+ submenu_indentation="\t"
+
+ if [ -z "$boot_device_id" ]; then
+ boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
+ fi
+ cat << EOF
+submenu '$(gettext_quoted "Advanced options for ${OS}")' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {
+EOF
+ fi
+
+ linux_entry "${OS}" "${version}" advanced \
+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" \
+ | sed "s/^/$submenu_indentation/"
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
- linux_entry "${OS}" "${version}" true \
- "single ${GRUB_CMDLINE_LINUX}"
+ linux_entry "${OS}" "${version}" recovery \
+ "single ${GRUB_CMDLINE_LINUX}" \
+ | sed "s/^/$submenu_indentation/"
fi
list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
+ is_first_entry=false
done
+
+# If at least one kernel was found, then we need to
+# add a closing '}' for the submenu command.
+if [ x"$is_first_entry" != xtrue ]; then
+ echo '}'
+fi
+
+echo -n "$suffix"
\ No newline at end of file
next prev parent reply other threads:[~2012-03-03 14:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-27 23:27 [PATCH] Add submenu support to 10_linux (grub-mkconfig) Jordan Uggla
2012-02-29 6:10 ` Jordan Uggla
2012-03-03 14:20 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-03-03 14:41 ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2012-03-03 16:46 ` Vladimir 'φ-coder/phcoder' Serbinenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F522DA1.4020705@gmail.com \
--to=phcoder@gmail.com \
--cc=cjwatson@ubuntu.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.