From 2ac8353c96326f911768c985f638dabe36991e32 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Feb 2018 11:51:51 -0400 Subject: Grub: Added properties to configure /etc/default/grub. This commit was sponsored by Ewen McNeill on Patreon. --- src/Propellor/Property/Grub.hs | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'src/Propellor/Property/Grub.hs') 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 +-- +-- +-- 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. -- -- cgit v1.3-2-g0d8e From 121c20726cebf3657b0b5d22d220cbdc7aa1aac4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Feb 2018 11:57:06 -0400 Subject: add only to default linux command line Don't affect rescue mode. --- joeyconfig.hs | 5 +++-- src/Propellor/Property/Grub.hs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/Propellor/Property/Grub.hs') diff --git a/joeyconfig.hs b/joeyconfig.hs index 258df4b1..3d895e69 100644 --- a/joeyconfig.hs +++ b/joeyconfig.hs @@ -89,8 +89,9 @@ darkstar = host "darkstar.kitenet.net" $ props & ipv6 "2001:4830:1600:187::2" & Hostname.sane & Apt.serviceInstalledRunning "swapspace" - & Grub.cmdline_Linux "i915.enable_psr=1" - ! Grub.cmdline_Linux "quiet" + ! Grub.cmdline_Linux_default "quiet" + -- Power consumption tuning + & Grub.cmdline_Linux_default "i915.enable_psr=1" & JoeySites.dkimMilter & JoeySites.postfixSaslPasswordClient diff --git a/src/Propellor/Property/Grub.hs b/src/Propellor/Property/Grub.hs index 573a30f3..79ecd8c9 100644 --- a/src/Propellor/Property/Grub.hs +++ b/src/Propellor/Property/Grub.hs @@ -6,7 +6,7 @@ module Propellor.Property.Grub ( mkConfig, installed', configured, - cmdline_Linux, + cmdline_Linux_default, boots, bootsMounted, TimeoutSecs, @@ -83,15 +83,15 @@ configured k v = ConfFile.adjustSection 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. +-- | Adds a word to the default 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 +-- > & Grub.cmdline_Linux_default "i915.enable_psr=1" +-- > ! Grub.cmdline_Linux_default "quiet" +cmdline_Linux_default :: String -> RevertableProperty DebianLike DebianLike +cmdline_Linux_default w = setup undo where setup = ConfFile.adjustSection ("linux command line includes " ++ w) @@ -109,7 +109,7 @@ cmdline_Linux w = setup undo (++ [mkline [""]]) simpleConfigFile `onChange` mkConfig - k = "GRUB_CMDLINE_LINUX" + k = "GRUB_CMDLINE_LINUX_DEFAULT" isline s = (k ++ "=") `isPrefixOf` s mkline ws = k ++ "=" ++ shellEscape (unwords ws) getws = concatMap words . shellUnEscape . drop 1 . dropWhile (/= '=') -- cgit v1.3-2-g0d8e