Improve error handling.
[grml2usb.git] / grml2usb
index 6d2a754..fa820bf 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -663,6 +663,7 @@ def unmount(target, unmount_options):
         proc = subprocess.Popen(["umount"] + list(unmount_options) + [target])
         proc.wait()
         if proc.returncode != 0:
+            logging.critical("Error executing umount")
             raise Exception("Error executing umount")
         else:
             logging.debug("unregister_mountpoint(%s)", target)
@@ -1049,7 +1050,7 @@ def copy_bootloader_files(iso_mount, target, grml_flavour):
         logging.critical("Fatal: file default.cfg could not be found.")
         logging.critical("Note:  this grml2usb version requires an ISO generated by grml-live >=0.9.24 ...")
         logging.critical("       ... either use grml releases >=2009.10 or switch to an older grml2usb version.")
-        raise
+        raise CriticalException("file default.cfg could not be found.")
 
     if not os.path.exists(iso_mount + '/boot/grub/footer.cfg'):
         logging.warning("Warning: Grml releases older than 2011.12 support only one flavour in grub.")
@@ -1472,7 +1473,7 @@ def install(image, device):
         logging.info("Using %s as install base", image)
     else:
         logging.info("Using ISO %s", image)
-        iso_mountpoint = tempfile.mkdtemp(prefix="grml2usb", dir=options.tmpdir)
+        iso_mountpoint = tempfile.mkdtemp(prefix="grml2usb", dir=os.path.abspath(options.tmpdir))
         register_tmpfile(iso_mountpoint)
         remove_image_mountpoint = True
         try:
@@ -1533,7 +1534,7 @@ def install_grml(mountpoint, device):
 
 
 def remove_mountpoint(mountpoint):
-    """remove a registred mountpoint
+    """remove a registered mountpoint
     """
 
     try:
@@ -1556,7 +1557,7 @@ def handle_mbr(device):
         return 0
 
     mbr_device, partition_number = get_device_from_partition(device)
-    if not partition_number:
+    if partition_number is None:
         logging.warn("Could not detect partition number, not activating partition")
 
     # if we get e.g. /dev/loop1 as device we don't want to put the MBR
@@ -1705,6 +1706,11 @@ def check_programs():
 
 def load_loop():
     """Runs modprobe loop and throws away it's output"""
+    if not which("modprobe"):
+        logging.critical("Fatal: modprobe not available, can not continue - sorry.")
+        logging.critical("Hint: is /sbin missing in PATH?")
+        sys.exit(1)
+
     proc = subprocess.Popen(["modprobe", "loop"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     proc.wait()