summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2018-02-01 11:51:51 -0400
committerJoey Hess2018-02-01 11:51:51 -0400
commit2ac8353c96326f911768c985f638dabe36991e32 (patch)
tree3a18f0fb99cfdcf20c6fb08ab487b3a3746a2cf1
parentee8191a8463f2af66a858b6ea2c2a65f65fa92b6 (diff)
Grub: Added properties to configure /etc/default/grub.
This commit was sponsored by Ewen McNeill on Patreon.
-rw-r--r--debian/changelog1
-rw-r--r--joeyconfig.hs2
-rw-r--r--src/Propellor/Property/Grub.hs65
3 files changed, 68 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog
index acfbc895..7dc8c42a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -10,6 +10,7 @@ propellor (5.3.0) UNRELEASED; urgency=medium
* Added BiosGrubFlag to PartFlag.
* Run su with --login, to avoid inheriting some problematic environment
variables, such as TMP, from the caller.
+ * Grub: Added properties to configure /etc/default/grub.
-- Joey Hess <id@joeyh.name> Tue, 02 Jan 2018 13:06:45 -0400
diff --git a/joeyconfig.hs b/joeyconfig.hs
index 3615181c..258df4b1 100644
--- a/joeyconfig.hs
+++ b/joeyconfig.hs
@@ -89,6 +89,8 @@ 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"
& JoeySites.dkimMilter
& JoeySites.postfixSaslPasswordClient
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.
--