+
+def search_and_copy(filename, search_path, dst):
+ """Search for the specified filename at searchpath and copy it to dst
+
+ @filename: filename to look for
+ @search_path: base search file
+ @dst: destionation to copy the file to
+ """
+ file_location = search_file(filename, search_path)
+ copy_if_exist(file_location, dst)
+
+
+def copy_if_exist(filename, dst):
+ """Copy filename to dst if filename is set.
+
+ @filename: a filename
+ @dst: dst file
+ """
+ if filename and (os.path.isfile(filename) or os.path.isdir(filename)):
+ exec_rsync(filename, dst)
+
+
+def copy_bootloader_files(iso_mount, target, grml_flavour):
+ """Copy grml's bootloader files to a given target
+
+ @iso_mount: path where a grml ISO is mounted on
+ @target: path where grml's main files should be copied to
+ @grml_flavour: name of the current processed grml_flavour
+ """
+
+ syslinux_target = target + "/boot/syslinux/"
+ execute(mkdir, syslinux_target)
+
+ grub_target = target + "/boot/grub/"
+ execute(mkdir, grub_target)
+
+ logo = search_file("logo.16", iso_mount, required=True)
+ exec_rsync(logo, syslinux_target + "logo.16")
+
+ bootx64_efi = search_file("bootx64.efi", iso_mount)
+ if bootx64_efi:
+ mkdir(target + "/efi/boot/")
+ exec_rsync(bootx64_efi, target + "/efi/boot/bootx64.efi")
+
+ efi_img = search_file("efi.img", iso_mount)
+ if efi_img:
+ mkdir(target + "/boot/")
+ exec_rsync(efi_img, target + "/boot/efi.img")
+ handle_secure_boot(target, efi_img)
+
+ for ffile in ["f%d" % number for number in range(1, 11)]:
+ search_and_copy(ffile, iso_mount, syslinux_target + ffile)
+
+ # avoid the "file is read only, overwrite anyway (y/n) ?" question
+ # of mtools by syslinux ("mmove -D o -D O s:/ldlinux.sys $target_file")
+ if os.path.isfile(syslinux_target + "ldlinux.sys"):
+ os.unlink(syslinux_target + "ldlinux.sys")
+
+ (source_dir, name) = get_defaults_file(iso_mount, grml_flavour, "default.cfg")
+ (source_dir, defaults_file) = get_defaults_file(iso_mount, grml_flavour, "grml.cfg")
+
+ if not source_dir:
+ raise CriticalException(
+ "file default.cfg could not be found.\n"
+ "Note: this grml2usb version requires an ISO generated by grml-live >=0.9.24 ...\n"
+ " ... either use grml releases >=2009.10 or switch to an older grml2usb version."
+ )
+
+ 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."
+ )
+
+ for expr in (
+ name,
+ "distri.cfg",
+ defaults_file,
+ "grml.png",
+ "hd.cfg",
+ "isolinux.cfg",
+ "isolinux.bin",
+ "isoprompt.cfg",
+ "options.cfg",
+ "prompt.cfg",
+ "vesamenu.cfg",
+ "grml.png",
+ "*.c32",
+ ):
+ glob_and_copy(iso_mount + source_dir + expr, 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)
+
+ search_and_copy(
+ "hidden.cfg", iso_mount + source_dir, syslinux_target + "new_" + "hidden.cfg"
+ )
+
+ # copy all grub files from ISO
+ glob_and_copy(iso_mount + "/boot/grub/*", grub_target)
+
+ # finally (after all GRUB files have been installed) build static loopback.cfg
+ build_loopbackcfg(target)