diff options
| author | Joey Hess <joeyh@joeyh.name> | 2018-02-01 11:51:51 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2018-02-01 11:51:51 -0400 |
| commit | 2ac8353c96326f911768c985f638dabe36991e32 (patch) | |
| tree | 3a18f0fb99cfdcf20c6fb08ab487b3a3746a2cf1 /src/Propellor | |
| parent | ee8191a8463f2af66a858b6ea2c2a65f65fa92b6 (diff) | |
Grub: Added properties to configure /etc/default/grub.
This commit was sponsored by Ewen McNeill on Patreon.
Diffstat (limited to 'src/Propellor')
| -rw-r--r-- | src/Propellor/Property/Grub.hs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/Propellor/Property/Grub.hs b/src/Propellor/Property/Grub.hs index 5cb9077d..573a30f3 100644 --- a/src/Propellor/Property/Grub.hs +++ b/src/Propellor/Property/Grub.hs @@ -5,6 +5,8 @@ module Propellor.Property.Grub ( installed, mkConfig, installed', + configured, + cmdline_Linux, boots, bootsMounted, TimeoutSecs, @@ -13,11 +15,15 @@ module Propellor.Property.Grub ( import Propellor.Base import qualified Propellor.Property.File as File +import qualified Propellor.Property.ConfFile as ConfFile import qualified Propellor.Property.Apt as Apt import Propellor.Property.Mount import Propellor.Property.Chroot (inChroot) import Propellor.Types.Info import Propellor.Types.Bootloader +import Utility.SafeCommand + +import Data.List -- | Eg, \"hd0,0\" or \"xen/xvda1\" type GrubDevice = String @@ -53,6 +59,65 @@ installed' grubtarget = setInfoProperty aptinstall Coreboot -> "grub-coreboot" Xen -> "grub-xen" +-- | Sets a simple confguration value, using grub-mkconfig to update +-- the grub boot menu accordingly. On Debian, these are written to +-- </etc/default/grub> +-- +-- Example: +-- +-- > & Grub.configured "GRUB_TIMEOUT" "10" +-- > & Grub.configured "GRUB_TERMINAL_INPUT" "console serial" +configured :: String -> String -> Property DebianLike +configured k v = ConfFile.adjustSection + ("grub configured with " ++ k ++ "=" ++ v) + isline + (not . isline) + (const [l]) + (const [l]) + simpleConfigFile + `onChange` mkConfig + where + isline s = (k ++ "=") `isPrefixOf` s + l = k ++ "=" ++ shellEscape v + +simpleConfigFile :: FilePath +simpleConfigFile = "/etc/default/grub" + +-- | Adds a word to the linux command line. Any other words in the command +-- line will be left unchanged. +-- +-- Example: +-- +-- > & Grub.cmdline_Linux "i915.enable_psr=1" +-- > ! Grub.cmdline_Linux "quiet" +cmdline_Linux :: String -> RevertableProperty DebianLike DebianLike +cmdline_Linux w = setup <!> undo + where + setup = ConfFile.adjustSection + ("linux command line includes " ++ w) + isline + (not . isline) + (map (mkline . addw . getws)) + (++ [mkline [w]]) + simpleConfigFile + `onChange` mkConfig + undo = ConfFile.adjustSection + ("linux command line does not include " ++ w) + isline + (not . isline) + (map (mkline . rmw . getws)) + (++ [mkline [""]]) + simpleConfigFile + `onChange` mkConfig + k = "GRUB_CMDLINE_LINUX" + isline s = (k ++ "=") `isPrefixOf` s + mkline ws = k ++ "=" ++ shellEscape (unwords ws) + getws = concatMap words . shellUnEscape . drop 1 . dropWhile (/= '=') + addw ws + | w `elem` ws = ws + | otherwise = ws ++ [w] + rmw = filter (/= w) + -- | Installs grub onto a device's boot loader, -- so the system can boot from that device. -- |
