]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Use submenus in grub-mkconfig.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 4 Mar 2012 21:18:33 +0000 (22:18 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 4 Mar 2012 21:18:33 +0000 (22:18 +0100)
* util/grub-mkconfig.in: Define GRUB_ACTUAL_DEFAULT.
* util/grub-mkconfig_lib.in (grub_quote): New function.
(gettext_printf): Use gettext and not gettext_quoted to fix several
messages.
* util/grub.d/10_hurd.in: Use submenus.
* util/grub.d/10_kfreebsd.in: Likewise.
* util/grub.d/10_linux.in: Likewise.
* util/grub.d/10_netbsd.in: Likewise.
* util/grub.d/20_linux_xen.in: Likewise.
* util/grub.d/30_os-prober.in: Likewise.
* util/grub.d/10_illumos.in: Add missing quoting.
* util/grub.d/10_windows.in: Likewise.

ChangeLog
util/grub-mkconfig.in
util/grub-mkconfig_lib.in
util/grub.d/10_hurd.in
util/grub.d/10_illumos.in
util/grub.d/10_kfreebsd.in
util/grub.d/10_linux.in
util/grub.d/10_netbsd.in
util/grub.d/10_windows.in
util/grub.d/20_linux_xen.in
util/grub.d/30_os-prober.in

index 7932efe8ffa2c02330b806d265993da78c332ec3..39399d664d0d402812356d2494f4a6ae767dd27c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2012-03-04  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Use submenus in grub-mkconfig.
+
+       * util/grub-mkconfig.in: Define GRUB_ACTUAL_DEFAULT.
+       * util/grub-mkconfig_lib.in (grub_quote): New function.
+       (gettext_printf): Use gettext and not gettext_quoted to fix several
+       messages.
+       * util/grub.d/10_hurd.in: Use submenus.
+       * util/grub.d/10_kfreebsd.in: Likewise.
+       * util/grub.d/10_linux.in: Likewise.
+       * util/grub.d/10_netbsd.in: Likewise.
+       * util/grub.d/20_linux_xen.in: Likewise.
+       * util/grub.d/30_os-prober.in: Likewise.
+       * util/grub.d/10_illumos.in: Add missing quoting.
+       * util/grub.d/10_windows.in: Likewise.
+
 2012-03-04  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Fix menu title instability bug.
index 8ff9f74832e5f2536933e526dd29503bb9303262..45aa916d2ca9cdd98d2ca2a1e68bfd900605135b 100644 (file)
@@ -40,6 +40,7 @@ grub_mkconfig_dir="${sysconfdir}"/grub.d
 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 @@ for x in ${GRUB_TERMINAL_OUTPUT}; do
     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 @@ export GRUB_DEVICE \
   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 \
index ab3b934e0e7254466cd19eef93ce6d69621b6a9e..797c690690c2a64f07e4dc07d3a546e80214c96f 100644 (file)
@@ -239,6 +239,11 @@ version_find_latest ()
 # One layer of quotation is eaten by "", the second by sed, and the third by
 # printf; so this turns ' into \'.  Note that you must use the output of
 # this function in a printf format string.
+
+grub_quote () {
+  sed "s/'/'\\\\\\\\''/g"
+}
+
 gettext_quoted () {
   gettext "$@" | sed "s/'/'\\\\\\\\''/g"
 }
@@ -249,7 +254,7 @@ gettext_quoted () {
 gettext_printf () {
   gettext_printf_format="$1"
   shift
-  printf "$(gettext_quoted "$gettext_printf_format")" "$@"
+  printf "$(gettext "$gettext_printf_format")" "$@"
 }
 
 uses_abstraction () {
index 4f77a8d3f0749dcf06c2bbf3fa59204e47fb995c..64510605eaf5bc554c0c97ba5850fe933c4d1dbc 100644 (file)
@@ -79,49 +79,62 @@ if ${all_of_them} && test -e /lib/ld.so.1 ; then : ; else
   exit 1
 fi
 
-for kernel in ${kernels}
-do
+title_correction_code=
+
+hurd_entry () {
+  kernel="$1"
+  type="$2"
   kernel_base="`basename "${kernel}"`"
-  KERNEL="using ${kernel_base}"
 
-  cat << EOF
-menuentry "${OS} ${KERNEL}" ${CLASS} \$menuentry_id_option 'gnuhurd-$kernel-false-$(grub_get_device_id "${GRUB_DEVICE_BOOT}")' {
-EOF
-  prepare_grub_to_access_device "${GRUB_DEVICE_BOOT}" | sed -e "s/^/\t/"
-  message="$(gettext_printf "Loading GNU Mach ...")"
-  cat << EOF
-       echo            '$message'
-       multiboot       ${kernel} root=device:${GRUB_DEVICE#/dev/} ${GRUB_CMDLINE_GNUMACH}
+  if [ x$type != xsimple ] ; then
+      if [ x$type = xrecovery ] ; then
+         title="$(gettext_printf "%s, with Hurd %s (recovery mode)" "${OS}" "${kernel_base}")"
+         oldtitle="$OS using $kernel_base (recovery mode)"
+      else
+         title="$(gettext_printf "%s, with Hurd %s" "${OS}" "${kernel_base}")"
+         oldtitle="$OS using $kernel_base"
+      fi
+      if [ x"$oldtitle" = x"$GRUB_ACTUAL_DEFAULT" ]; then
+         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
+         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
+         grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnuhurd-advanced-$boot_device_id>'gnuhurd-$kernel-$type-$(grub_get_device_id "${GRUB_DEVICE_BOOT}")'")"
+      fi
+      sed "s/^/$submenu_indentation/" << EOF
+menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnuhurd-$kernel-$type-$(grub_get_device_id "${GRUB_DEVICE_BOOT}")' {
 EOF
-  save_default_entry | sed -e "s/^/\t/"
-  prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
-  message="$(gettext_printf "Loading the Hurd ...")"
-  cat << EOF
-       echo            '$message'
-       module          /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
-                       --multiboot-command-line='\${kernel-command-line}' \\
-                       --host-priv-port='\${host-port}' \\
-                       --device-master-port='\${device-port}' \\
-                       --exec-server-task='\${exec-task}' -T typed '\${root}' \\
-                       '\$(task-create)' '\$(task-resume)'
-       module          /lib/ld.so.1 exec /hurd/exec '\$(exec-task=task-create)'
-}
+  else
+      sed "s/^/$submenu_indentation/" << EOF
+menuentry '$(echo "$OS" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnuhurd-simple-$(grub_get_device_id "${GRUB_DEVICE_BOOT}")' {
 EOF
+  fi
 
-  cat << EOF
-menuentry "${OS} ${KERNEL} (recovery mode)" ${CLASS} {
-EOF
-  prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
+  prepare_grub_to_access_device "${GRUB_DEVICE_BOOT}" | sed -e "s/^/\t/"|sed "s/^/$submenu_indentation/"
   message="$(gettext_printf "Loading GNU Mach ...")"
-  cat << EOF
+
+  if [ x$type = xrecovery ] ; then
+      opts="-s"
+  else
+      opts=
+  fi
+  sed "s/^/$submenu_indentation/" << EOF
        echo            '$message'
-       multiboot       ${kernel} root=device:${GRUB_DEVICE#/dev/} -s ${GRUB_CMDLINE_GNUMACH}
+       multiboot       ${kernel} root=device:${GRUB_DEVICE#/dev/} $opts ${GRUB_CMDLINE_GNUMACH}
 EOF
-  prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
+
+  if [ x$type != xrecovery ] ; then
+      save_default_entry | sed -e "s/^/\t/"| sed "s/^/$submenu_indentation/"
+  fi
+  prepare_grub_to_access_device "${GRUB_DEVICE}" | sed -e "s/^/\t/"| sed "s/^/$submenu_indentation/"
   message="$(gettext_printf "Loading the Hurd ...")"
-  cat << EOF
+  if [ x$type = xrecovery ] ; then
+      opts=
+  else
+      opts="--readonly"
+  fi
+
+  sed "s/^/$submenu_indentation/" << EOF
        echo            '$message'
-       module          /hurd/${hurd_fs}.static ${hurd_fs} \\
+       module          /hurd/${hurd_fs}.static ${hurd_fs} $opts \\
                        --multiboot-command-line='\${kernel-command-line}' \\
                        --host-priv-port='\${host-port}' \\
                        --device-master-port='\${device-port}' \\
@@ -131,4 +144,35 @@ EOF
 }
 EOF
 
+}
+
+title_correction_code=
+
+# 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
+
+for kernel in ${kernels}
+do
+
+  if [ "x$is_first_entry" = xtrue ]; then
+      hurd_entry "$kernel" simple
+      submenu_indentation="\t"
+    
+      # TRANSLATORS: %s is replaced with an OS name
+      echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnuhurd-advanced-$(grub_get_device_id "${GRUB_DEVICE_BOOT}")' {"
+  fi
+
+  hurd_entry "$kernel" advanced
+  hurd_entry "$kernel" recovery
+  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 "$title_correction_code"
index e9bdf0872d476ea8d97cc3472c8b6953576c698e..422d56f2a14e5d60519c1b129b84793b5a0bac40 100644 (file)
@@ -34,7 +34,7 @@ case "${GRUB_DISTRIBUTOR}" in
   ;;
 esac
 
-echo "menuentry '${OS}' ${CLASS} \$menuentry_id_option 'illumos-$(grub_get_device_id "${GRUB_DEVICE_BOOT}")' {"
+echo "menuentry '$(echo "$OS" | grub_quote)' ${CLASS} \$menuentry_id_option 'illumos-$(grub_get_device_id "${GRUB_DEVICE_BOOT}")' {"
 save_default_entry | sed -e "s/^/\t/"
 prepare_grub_to_access_device "${GRUB_DEVICE_BOOT}" | sed -e "s/^/\t/"
 message="$(gettext_printf "Loading kernel of Illumos ...")"
index a7294724fa43f8985cfe4579624e6e665b0af747..93405a6d4f7ece39e90a1a89d74919fc1a15b29a 100644 (file)
@@ -63,37 +63,49 @@ load_kfreebsd_module ()
 EOF
 }
 
+title_correction_code=
+
 kfreebsd_entry ()
 {
   os="$1"
   version="$2"
-  recovery="$3"
+  type="$3"
   args="$4"
-  if ${recovery} ; then
-    title="$(gettext_quoted "%s, with kFreeBSD %s (recovery mode)")"
-  else
-    title="$(gettext_quoted "%s, with kFreeBSD %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 'kfreebsd-$version-$recovery-$boot_device_id' {\n" "${os}" "${version}"
-  if ! ${recovery} ; then
-      save_default_entry | sed -e "s/^/\t/"
+  if [ x$type != xsimple ] ; then
+      if [ x$type = xrecovery ] ; then
+         title="$(gettext_printf "%s, with kFreeBSD %s (recovery mode)" "${os}" "${version}")"
+      else
+         title="$(gettext_printf "%s, with kFreeBSD %s" "${os}" "${version}")"
+      fi
+      replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
+      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
+         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
+         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
+         grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "kfreebsd-advanced-$boot_device_id>kfreebsd-$version-$type-$boot_device_id")"
+      fi
+      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'kfreebsd-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+  else
+      echo "menuentry '$(echo "$OS" | grub_quote)' ${CLASS} \$menuentry_id_option 'kfreebsd-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+  fi
+  if [ x$type != xrecovery ] ; then
+      save_default_entry | sed -e "s/^/\t/" | sed "s/^/$submenu_indentation/"
   fi
   if [ -z "${prepare_boot_cache}" ]; then
     prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
   fi
 
-  printf '%s\n' "${prepare_boot_cache}"
+  printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
   message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})"
-  cat << EOF
+  sed "s/^/$submenu_indentation/" << EOF
        echo                    '$message'
        kfreebsd                ${rel_dirname}/${basename} ${args}
 EOF
 
   if test -n "${devices}" ; then
-    cat << EOF
+      sed "s/^/$submenu_indentation/" << EOF
        kfreebsd_loadenv        ${devices_rel_dirname}/${devices_basename}
 EOF
   fi
@@ -112,19 +124,19 @@ EOF
 
       ls "${dirname}/zfs/zpool.cache" > /dev/null
       printf '%s\n' "${prepare_boot_cache}"
-  cat << EOF
+      sed "s/^/$submenu_indentation/" << EOF
        kfreebsd_module         ${rel_dirname}/zfs/zpool.cache type=/boot/zfs/zpool.cache
 EOF
     ;;
   esac
 
   if [ x${kfreebsd_fs} = xufs ]; then
-       load_kfreebsd_module ${kfreebsd_fs} true
+       load_kfreebsd_module ${kfreebsd_fs} true | sed "s/^/$submenu_indentation/"
   else
-       load_kfreebsd_module ${kfreebsd_fs} false
+       load_kfreebsd_module ${kfreebsd_fs} false | sed "s/^/$submenu_indentation/"
   fi
 
-  cat << EOF
+  sed "s/^/$submenu_indentation/" << EOF
        set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device}
        set kFreeBSD.vfs.root.mountfrom.options=rw
 }
@@ -136,6 +148,13 @@ list=`for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
       done`
 prepare_boot_cache=
 boot_device_id=
+title_correction_code=
+
+# 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
   kfreebsd=`version_find_latest $list`
@@ -192,10 +211,31 @@ while [ "x$list" != "x" ] ; do
     module_dir_rel=$(make_system_path_relative_to_its_root $module_dir)
   fi
 
-  kfreebsd_entry "${OS}" "${version}" false
+  if [ "x$is_first_entry" = xtrue ]; then
+      kfreebsd_entry "${OS}" "${version}" simple
+      submenu_indentation="\t"
+    
+      if [ -z "$boot_device_id" ]; then
+         boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
+      fi
+      # TRANSLATORS: %s is replaced with an OS name
+      echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'kfreebsd-advanced-$boot_device_id' {"
+  fi
+
+  kfreebsd_entry "${OS}" "${version}" advanced
   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
-    kfreebsd_entry "${OS}" "${version}" true "-s"
+    kfreebsd_entry "${OS}" "${version}" recovery "-s"
   fi
 
   list=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | 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 "$title_correction_code"
+
index db1e81455cfda7f91d143ac1da335bb2e39ff5fd..f5d8a24062bbcc22b3748823dccdf751e936f72c 100644 (file)
@@ -66,77 +66,81 @@ case x"$GRUBFS" in
        GRUB_CMDLINE_LINUX="boot=zfs rpool=${RPOOL} bootfs=${RPOOL}${bootfs} ${cmdline} ${GRUB_CMDLINE_LINUX}";;
 esac
 
+title_correction_code=
+
 linux_entry ()
 {
   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_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
+         *)
+             title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
+      esac
+      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
+         replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
+         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
+         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
+         grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
+      fi
+      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+  else
+      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+  fi      
+  if [ x$type != xrecovery ] ; then
       save_default_entry | sed -e "s/^/\t/"
   fi
 
   # Use ELILO's generic "efifb" when it's known to be available.
   # FIXME: We need an interface to select vesafb in case efifb can't be used.
   if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
-      cat << EOF
-       load_video
-EOF
+      echo "   load_video" | sed "s/^/$submenu_indentation/"
       if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
          && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
-         cat << EOF
-       set gfxpayload=keep
-EOF
+         echo "        set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
       fi
   else
       if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
-         cat << EOF
-       load_video
-EOF
+         echo "        load_video" | sed "s/^/$submenu_indentation/"
       fi
-         cat << EOF
-       set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
-EOF
+      echo "   set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
   fi
 
-  cat << EOF
-       insmod gzio
-EOF
+  echo "       insmod gzio" | sed "s/^/$submenu_indentation/"
 
   if [ x$dirname = x/ ]; then
     if [ -z "${prepare_root_cache}" ]; then
       prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")"
     fi
-    printf '%s\n' "${prepare_root_cache}"
+    printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
   else
     if [ -z "${prepare_boot_cache}" ]; then
       prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
     fi
-    printf '%s\n' "${prepare_boot_cache}"
+    printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
   fi
   message="$(gettext_printf "Loading Linux %s ..." ${version})"
-  cat << EOF
+  sed "s/^/$submenu_indentation/" << EOF
        echo    '$message'
        linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
 EOF
   if test -n "${initrd}" ; then
     # TRANSLATORS: ramdisk isn't identifier. Should be translated.
     message="$(gettext_printf "Loading initial ramdisk ...")"
-    cat << EOF
+    sed "s/^/$submenu_indentation/" << EOF
        echo    '$message'
        initrd  ${rel_dirname}/${initrd}
 EOF
   fi
-  cat << EOF
+  sed "s/^/$submenu_indentation/" << EOF
 }
 EOF
 }
@@ -155,7 +159,13 @@ esac
 prepare_boot_cache=
 prepare_root_cache=
 boot_device_id=
+title_correction_code=
+
+# 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 +210,34 @@ while [ "x$list" != "x" ] ; do
     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
+    # TRANSLATORS: %s is replaced with an OS name
+    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
+  fi
+
+  linux_entry "${OS}" "${version}" advanced \
+              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
   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}"
   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 "$title_correction_code"
index 3f03a380b9e73d13fbf3f17529da177e130a63ee..65275d79ad4398c2fe4facb91e8b904f26373499 100644 (file)
@@ -85,40 +85,54 @@ netbsd_load_fs_module ()
   esac
 }
 
+title_correction_code=
+
 netbsd_entry ()
 {
   loader="$1"  # "knetbsd" or "multiboot"
   kernel="$2"  # absolute path to the kernel file
-  recovery="$3"        # is this is a recovery entry?
+  type="$3"
   args="$4"    # extra arguments appended to loader command
 
   kroot_device="$(echo ${GRUB_DEVICE} | sed -e 's,^/dev/r,,')"
-  if ${recovery} ; then
-    title="$(gettext_quoted "%s, with kernel %s (via %s, recovery mode)")"
-  else
-    title="$(gettext_quoted "%s, with kernel %s (via %s)")"
-  fi
 
   if [ -z "$boot_device_id" ]; then
       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
   fi
-  printf "menuentry \"${title}\" \$menuentry_id_option 'netbsd-$kernel-$recovery-$boot_device_id' {\n" \
-    "${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}"
-  printf "%s\n" "${prepare_boot_cache}"
+
+  if [ x$type != xsimple ] ; then
+      if [ x$type = xrecovery ] ; then
+         title="$(gettext_printf "%s, with kernel %s (via %s, recovery mode)" "${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}")"
+      else
+         title="$(gettext_printf "%s, with kernel %s (via %s)" "${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}")"
+      fi
+      replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
+      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
+         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
+         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
+         grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "netbsd-advanced-$boot_device_id>netbsd-${loader}-$kernel-$type-$boot_device_id")"
+      fi
+
+      echo "menuentry '$(echo "$title" | grub_quote)' \$menuentry_id_option 'netbsd-${loader}-$kernel-$type-$boot_device_id' {"  | sed "s/^/$submenu_indentation/"
+  else
+      echo "menuentry '$(echo "$OS" | grub_quote)' \$menuentry_id_option 'netbsd-${loader}-simple-$boot_device_id' {"  | sed "s/^/$submenu_indentation/"
+  fi
+
+  printf "%s\n" "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
   case "${loader}" in
     knetbsd)
       printf "\tknetbsd %s -r %s %s\n" \
-        "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
+        "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}" | sed "s/^/$submenu_indentation/"
       ;;
     multiboot)
       printf "\tmultiboot %s %s root=%s %s\n" \
-        "${kernel}" "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
+        "${kernel}" "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}" | sed "s/^/$submenu_indentation/"
       ;;
   esac
 
   netbsd_load_fs_module "${loader}" "${kernel}"
 
-  printf "}\n"
+  printf "}\n" | sed "s/^/$submenu_indentation/"
 }
 
 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e 's,^,      ,')"
@@ -128,6 +142,11 @@ boot_device_id=
 # pick all statically linked ELF executable files (or links) in / with a
 # name that starts with `netbsd'.
 pattern="^ELF[^,]*executable.*statically linked"
+# 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
 for k in $(ls -t /netbsd*) ; do
   if ! grub_file_is_not_garbage "$k" ; then
     continue
@@ -137,10 +156,31 @@ for k in $(ls -t /netbsd*) ; do
   fi
 
   gettext_printf "Found NetBSD kernel: %s\n" "$k" >&2
-  netbsd_entry "knetbsd"   "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
-  netbsd_entry "multiboot" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
+
+  if [ "x$is_first_entry" = xtrue ]; then
+      netbsd_entry "knetbsd"   "$k" simple "${GRUB_CMDLINE_NETBSD_DEFAULT}"
+    submenu_indentation="\t"
+    
+    if [ -z "$boot_device_id" ]; then
+       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
+    fi
+    # TRANSLATORS: %s is replaced with an OS name
+    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'netbsd-advanced-$boot_device_id' {"
+  fi
+
+  netbsd_entry "knetbsd"   "$k" advanced "${GRUB_CMDLINE_NETBSD_DEFAULT}"
+  netbsd_entry "multiboot" "$k" advanced "${GRUB_CMDLINE_NETBSD_DEFAULT}"
   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
-    netbsd_entry "knetbsd"   "$k" true "-s"
-    netbsd_entry "multiboot" "$k" true "-s"
+    netbsd_entry "knetbsd"   "$k" recovery "-s"
+    netbsd_entry "multiboot" "$k" recovery "-s"
   fi
+  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 "$title_correction_code"
index 63b748d0f7baf3474ff9d10210128c6d18ab858a..e5839cd29f48af37e3724876e403330532037574 100644 (file)
@@ -67,11 +67,11 @@ for drv in $drives ; do
 
   # Check for Vista bootmgr.
   if [ -f "$dir"/bootmgr -a -f "$dir"/boot/bcd ] ; then
-    OS="$(gettext_quoted "Windows Vista/7 (loader)")"
+    OS="$(gettext "Windows Vista/7 (loader)")"
     osid=bootmgr
   # Check for NTLDR.
   elif [ -f "$dir"/ntldr -a -f "$dir"/ntdetect.com -a -f "$dir"/boot.ini ] ; then
-    OS=`get_os_name_from_boot_ini "$dir"/boot.ini` || OS="$(gettext_quoted "Windows NT/2000/XP (loader)")"
+    OS=`get_os_name_from_boot_ini "$dir"/boot.ini` || OS="$(gettext "Windows NT/2000/XP (loader)")"
     osid=ntldr
     needmap=t
 
@@ -84,7 +84,7 @@ for drv in $drives ; do
 
   gettext_printf "Found %s on %s (%s)\n" "$OS" "$drv" "$dev" >&2
   cat << EOF
-menuentry "$OS" \$menuentry_id_option '$osid-$(grub_get_device_id "${dev}")' {
+menuentry '$(echo "$OS" | grub_quote)' \$menuentry_id_option '$osid-$(grub_get_device_id "${dev}")' {
 EOF
 
   save_default_entry | sed -e 's,^,\t,'
index 1fc34377c188e81e9d205022baee74c84968d24c..716565c434bf134865fa78242144956005ede1f9 100644 (file)
@@ -74,34 +74,47 @@ case x"$GRUBFS" in
        GRUB_CMDLINE_LINUX="boot=zfs rpool=${RPOOL} bootfs=${RPOOL}${bootfs} ${cmdline} ${GRUB_CMDLINE_LINUX}";;
 esac
 
+title_correction_code=
+
 linux_entry ()
 {
   os="$1"
   version="$2"
   xen_version="$3"
-  recovery="$4"
+  type="$4"
   args="$5"
   xen_args="$6"
-  if ${recovery} ; then
-    title="$(gettext_quoted "%s, with Xen %s and Linux %s (recovery mode)")"
-  else
-    title="$(gettext_quoted "%s, with Xen %s and 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 'xen-gnulinux-$version-$recovery-$boot_device_id' {\n" "${os}" "${xen_version}" "${version}"
-  if ! ${recovery} ; then
-      save_default_entry | sed -e "s/^/\t/"
+  if [ x$type != xsimple ] ; then
+      if [ x$type = xrecovery ] ; then
+         title="$(gettext_printf "%s, with Xen %s and Linux %s (recovery mode)" "${os}" "${xen_version}" "${version}")"
+      else
+         title="$(gettext_printf "%s, with Xen %s and Linux %s" "${os}" "${xen_version}" "${version}")"
+      fi
+      replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
+      if [ x"Xen ${xen_version}>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
+         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
+         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
+         grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
+      fi
+      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+  else
+      title="$(gettext_printf "%s, with Xen hypervisor" "${os}")"
+      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+  fi
+  if [ x$type != xrecovery ] ; then
+      save_default_entry | sed -e "s/^/\t/" | sed "s/^/$submenu_indentation/"
   fi
 
   if [ -z "${prepare_boot_cache}" ]; then
     prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
   fi
-  printf '%s\n' "${prepare_boot_cache}"
+  printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
   xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
   lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
-  cat << EOF
+  sed "s/^/$submenu_indentation/" << EOF
        echo    '$xmessage'
        multiboot       ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args}
        echo    '$lmessage'
@@ -110,12 +123,12 @@ EOF
   if test -n "${initrd}" ; then
     # TRANSLATORS: ramdisk isn't identifier. Should be translated.
     message="$(gettext_printf "Loading initial ramdisk ...")"
-    cat << EOF
+    sed "s/^/$submenu_indentation/" << EOF
        echo    '$message'
        module  ${rel_dirname}/${initrd}
 EOF
   fi
-  cat << EOF
+  sed "s/^/$submenu_indentation/" << EOF
 }
 EOF
 }
@@ -144,6 +157,14 @@ xen_list=`for i in /boot/xen*; do
 prepare_boot_cache=
 boot_device_id=
 
+title_correction_code=
+
+# 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${xen_list}" != "x" ] ; do
     list="${linux_list}"
     current_xen=`version_find_latest $xen_list`
@@ -154,7 +175,9 @@ while [ "x${xen_list}" != "x" ] ; do
     if [ -z "$boot_device_id" ]; then
        boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
     fi
-    echo "submenu \"Xen ${xen_version}\" \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
+    if [ "x$is_first_entry" != xtrue ]; then
+       echo "  submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
+    fi
     while [ "x$list" != "x" ] ; do
        linux=`version_find_latest $list`
        gettext_printf "Found linux image: %s\n" "$linux" >&2
@@ -183,15 +206,40 @@ while [ "x${xen_list}" != "x" ] ; do
            linux_root_device_thisversion=${GRUB_DEVICE}
        fi
 
-       linux_entry "${OS}" "${version}" "${xen_version}" false \
+       if [ "x$is_first_entry" = xtrue ]; then
+           linux_entry "${OS}" "${version}" "${xen_version}" simple \
+               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
+
+           submenu_indentation="\t\t"
+    
+           if [ -z "$boot_device_id" ]; then
+               boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
+           fi
+            # TRANSLATORS: %s is replaced with an OS name
+           echo "submenu '$(gettext_printf "Advanced options for %s (with Xen hypervisor)" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
+       echo "  submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
+       fi
+       is_first_entry=false
+
+       linux_entry "${OS}" "${version}" "${xen_version}" advanced \
            "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
        if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
-           linux_entry "${OS}" "${version}" "${xen_version}" true \
+           linux_entry "${OS}" "${version}" "${xen_version}" recovery \
                "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
        fi
 
        list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
     done
-    echo "}"
+    if [ x"$is_first_entry" != xtrue ]; then
+       echo '  }'
+    fi
     xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '`
 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 "$title_correction_code"
index 6ef4027e5e6b158599f8c92889d3edbdbb16cf5b..bcc6c2524ded3b002cd7db2f7294d291608cb6e3 100644 (file)
@@ -52,7 +52,7 @@ osx_entry() {
     # TRANSLATORS: it refers on the OS residing on device %s
     onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
         cat << EOF
-menuentry "${LONGNAME} $bitstr $onstr" --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")'  {
+menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")'  {
 EOF
        save_default_entry | sed -e "s/^/\t/"
        prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
@@ -73,10 +73,11 @@ EOF
               $1 /kernelcache boot-uuid=\${uuid} rd=*uuid
            else
               $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
-           elif [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
-              xnu_mkext /System/Library/Extensions.mkext
-           else
-              xnu_kextdir /System/Library/Extensions
+              if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
+                xnu_mkext /System/Library/Extensions.mkext
+              else
+                xnu_kextdir /System/Library/Extensions
+              fi
            fi
            if [ -f /Extra/Extensions.mkext ]; then
               xnu_mkext /Extra/Extensions.mkext
@@ -123,7 +124,7 @@ for OS in ${OSPROBED} ; do
 
          onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
       cat << EOF
-menuentry "${LONGNAME} $onstr" --class windows --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' {
+menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' {
 EOF
       save_default_entry | sed -e "s/^/\t/"
       prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
@@ -147,6 +148,9 @@ EOF
       LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
       prepare_boot_cache=
       boot_device_id=
+      is_first_entry=true
+      title_correction_code=
+      OS="${LONGNAME}"
 
       for LINUX in ${LINUXPROBED} ; do
         LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
@@ -166,7 +170,7 @@ EOF
        fi
 
        onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
-       recovery_params="$(echo "${LPARAMS}" | grep single)"
+       recovery_params="$(echo "${LPARAMS}" | grep single)" || true
        counter=1
        while echo "$used_osprober_linux_ids" | grep 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id' > /dev/null; do
            counter=$((counter+1));
@@ -175,26 +179,59 @@ EOF
            boot_device_id="$(grub_get_device_id "${DEVICE}")"
        fi
        used_osprober_linux_ids="$used_osprober_linux_ids 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id'"
-        cat << EOF
-menuentry "${LLABEL} $onstr" --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
-EOF
-       save_default_entry | sed -e "s/^/\t/"
+
        if [ -z "${prepare_boot_cache}" ]; then
          prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
        fi
-       printf '%s\n' "${prepare_boot_cache}"
-       cat <<  EOF
+
+       if [ "x$is_first_entry" = xtrue ]; then
+            cat << EOF
+menuentry '$(echo "$OS" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
+EOF
+           save_default_entry | sed -e "s/^/\t/"
+           printf '%s\n' "${prepare_boot_cache}"
+           cat <<  EOF
        linux ${LKERNEL} ${LPARAMS}
 EOF
-        if [ -n "${LINITRD}" ] ; then
+            if [ -n "${LINITRD}" ] ; then
           cat << EOF
        initrd ${LINITRD}
 EOF
-        fi
+            fi
         cat << EOF
 }
 EOF
+           echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'osprober-gnulinux-advanced-$boot_device_id' {"
+           is_first_entry=false
+       fi
+       title="${LLABEL} $onstr"
+        cat << EOF
+       menuentry '$(echo "$title" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
+EOF
+       save_default_entry | sed -e "s/^/\t\t/"
+       printf '%s\n' "${prepare_boot_cache}" | sed -e "s/^/\t/"
+       cat <<  EOF
+               linux ${LKERNEL} ${LPARAMS}
+EOF
+        if [ -n "${LINITRD}" ] ; then
+            cat << EOF
+               initrd ${LINITRD}
+EOF
+        fi
+        cat << EOF
+       }
+EOF
+       if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
+           replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
+           quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
+           title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
+           grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
+       fi
       done
+      if [ x"$is_first_entry" != xtrue ]; then
+         echo '}'
+      fi
+      echo "$title_correction_code"
     ;;
     macosx)
       OSXUUID="`${grub_probe} --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
@@ -204,7 +241,7 @@ EOF
     hurd)
       onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
       cat << EOF
-menuentry "${LONGNAME} $onstr" --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' {
+menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' {
 EOF
       save_default_entry | sed -e "s/^/\t/"
       prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"