From 5b336fc3c5cbd5a20bddc880e91d8ff845fb1535 Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 19 Aug 2014 14:57:22 +0200 Subject: [PATCH 1/3] New grubcfg module, ported from Thus. --- .gitignore | 3 ++ settings.conf | 1 + src/modules/grubcfg/grubcfg.conf | 3 ++ src/modules/grubcfg/main.py | 66 ++++++++++++++++++++++++++++++++ src/modules/grubcfg/module.desc | 5 +++ 5 files changed, 78 insertions(+) create mode 100644 src/modules/grubcfg/grubcfg.conf create mode 100644 src/modules/grubcfg/main.py create mode 100644 src/modules/grubcfg/module.desc diff --git a/.gitignore b/.gitignore index 9ffd88abb..58c1b59bb 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ CMakeLists.txt.user # PyCharm .idea + +# Backup files +*~ diff --git a/settings.conf b/settings.conf index 7640314d6..4cee7960b 100644 --- a/settings.conf +++ b/settings.conf @@ -40,6 +40,7 @@ install: - networkcfg - hwclock - services +- grubcfg - grub - umount diff --git a/src/modules/grubcfg/grubcfg.conf b/src/modules/grubcfg/grubcfg.conf new file mode 100644 index 000000000..bdbe2dbcd --- /dev/null +++ b/src/modules/grubcfg/grubcfg.conf @@ -0,0 +1,3 @@ +--- +# Replace 'LinuxDistribution' with your distribution name - for example with 'Manjaro' +distributor: LinuxDistribution diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py new file mode 100644 index 000000000..74e50a7cd --- /dev/null +++ b/src/modules/grubcfg/main.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# === This file is part of Calamares - === +# +# Copyright 2014, Philip Müller +# +# Calamares is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Calamares is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Calamares. If not, see . + +import libcalamares +import os + + +def modify_grub_default(partitions, root_mount_point, distributor): + + default_dir = os.path.join(root_mount_point, "etc/default") + default_grub = os.path.join(default_dir, "grub") + plymouth_bin = os.path.join(root_mount_point, "usr/bin/plymouth") + use_splash = '' + + if os.path.exists(plymouth_bin): + use_splash = 'splash' + + for partition in partitions: + if partition["fs"] == "linuxswap": + swap_uuid = partition["uuid"] + + if swap_uuid != "": + kernel_cmd = 'GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=%s quiet %s"' % (swap_uuid, use_splash) + else: + kernel_cmd = 'GRUB_CMDLINE_LINUX_DEFAULT="quiet %s"' % use_splash + + 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()] + + for i in range(len(lines)): + if lines[i].startswith("#GRUB_CMDLINE_LINUX_DEFAULT"): + lines[i] = kernel_cmd + elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"): + lines[i] = kernel_cmd + elif lines[i].startswith("#GRUB_DISTRIBUTOR") or lines[i].startswith("GRUB_DISTRIBUTOR"): + lines[i] = "GRUB_DISTRIBUTOR=%s" % distributor + + with open(default_grub, 'w') as grub_file: + grub_file.write("\n".join(lines) + "\n") + + +def run(): + partitions = libcalamares.globalstorage.value("partitions") + root_mount_point = libcalamares.globalstorage.value("rootMountPoint") + distributor = libcalamares.job.configuration["distributor"] + modify_grub_default(partitions, root_mount_point, distributor) + return None diff --git a/src/modules/grubcfg/module.desc b/src/modules/grubcfg/module.desc new file mode 100644 index 000000000..34f1a5a1e --- /dev/null +++ b/src/modules/grubcfg/module.desc @@ -0,0 +1,5 @@ +--- +type: "job" +name: "grubcfg" +interface: "python" +script: "main.py" From 0c4e8863cf883ca2685ac92d691299ff12c6f9ea Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 19 Aug 2014 15:28:12 +0200 Subject: [PATCH 2/3] grubcfg: set swap_uuid variable --- src/modules/grubcfg/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 74e50a7cd..7d3280122 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -31,6 +31,7 @@ def modify_grub_default(partitions, root_mount_point, distributor): if os.path.exists(plymouth_bin): use_splash = 'splash' + swap_uuid = "" for partition in partitions: if partition["fs"] == "linuxswap": swap_uuid = partition["uuid"] From 82237d1bd1a1931b672bd42f1f10a3ccffb5acda Mon Sep 17 00:00:00 2001 From: Philip Date: Tue, 19 Aug 2014 15:46:36 +0200 Subject: [PATCH 3/3] grubcfg: group variables --- src/modules/grubcfg/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 7d3280122..734b94b75 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -26,12 +26,12 @@ def modify_grub_default(partitions, root_mount_point, distributor): default_dir = os.path.join(root_mount_point, "etc/default") default_grub = os.path.join(default_dir, "grub") plymouth_bin = os.path.join(root_mount_point, "usr/bin/plymouth") - use_splash = '' + use_splash = "" + swap_uuid = "" if os.path.exists(plymouth_bin): - use_splash = 'splash' + use_splash = "splash" - swap_uuid = "" for partition in partitions: if partition["fs"] == "linuxswap": swap_uuid = partition["uuid"]