linux-boot-probe: fix mounted/40grub2 menuentry parsing
authorTJ <git@iam.tj>
Thu, 14 Dec 2017 19:52:27 +0000 (19:52 +0000)
committerTJ <git@iam.tj>
Thu, 14 Dec 2017 19:52:27 +0000 (19:52 +0000)
linux-boot-probes/mounted/common/40grub2

index 885614e..31e0c50 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-. /usr/share/os-prober/common.sh
+. usr/share/os-prober/common.sh
 set -e
 
 partition="$1"
@@ -43,20 +43,19 @@ parse_grub_menu () {
                        menuentry)
                                entry_result
                                shift 1
-                               # The double-quoted string is the title.
-                               # Make sure to look at the text of the line
-                               # before 'set' mangled it.
-                               title="$(echo "$line" | sed -n 's/[^"]*"\(.*\)".*/\1/p' | sed 's/://g')"
-                               if [ -z "$title" ]; then
-                                       # ... or single-quoted?  Be careful
-                                       # to handle constructions like
-                                       # 'foo'\''bar' (which expands to
-                                       # foo'bar, as in shell), and to
-                                       # handle multiple single-quoted
-                                       # strings on the same line.
-                                       title="$(echo "$line" | sed -n "s/[^']*'\(\([^']\|'\\\\''\)*\)'.*/\1/p" | sed "s/'\\\\''/'/; s/://g")"
-                               fi
+        # strip all of: --option=abcd --option='ab cd' --option="ab cd" menuentry { command block
+        # and everything else except the first quoted string or non-space word
+        # and remove any : from the remaining title
+        title=$( printf "%s" "$line"  | sed -n "s/^[[:blank:]]*//; p" )
+        title=$( printf "%s" "$title" | sed -n "s/--[^ ]*=\(\([\"']\)[^\"']*\2 \|[^ ]* \)//g; p" )
+        title=$( printf "%s" "$title" | sed -n "s/{//; p" )
+        title=$( printf "%s" "$title" | sed -n "s/menuentry//; p" )
+        title=$( printf "%s" "$title" | sed -n "s/^[ ]*\(\([\"']\{1\}\)\(.*\)\2\|\([^\"' ][^ ]*\)\).*/\3\4/; p" )
+        title=$( printf "%s" "$title" | sed -n "s/\\\\'//; p" )
+        title=$( printf "%s" "$title" | sed -n "s/''//; p" )
+        title=$( printf "%s" "$title" | sed -n "s/://g; p" )
                                if [ -z "$title" ]; then
+          echo "No title: $line"
                                        ignore_item=1
                                elif echo "$title" | grep -q '(on /dev/[^)]*)$'; then
                                        log "Skipping entry '$title':"