From c6c861654dfe4ae73e96ae64e7545c274234a38b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Nov 2019 16:06:59 +0100 Subject: [PATCH] [grubcfg] Update GRUB_DISTRIBUTION as needed - Previous fix would erase the distribution information (using an empty string to flag 'preserve existing GRUB_DISTRIBUTION lines'), but that is fragile. A distro might set that, and yet **not** set a GRUB_DISTRIBUTION line, in which case it would end up with a setup without any GRUB_DISTRIBUTION set. - When a GRUB_DISTRIBUTION line is found, **then** check if it should update the line or not. This way, we have a suitable distribution to write if no GRUB_DISTRIBUTION is found at all. --- src/modules/grubcfg/main.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index d09f15fed..866cd4815 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -46,9 +46,12 @@ def modify_grub_default(partitions, root_mount_point, distributor): :param partitions: :param root_mount_point: :param distributor: name of the distributor to fill in for - GRUB_DISTRIBUTOR. Must be a string, but if it is empty ("") - then the existing GRUB_DISTRIBUTOR lines are kept instead - of replaced by a new line. + GRUB_DISTRIBUTOR. Must be a string. If the job setting + *keepDistributor* is set, then this is only used if no + GRUB_DISTRIBUTOR is found at all (otherwise, when *keepDistributor* + is set, the GRUB_DISTRIBUTOR lines are left unchanged). + If *keepDistributor* is unset or false, then GRUB_DISTRIBUTOR + is always updated to set this value. :return: """ default_dir = os.path.join(root_mount_point, "etc/default") @@ -175,7 +178,7 @@ def modify_grub_default(partitions, root_mount_point, distributor): have_kernel_cmd = True elif (lines[i].startswith("#GRUB_DISTRIBUTOR") or lines[i].startswith("GRUB_DISTRIBUTOR")): - if distributor: + if libcalamares.job.configuration.get("keepDistributor", false): lines[i] = distributor_line have_distributor_line = True else: @@ -240,10 +243,6 @@ def run(): root_mount_point = libcalamares.globalstorage.value("rootMountPoint") branding = libcalamares.globalstorage.value("branding") - - if libcalamares.job.configuration.get("keepDistributor", false): - distributor = "" - else: - distributor = branding["bootloaderEntryName"] + distributor = branding["bootloaderEntryName"] return modify_grub_default(partitions, root_mount_point, distributor)