setup-gummiboot-conf: fix non-existing kernels handling
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Thu, 7 Nov 2013 12:54:34 +0000 (14:54 +0200)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Thu, 7 Nov 2013 13:25:19 +0000 (15:25 +0200)
This patch is a bug-fix and it fixes the case when the default entry in
'loader.conf' does not actually exist in 'loader/entries'. Instead of failing,
we should just find the newest existing version of the kernel.

Change-Id: I61e169f37b5487b8abd6188a771f37f2f08ab328
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
setup-gummiboot-conf

index fa0cf58..5a84ad9 100755 (executable)
@@ -68,11 +68,13 @@ default_entry="$(cat "$conf_file" | sed -n -e 's/[ \t]*default[ \t]\+\(.\+\)[ \t
 [ "$(printf "%s\n" "$default_entry" | wc -l)" -eq "1" ] || \
        fatal "more than one default entry in \"$conf_file\""
 
-if ! [ -f "$entries_dir/$default_entry" ]; then
-       # The default entry does not exist anymore. Pick the entry
-       # corresponding to the newest kernel then.
-       default_entry="$(printf "%s" "$entries" | head -n1)"
-fi
+while ! [ -f "$entries_dir/$default_entry" ]; do
+        # The default entry does not exist anymore. Remove it and pick the
+        # entry corresponding to the newest installed kerne.
+        rm -f "$entries_dir/$default_entry"
+        entries="$(printf "%s" "$entries" | tail -n+2)"
+        default_entry="$(printf "%s" "$entries" | head -n1).conf"
+done
 
 # Use the default entry to prepare the pattern for other entries
 pattern="$(cat "$entries_dir/$default_entry")"