grml2usb: abort if required logo.16 file is missing
[grml2usb.git] / grml2usb
index 1c2ed5b..f15dbf6 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2
 # -*- coding: utf-8 -*-
 # pylint: disable-msg=C0302
 """
@@ -7,7 +7,7 @@ grml2usb
 
 This script installs a Grml system (either a running system or ISO[s]) to a USB device
 
-:copyright: (c) 2009, 2010, 2011 by Michael Prokop <mika@grml.org>
+:copyright: (c) 2009-2019 by Michael Prokop <mika@grml.org>
 :license: GPL v2 or any later version
 :bugreports: http://grml.org/bugs/
 
@@ -69,10 +69,10 @@ def grub_option(option, opt, value, opt_parser):
 
 
 # cmdline parsing
-USAGE = "Usage: %prog [options] <[ISO[s] | /lib/live/mount/medium]> </dev/sdX#>\n\
+USAGE = "Usage: %prog [options] <[ISO[s] | /run/live/medium]> </dev/sdX#>\n\
 \n\
 %prog installs Grml ISO[s] to an USB device to be able to boot from it.\n\
-Make sure you have at least one Grml ISO or a running Grml system (/lib/live/mount/medium),\n\
+Make sure you have at least one Grml ISO or a running Grml system (/run/live/medium),\n\
 grub or syslinux and root access.\n\
 \n\
 Run %prog --help for usage hints, further information via: man grml2usb"
@@ -315,7 +315,7 @@ def get_defaults_file(iso_mount, flavour, name):
     return ('', '')
 
 
-def search_file(filename, search_path='/bin' + os.pathsep + '/usr/bin', lst_return=False):
+def search_file(filename, search_path='/bin' + os.pathsep + '/usr/bin', lst_return=False, required=False):
     """Given a search path, find file
 
     @filename: name of file to search for
@@ -344,6 +344,10 @@ def search_file(filename, search_path='/bin' + os.pathsep + '/usr/bin', lst_retu
                 retval.append(os.path.abspath(os.path.join(current_dir, filename)))
                 if not lst_return:
                     break
+
+    if required and not retval:
+        raise CriticalException("Required file %s not found in %s" % (filename, search_path))
+
     if lst_return:
         return retval
     elif retval:
@@ -1108,7 +1112,7 @@ def copy_bootloader_files(iso_mount, target, grml_flavour):
     grub_target = target + '/boot/grub/'
     execute(mkdir, grub_target)
 
-    logo = search_file('logo.16', iso_mount)
+    logo = search_file('logo.16', iso_mount, required=True)
     exec_rsync(logo, syslinux_target + 'logo.16')
 
     bootx64_efi = search_file('bootx64.efi', iso_mount)
@@ -1227,7 +1231,7 @@ def identify_grml_flavour(mountpath):
     version_files = search_file('grml-version', mountpath, lst_return=True)
 
     if not version_files:
-        if mountpath.startswith("/lib/live/mount/medium"):
+        if mountpath.startswith("/run/live/medium"):
             logging.critical("Error: could not find grml-version file.")
             logging.critical("Looks like your system is running from RAM but required files are not available.")
             logging.critical("Please either boot without toram=... or use boot option toram instead of toram=...")
@@ -1300,6 +1304,10 @@ def handle_grub_config(grml_flavour, device, target):
                 if shortname in filename:
                     line = live_media_path_re.sub('', line)
                     line = line.rstrip() + ' live-media-path=/live/%s/ ' % (grml_flavour)
+                if bootopt.strip():
+                    line = line.replace(' {} '.format(bootopt.strip()), ' ')
+                    if line.endswith(bootopt):
+                        line = line[:-len(bootopt)]
                 line = line.rstrip() + r' bootid=%s %s ' % (UUID, bootopt)
                 for regex in remove_regexes:
                     line = regex.sub(' ', line)
@@ -1628,7 +1636,7 @@ def install(image, device):
 def install_grml(mountpoint, device):
     """Main logic for copying files of the currently running Grml system.
 
-    @mountpoint: directory where currently running live system resides (usually /lib/live/mount/medium)
+    @mountpoint: directory where currently running live system resides (usually /run/live/medium)
     @device: partition where the specified ISO should be installed to"""
 
     device_mountpoint = device