diff --git a/src/modules/grubcfg/grubcfg.conf b/src/modules/grubcfg/grubcfg.conf index b354ec35a..ba31d6070 100644 --- a/src/modules/grubcfg/grubcfg.conf +++ b/src/modules/grubcfg/grubcfg.conf @@ -1,9 +1,12 @@ +# Create, overwrite or update /etc/default/grub in the target system. +# # Write lines to /etc/default/grub (in the target system) based # on calculated values and the values set in the *defaults* key # in this configuration file. # # Calculated values are: -# - GRUB_DISTRIBUTOR, branding module, *bootloaderEntryName* +# - GRUB_DISTRIBUTOR, branding module, *bootloaderEntryName* (this +# string is sanitized, and see also setting *keepDistributor*) # - GRUB_ENABLE_CRYPTODISK, based on the presence of filesystems # that use LUKS # - GRUB_CMDLINE_LINUX_DEFAULT, adding LUKS setup and plymouth @@ -14,6 +17,12 @@ # already existed. If set to false, edits the existing file instead. overwrite: false +# If set to true, an **existing** setting for GRUB_DISTRIBUTOR is +# kept, not updated to the *bootloaderEntryName* from the branding file. +# Use this if the GRUB_DISTRIBUTOR setting in the file is "smart" in +# some way (e.g. uses shell-command substitution). +keepDistributor: false + # Default entries to write to /etc/default/grub if it does not exist yet or if # we are overwriting it. # diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 83441a736..1f2574965 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -45,7 +45,13 @@ def modify_grub_default(partitions, root_mount_point, distributor): :param partitions: :param root_mount_point: - :param distributor: + :param distributor: name of the distributor to fill in for + 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") @@ -172,8 +178,13 @@ 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")): - lines[i] = distributor_line - have_distributor_line = True + if libcalamares.job.configuration.get("keepDistributor", false): + lines[i] = distributor_line + have_distributor_line = True + else: + # We're not updating because of *keepDistributor*, but if + # this was a comment line, then it's still not been set. + have_distributor_line = have_distributor_line or not lines[i].startsdwith("#") else: lines = [] diff --git a/src/modules/grubcfg/tests/1.global b/src/modules/grubcfg/tests/1.global new file mode 100644 index 000000000..02ae840cb --- /dev/null +++ b/src/modules/grubcfg/tests/1.global @@ -0,0 +1,2 @@ +--- +bogus: true diff --git a/src/modules/grubcfg/tests/2.global b/src/modules/grubcfg/tests/2.global new file mode 100644 index 000000000..83e79db28 --- /dev/null +++ b/src/modules/grubcfg/tests/2.global @@ -0,0 +1,10 @@ +--- +bogus: true +firmwareType: bios +bootLoader: grub +rootMountPoint: /tmp/calamares + +branding: + bootloaderEntryName: generic +partitions: [] + diff --git a/src/modules/grubcfg/tests/2.job b/src/modules/grubcfg/tests/2.job new file mode 100644 index 000000000..d7b8db9d1 --- /dev/null +++ b/src/modules/grubcfg/tests/2.job @@ -0,0 +1,9 @@ +--- +overwrite: true +keepDistributor: false +defaults: + GRUB_TIMEOUT: 5 + GRUB_DEFAULT: "saved" + GRUB_DISABLE_SUBMENU: true + GRUB_TERMINAL_OUTPUT: "console" + GRUB_DISABLE_RECOVERY: true