summarylogtreecommitdiffstats
path: root/find-grub-dir.patch
blob: f891c84568cfd07a295bad39c18b1e80ef9c8c1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Index: b/util/grub-set-default.in
===================================================================
--- a/util/grub-set-default.in
+++ b/util/grub-set-default.in
@@ -74,18 +74,45 @@
     exit 1
 fi
 
+find_grub_dir ()
+{
+        echo  -n "Searching for GRUB installation directory ... " >&2
+
+        for d in $grub_dirs ; do
+                if [ -d "$d" ] ; then
+                        grub_dir="$d"
+                        break
+                fi
+        done
+
+        if [ -z "$grub_dir" ] ; then
+                abort "No GRUB directory found.\n###"
+        else
+                echo "found: $grub_dir" >&2
+        fi
+
+        echo $grub_dir
+}
+
+grub_dirs="/boot/grub /boot/boot/grub"
+
 # Determine the GRUB directory. This is different among OSes.
-grubdir=${rootdir}/boot/grub
-if test -d ${grubdir}; then
+# if rootdir has been informed use it or find grubdir otherwise
+if [ -n "${rootdir}" ]; then
+  grubdir=${rootdir}/boot/grub
+  if test -d ${grubdir}; then
     :
-else
+  else
     grubdir=${rootdir}/grub
     if test -d ${grubdir}; then
-	:
+        :
     else
-	echo "No GRUB directory found under ${rootdir}/" 1>&2
-	exit 1
+        echo "No GRUB directory found under ${rootdir}/" 1>&2
+        exit 1
     fi
+  fi
+else
+  grubdir=$(find_grub_dir)
 fi
 
 file=${grubdir}/default