From d775acad02bbdd1ab127e738ecfdddefc3f189db Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@lysator.liu.se> Date: Mon, 30 Apr 2018 22:12:27 +0200 Subject: [PATCH] Definition for managing Grub 0.x options. This adds the defintion bootloader::grub0::option, which can set and unset options in the Grub 0.x config file. It handles both "bare" options (e.g. 'hiddenmenu') and valued options (e.g. timeout=5). Managing Grub 2 options seems a bit more complicated, so for now we only implement the Grub 0.x version. --- manifests/grub0/option.pp | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 manifests/grub0/option.pp diff --git a/manifests/grub0/option.pp b/manifests/grub0/option.pp new file mode 100644 index 0000000..964406c --- /dev/null +++ b/manifests/grub0/option.pp @@ -0,0 +1,60 @@ +# Copyright © 2018 Thomas Bellman, Linköping, Sweden +# Licensed under the GNU LGPL v3+; see the README file for more information. + + +/* + * Set or remove an option for Grub 0.x. + * + * Parameters + * - name Grub0 option to set or remove + * + * - ensure One of 'present' (the default) or 'absent'. + * + * - value What value to set for the option. If set to true, it will + * be a value-less option, e.g. 'hiddenmenu'. + */ +define bootloader::grub0::option($ensure='present', $value=undef) +{ + $qname = regexp_quote($name) + + # The Agueas Grub lens puts new options at the end of the file, after + # all boot alternatives ('title' options). People probably don't + # expect that, and will be confused when trying to find such options. + # By using ensure_line, we can put them in a reasonable position. + + if ($ensure == 'absent') + { + delete_lines { + "bootloader::grub0::option::${name}": + file => '/boot/grub/grub.conf', + pattern => "${qname}(=.*)?"; + } + } + elsif ($ensure != 'present') + { + fail("Bootloader::Option[${title}]: ", + "Bad ensure parameter, ${ensure}") + } + elsif ($value == true) + { + ensure_line { + "bootloader::grub0::option::${name}": + file => '/boot/grub/grub.conf', + line => $name, + pattern => "${qname}(\s*=.*)", + addhow => 'prepend', + where => '((title\s*.*$)|)$'; + } + } + else + { + ensure_line { + "bootloader::grub0::option::${name}": + file => '/boot/grub/grub.conf', + line => "${name}=${value}", + pattern => "${qname}(\s*=.*)", + addhow => 'prepend', + where => '((title\s*.*$)|)$'; + } + } +} -- GitLab