Maintainer scripts: test for presence of grub.cfg, don't execute update-grub otherwise
authorMichael Prokop <mika@grml.org>
Mon, 20 Feb 2012 13:52:24 +0000 (14:52 +0100)
committerMichael Prokop <mika@grml.org>
Mon, 20 Feb 2012 13:52:24 +0000 (14:52 +0100)
Let's do the same as memtest86+-4.20 does: test for presence of
/boot/grub/grub.cfg, if the file exists (and running some other
checks) we can execute update-grub, otherwise don't care....

This is supposed to address the annoying:

| /usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).

issue which is showing up in minimal chroots on package removal.

Closes: #660588

debian/postinst
debian/postrm

index 131e59f..d5f9b75 100644 (file)
@@ -3,27 +3,39 @@
 
 set -e
 
 
 set -e
 
+update_grub_wrapper() {
+  # default, unless configured otherwise:
+  ISO_LOCATION=/boot/grml
+
+  if [ -r /etc/default/grml-rescueboot ] ; then
+    . /etc/default/grml-rescueboot
+  fi
+
+  if ! ls "${ISO_LOCATION}"/*iso >/dev/null 2>&1 ; then
+    echo "INFO: No *.iso files found inside ${ISO_LOCATION}."
+    echo "INFO: Please create ${ISO_LOCATION} and place rescue ISO(s) there."
+    echo "INFO: Finally invoke update-grub and enjoy your rescue system."
+    return 0
+  fi
+
+  if ! which update-grub >/dev/null 2>&1; then
+    echo "WARN: ISOs found inside ${ISO_LOCATION} but update-grub not present (huh?)"
+    return 0
+  fi
+
+  if ! [ -e /boot/grub/grub.cfg ] ; then
+    echo "WARN: ISOs found inside ${ISO_LOCATION} but /boot/grub/grub.cfg does not exist."
+    echo "WARN: Ignoring request to run update-grub to avoid possible boot loader problems."
+    return 0
+  fi
+
+  echo "INFO: ISOs found inside ${ISO_LOCATION}, invoking update-grub:"
+  update-grub
+}
+
 case "$1" in
     configure)
 case "$1" in
     configure)
-      # default, unless configured otherwise:
-      ISO_LOCATION=/boot/grml
-
-      if [ -r /etc/default/grml-rescueboot ] ; then
-       . /etc/default/grml-rescueboot
-      fi
-
-      if ! ls "${ISO_LOCATION}"/*iso >/dev/null 2>&1 ; then
-       echo "INFO: No *.iso files found inside ${ISO_LOCATION}."
-        echo "INFO: Please create ${ISO_LOCATION} and place rescue ISO(s) there."
-       echo "INFO: Finally invoke update-grub and enjoy your rescue system."
-      else
-       if ! which update-grub >/dev/null 2>&1; then
-         echo "WARN: ISOs found inside ${ISO_LOCATION} but update-grub not present (huh?)"
-       else
-         echo "INFO: ISOs found inside ${ISO_LOCATION}, invoking update-grub:"
-          update-grub
-        fi
-      fi
+      update_grub_wrapper
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)
index 2154b59..dc1ef1d 100644 (file)
@@ -5,7 +5,7 @@ set -e
 
 case "$1" in
     purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
 
 case "$1" in
     purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
-      if which update-grub >/dev/null 2>&1; then
+      if test -e /boot/grub/grub.cfg && which update-grub >/dev/null 2>&1; then
         echo "Updating grub.cfg to make sure there are no non-existing entries being left."
         update-grub
       fi
         echo "Updating grub.cfg to make sure there are no non-existing entries being left."
         update-grub
       fi