From 03077403d291bbdadd6e0485e73870db234b28a2 Mon Sep 17 00:00:00 2001 From: Shinji Suzuki Date: Tue, 20 Mar 2018 14:08:58 +0900 Subject: [PATCH] Fix regression introduced by 8ea5932bdcd706d7ca4c8b44aa7b0a424daec59d. With the change in the commit, loopback.cfg got regenerated at the location of file determined by scanning iso tree. If no loopback.cfg was found, it was assumed to be at the distribution root directory. In either case, loopback.cfg was generated/overwritten at the determined location and the file was chosen for booting. Now, if no loopback.cfg is found, grub.cfg is sought. It is only in the case where neither is found that loopback.cfg gets generated and used. Therefore no config files provided by distro get overwritten. --- scripts/grub.py | 149 +++++++++++++++++++----------------------------- scripts/iso.py | 4 ++ 2 files changed, 64 insertions(+), 89 deletions(-) diff --git a/scripts/grub.py b/scripts/grub.py index 37647cf..fccb1ec 100644 --- a/scripts/grub.py +++ b/scripts/grub.py @@ -20,60 +20,68 @@ def mbusb_update_grub_cfg(): Function to update grub.cfg file to support UEFI/EFI systems :return: """ - # Lets convert syslinux config file to grub2 accepted file format. + install_dir = os.path.join(config.usb_mount, 'multibootusb', iso.iso_basename(config.image_path)) - - # First write custom loopback.cfg file so as to be detected by iso2grub2 function later. - - # There may be more than one loopback.cfg but we just need to fix - # one and that is goingn to be referenced in mbusb's grub.cfg. - loopback_cfg_path = iso.iso_file_path(config.image_path, 'loopback.cfg') - if not loopback_cfg_path: - loopback_cfg_path = 'loopback.cfg' - - wrote_custom_cfg = write_custom_grub_cfg(install_dir, loopback_cfg_path) - - # Try to generate loopback entry file from syslinux config files - try: - gen.log('Trying to create loopback.cfg') - iso2_grub2_cfg = iso2grub2(install_dir, loopback_cfg_path, - wrote_custom_cfg) - except Exception as e: - print(e) - gen.log(e) - gen.log('Error converting syslinux cfg to grub2 cfg', error=True) - iso2_grub2_cfg = False - grub_cfg_path = None syslinux_menu = None -# sys_cfg_path = None - mbus_grub_cfg_path = os.path.join(config.usb_mount, 'multibootusb', 'grub', 'grub.cfg') -# iso_grub_cfg = iso.iso_file_path(config.image_path, 'grub.cfg') - if iso.isolinux_bin_dir(config.image_path) is not False: - iso_sys_cfg_path = os.path.join(iso.isolinux_bin_dir(config.image_path), 'syslinux.cfg') - iso_iso_cfg_path = os.path.join(iso.isolinux_bin_dir(config.image_path), 'isolinux.cfg') - - if os.path.exists(os.path.join(config.usb_mount, 'multibootusb', iso.iso_basename(config.image_path), - iso_sys_cfg_path)): - syslinux_menu = iso_sys_cfg_path.replace('\\', '/') - elif os.path.exists(os.path.join(config.usb_mount, 'multibootusb', iso.iso_basename(config.image_path), - iso_iso_cfg_path)): - syslinux_menu = iso_iso_cfg_path.replace('\\', '/') - - efi_grub_cfg = get_grub_cfg(config.image_path) - boot_grub_cfg = get_grub_cfg(config.image_path, efi=False) - - if loopback_cfg_path is not False: - grub_cfg_path = loopback_cfg_path.replace('\\', '/') - elif efi_grub_cfg is not False: - grub_cfg_path = efi_grub_cfg.replace('\\', '/') - elif boot_grub_cfg is not False: - grub_cfg_path = boot_grub_cfg.replace('\\', '/') - elif iso2_grub2_cfg is not False: - grub_cfg_path = iso2_grub2_cfg.replace('\\', '/') - #elif bootx_64_cfg is not False: - # grub_cfg_path = bootx_64_cfg.replace('\\', '/') + mbus_grub_cfg_path = os.path.join(config.usb_mount, 'multibootusb', + 'grub', 'grub.cfg') + isobin_dir = iso.isolinux_bin_dir(config.image_path) + if isobin_dir is not False: + for name in ['syslinux.cfg', 'isolinux.cfg']: + cfg_path = os.path.join(isobin_dir, name) + cfg_fullpath = os.path.join(install_dir, cfg_path) + if os.path.exists(cfg_fullpath): + syslinux_menu = cfg_path.replace('\\', '/') + break + + # Decide which grub config file to boot by. + loopback_cfg_list = iso.get_file_list( + config.image_path, + lambda x: os.path.basename(x).lower()=='loopback.cfg') + grub_cfg_list = iso.get_file_list( + config.image_path, + lambda x: os.path.basename(x).lower().startswith('grub') and + os.path.basename(x).lower().endswith('.cfg')) + candidates = [] + for src_list, predicate in [ + # List in the order of decreasing preference. + (loopback_cfg_list, lambda x: 'efi' in x.lower()), + (loopback_cfg_list, lambda x: 'boot' in x.lower()), + (grub_cfg_list, lambda x: 'efi' in x.lower()), + (grub_cfg_list, lambda x: 'boot' in x.lower()), + (loopback_cfg_list, + lambda x: 'efi' not in x.lower() and 'boot' not in x.lower()), + (grub_cfg_list, + lambda x: 'efi' not in x.lower() and 'boot' not in x.lower())]: + sub_candidates = [x for x in src_list if predicate(x)] + if len(sub_candidates): + candidates.append(sub_candidates[0]) + # We could 'break' here but will let the iteration continue + # in order to lower the chance of keeping latent bugs. + + if 0