Merge remote-tracking branch 'origin/pr/26'
[grml2usb.git] / grml2usb
index b12cf88..6cf456a 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -56,7 +56,10 @@ DATESTAMP = time.mktime(datetime.datetime.now().timetuple())  # unique identifie
 GRML_FLAVOURS = set()  # which flavours are being installed?
 GRML_DEFAULT = None
 UUID = None
-SYSLINUX_LIBS = "/usr/lib/syslinux/modules/bios/"
+SYSLINUX_LIBS = [
+    "/usr/lib/syslinux/modules/bios/", # Debian
+    "/usr/lib/syslinux/bios/", # Arch Linux
+]
 GPT_HEADER = b"\x55\xaa\x45\x46\x49\x20\x50\x41\x52\x54"  # original GPT header
 GRUB_INSTALL = None
 
@@ -138,6 +141,8 @@ parser.add_option("--syslinux", dest="syslinux", action="callback", default=True
                   help="install syslinux bootloader (deprecated as it's the default)")
 parser.add_option("--syslinux-mbr", dest="syslinuxmbr", action="store_true",
                   help="install syslinux master boot record (MBR) instead of default")
+parser.add_option("--syslinux-libs", dest="syslinuxlibs", action="append", default=[],
+                  help="syslinux modules directory path")
 parser.add_option("--tmpdir", dest="tmpdir", default="/tmp",
                   help="directory to be used for temporary files")
 parser.add_option("--verbose", dest="verbose", action="store_true",
@@ -804,9 +809,7 @@ def check_for_fat(partition):
                 " (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, text=True)
-        filesystem = udev_info.communicate()[0].rstrip()
+        filesystem = subprocess.check_output(["/sbin/blkid", "-s", "TYPE", "-o", "value", partition]).decode().rstrip()
 
         if filesystem != "vfat":
             raise CriticalException(
@@ -814,7 +817,7 @@ def check_for_fat(partition):
                     "(Use --fat16 or run mkfs.vfat %s)" % (partition, partition))
 
     except OSError:
-        raise CriticalException("Sorry, /sbin/blkid not available (install e2fsprogs?)")
+        raise CriticalException("Sorry, /sbin/blkid not available (install util-linux?)")
 
 
 def mkdir(directory):
@@ -1129,8 +1132,11 @@ def copy_bootloader_files(iso_mount, target, grml_flavour):
       'prompt.cfg', 'vesamenu.cfg', 'grml.png', '*.c32':
         glob_and_copy(iso_mount + source_dir + expr, syslinux_target)
 
-    for filename in glob.glob1(syslinux_target, "*.c32"):
-        copy_if_exist(os.path.join(SYSLINUX_LIBS, filename), syslinux_target)
+    for modules_dir in options.syslinuxlibs + SYSLINUX_LIBS:
+        if os.path.isdir(modules_dir):
+            for filename in glob.glob1(syslinux_target, "*.c32"):
+                copy_if_exist(os.path.join(modules_dir, filename), syslinux_target)
+            break
 
     # copy the addons_*.cfg file to the new syslinux directory
     glob_and_copy(iso_mount + source_dir + 'addon*.cfg', syslinux_target)
@@ -1318,6 +1324,7 @@ def add_entry_if_not_present(filename, entry):
     @entry: data to write to the file
     """
     data = open(filename, "a+")
+    data.seek(0)
     for line in data:
         if line == entry:
             break
@@ -1690,7 +1697,7 @@ def handle_mbr(device):
                 mbrcode = mbrpath
                 break
 
-        if mbrcode is "":
+        if not mbrcode:
             str_locations = " or ".join(['"%s"' % l for l in mbr_locations])
             logging.error('Cannot find syslinux MBR, install it at %s)',
                           str_locations)