Fix error message for unintialized partition [Closes: 857]
[grml2usb.git] / grml2usb
index 4205a32..e85d574 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -22,7 +22,7 @@ import uuid
 import struct
 
 # global variables
-PROG_VERSION = "0.9.26~git"
+PROG_VERSION = "0.9.27~git"
 MOUNTED = set()  # register mountpoints
 TMPFILES = set() # register tmpfiles
 DATESTAMP = time.mktime(datetime.datetime.now().timetuple()) # unique identifier for syslinux.cfg
@@ -649,7 +649,7 @@ def install_grub(device):
                     grub_device = device
 
                 logging.info("Installing grub as bootloader")
-                logging.debug("grub-install --recheck --no-floppy --root-directory=%s %s",
+                logging.debug("grub-install --recheck --force --no-floppy --root-directory=%s %s",
                               device_mountpoint, grub_device)
                 proc = subprocess.Popen(["grub-install", "--recheck", "--force", "--no-floppy",
                                          "--root-directory=%s" % device_mountpoint, grub_device],
@@ -699,18 +699,12 @@ def install_bootloader(device):
 
     # by default we use grub, so install syslinux only on request
     if options.grub:
-        if not which("grub-install"):
-            logging.critical("Fatal: grub-install not available (please install the "
-                             + "grub package or use the --syslinux option)")
+        try:
+            install_grub(device)
+        except CriticalException, error:
+            logging.critical("Fatal: %s", error)
             cleanup()
             sys.exit(1)
-        else:
-            try:
-                install_grub(device)
-            except CriticalException, error:
-                logging.critical("Fatal: %s", error)
-                cleanup()
-                sys.exit(1)
     else:
         try:
             install_syslinux(device)
@@ -980,19 +974,19 @@ def check_for_fat(partition):
 
     @partition: device name of partition"""
 
+    if not os.access(partition, os.R_OK):
+        raise CriticalException("Failed to read device %s"
+                " (wrong UID/permissions or device/directory not present?)" % partition)
+
     try:
         udev_info = subprocess.Popen(["/sbin/blkid", "-s", "TYPE", "-o", "value", partition],
                                      stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         filesystem = udev_info.communicate()[0].rstrip()
 
-        if udev_info.returncode == 2:
-            raise CriticalException("Failed to read device %s"
-                                    " (wrong UID/permissions or device/directory not present?)" % partition)
-
         if filesystem != "vfat":
             raise CriticalException(
-                    "Partition %s does not contain a FAT16 filesystem." % (partition) \
-                    + "(Use --fat16 or run mkfs.vfat %s)" % (partition))
+                    "Partition %s does not contain a FAT16 filesystem. "
+                    "(Use --fat16 or run mkfs.vfat %s)" % (partition, partition))
 
     except OSError:
         raise CriticalException("Sorry, /sbin/blkid not available (install e2fsprogs?)")
@@ -2057,7 +2051,6 @@ def main():
     if options.dryrun:
         logging.info("Running in simulation mode as requested via option dry-run.")
 
-
     # specified arguments
     device = args[len(args) - 1]
     isos = args[0:len(args) - 1]
@@ -2071,6 +2064,18 @@ def main():
             logging.critical("Fatal: installation on raw device not supported. (BIOS won't support it.)")
             sys.exit(1)
 
+    if options.grub:
+        if not which("grub-install"):
+            logging.critical("Fatal: grub-install not available (please install the "
+                             + "grub package or drop the --grub option)")
+            sys.exit(1)
+
+    if options.syslinux:
+        if not which("syslinux"):
+            logging.critical("Fatal: syslinux not available (please install the "
+                             + "syslinux package or use the --grub option)")
+            sys.exit(1)
+
     if not which("rsync"):
         logging.critical("Fatal: rsync not available, can not continue - sorry.")
         sys.exit(1)