grubcfg: Create /etc/default/grub if missing.

Also adds a grubcfg.conf with the following settings:

* overwrite: If set to true, always creates /etc/default/grub from
  scratch even if the file already existed. If set to false, edits the
  existing file instead. The default is "false".

* defaults: Default entries to write to /etc/default/grub if it does not
  exist yet or if we are overwriting it. Note that in addition,
  GRUB_CMDLINE_LINUX_DEFAULT and GRUB_DISTRIBUTOR will always be
  written, with automatically detected values. The default in the code
  is empty. The shipped grubcfg.conf currently reproduces the default
  settings from the Fedora installer Anaconda.

Fixes #128.
This commit is contained in:
Kevin Kofler 2014-11-18 04:32:55 +01:00
parent d5b95d79e5
commit 1499963920
2 changed files with 44 additions and 13 deletions

View File

@ -0,0 +1,13 @@
---
# If set to true, always creates /etc/default/grub from scratch even if the file
# already existed. If set to false, edits the existing file instead.
overwrite: false
# Default entries to write to /etc/default/grub if it does not exist yet or if
# we are overwriting it. Note that in addition, GRUB_CMDLINE_LINUX_DEFAULT and
# GRUB_DISTRIBUTOR will always be written, with automatically detected values.
defaults:
GRUB_TIMEOUT: 5
GRUB_DEFAULT: "saved"
GRUB_DISABLE_SUBMENU: true
GRUB_TERMINAL_OUTPUT: "console"
GRUB_DISABLE_RECOVERY: true

View File

@ -46,22 +46,40 @@ def modify_grub_default(partitions, root_mount_point, distributor):
if not os.path.exists(default_dir):
os.mkdir(default_dir)
with open(default_grub, 'r') as grub_file:
lines = [x.strip() for x in grub_file.readlines()]
have_kernel_cmd = False
have_distributor_line = False
for i in range(len(lines)):
if lines[i].startswith("#GRUB_CMDLINE_LINUX_DEFAULT"):
lines[i] = kernel_cmd
have_kernel_cmd = True
elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"):
lines[i] = kernel_cmd
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 "overwrite" in libcalamares.job.configuration:
overwrite = libcalamares.job.configuration["overwrite"]
else:
overwrite = False
if os.path.exists(default_grub) and not overwrite:
with open(default_grub, 'r') as grub_file:
lines = [x.strip() for x in grub_file.readlines()]
for i in range(len(lines)):
if lines[i].startswith("#GRUB_CMDLINE_LINUX_DEFAULT"):
lines[i] = kernel_cmd
have_kernel_cmd = True
elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"):
lines[i] = kernel_cmd
have_kernel_cmd = True
elif lines[i].startswith("#GRUB_DISTRIBUTOR") or lines[i].startswith("GRUB_DISTRIBUTOR"):
lines[i] = distributor_line
have_distributor_line = True
else:
lines = []
if "defaults" in libcalamares.job.configuration:
for key, value in libcalamares.job.configuration["defaults"].items():
if value.__class__.__name__ == "bool":
if value:
escaped_value = "true"
else:
escaped_value = "false"
else:
escaped_value = str(value).replace("'", "'\\''")
lines.append("%s='%s'" % (key, escaped_value))
if not have_kernel_cmd:
lines.append(kernel_cmd)