File os-prober-1.49-fix-grub2.cfg-parsing.patch of Package os-prober.1605

From: Andrey Borzenkov <arvidjaar@gmail.com>
Subject: fix parsing GRUB2 grub.cfg
References: bnc#796919

Fix several problems in parsing of grub.cfg by
linux-boot-probes/mounted/40grub2

1. Look for /boot/grub2-efi/grub.cfg as well (openSUSE 12.2)

2. It checked for literal "(on /dev/.*)" to filter out menu entries
added by another os-prober on target system. But grub.cfg now includes
TRANSLATED strings, so this check will fail if grub.cfg was created in
non-English locale. Use menu entry ID to check whether entry was added
by os-prober (it always starts with osprober-). Suggested by Vladimir
Serbienko.
Index: os-prober-1.61/linux-boot-probes/mounted/common/40grub2
===================================================================
--- os-prober-1.61.orig/linux-boot-probes/mounted/common/40grub2
+++ os-prober-1.61/linux-boot-probes/mounted/common/40grub2
@@ -43,6 +43,13 @@ parse_grub_menu () {
 			menuentry)
 				entry_result
 				shift 1
+				# Currently GRUB2 puts translated strings
+				# in grub.cfg, so checking for verbatim
+				# (on /dev/.*) will fail if target grub.cfg
+				# was created in non-English locale. Extract
+				# menu entry ID and check if it starts with
+				# "osprober-"
+				id="$(echo "$line" | sed -n 's/^.*[[:space:]]\+\(\$menuentry_id_option\|--id\)[[:space:]]\+\([^[:space:]]\+\).*$/\2/p')"
 				# The double-quoted string is the title.
 				# Make sure to look at the text of the line
 				# before 'set' mangled it.
@@ -58,9 +65,9 @@ parse_grub_menu () {
 				fi
 				if [ -z "$title" ]; then
 					ignore_item=1
-				elif echo "$title" | grep -q '(on /dev/[^)]*)$'; then
+				elif echo "$title" | grep -q '(on /dev/[^)]*)$' || echo "$id" | grep -q "^\([\"']\|\)osprober-"; then
 					log "Skipping entry '$title':"
-					log "appears to be an automatic reference taken from another menu.lst"
+					log "appears to be an automatic reference taken from another grub.cfg"
 					ignore_item=1
 				fi
 			;;
@@ -98,6 +105,9 @@ if [ -e "$mpoint/boot/grub/grub.cfg" ] &
     [ "$mpoint/boot/grub/grub.cfg" -nt "$mpoint/boot/grub/menu.lst" ]); then
 	debug "parsing grub.cfg"
 	parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub/grub.cfg"
+elif [ -e "$mpoint/boot/grub2-efi/grub.cfg" ]; then
+	debug "parsing grub.cfg"
+	parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub2-efi/grub.cfg"
 elif [ -e "$mpoint/boot/grub2/grub.cfg" ]; then
 	debug "parsing grub.cfg"
 	parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub2/grub.cfg"
openSUSE Build Service is sponsored by