From b3c795dc4784e64e2756d3736ce953a1e507f509 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Jan 2018 15:13:35 -0400 Subject: Run su with --login To avoid inheriting some problematic environment variables, such as TMP, from the caller. The only potential breakage from this change would be if something used setEnv before one of the affected properties. Audited propellor's source for that, and nothing does. Anything that did would could fail in a concurrent context anyway. --- debian/changelog | 2 ++ 1 file changed, 2 insertions(+) (limited to 'debian/changelog') diff --git a/debian/changelog b/debian/changelog index 4545bcd1..acfbc895 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,8 @@ propellor (5.3.0) UNRELEASED; urgency=medium * Added rawPartition to PartSpec, for specifying partitions with no filesystem. * Added BiosGrubFlag to PartFlag. + * Run su with --login, to avoid inheriting some problematic environment + variables, such as TMP, from the caller. -- Joey Hess Tue, 02 Jan 2018 13:06:45 -0400 -- cgit v1.2.3 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. --- debian/changelog | 1 + joeyconfig.hs | 2 ++ src/Propellor/Property/Grub.hs | 65 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) (limited to 'debian/changelog') 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 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 +-- +-- +-- 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.2.3 From 141cf24148a1258a94f95ba1a6b2265070675d30 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Feb 2018 12:19:09 -0400 Subject: Laptop: New module, starting with powertopAutoTuneOnBoot. This commit was sponsored by Brock Spratlen on Patreon. --- debian/changelog | 1 + joeyconfig.hs | 5 +++-- propellor.cabal | 1 + src/Propellor/Property/Laptop.hs | 28 ++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Propellor/Property/Laptop.hs (limited to 'debian/changelog') diff --git a/debian/changelog b/debian/changelog index 7dc8c42a..23172a22 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,7 @@ propellor (5.3.0) UNRELEASED; urgency=medium * 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. + * Laptop: New module, starting with powertopAutoTuneOnBoot. -- Joey Hess Tue, 02 Jan 2018 13:06:45 -0400 diff --git a/joeyconfig.hs b/joeyconfig.hs index 3d895e69..1d019498 100644 --- a/joeyconfig.hs +++ b/joeyconfig.hs @@ -33,6 +33,7 @@ import qualified Propellor.Property.Gpg as Gpg import qualified Propellor.Property.Systemd as Systemd import qualified Propellor.Property.Journald as Journald import qualified Propellor.Property.Fail2Ban as Fail2Ban +import qualified Propellor.Property.Laptop as Laptop import qualified Propellor.Property.OS as OS import qualified Propellor.Property.HostingProvider.CloudAtCost as CloudAtCost import qualified Propellor.Property.HostingProvider.Linode as Linode @@ -89,9 +90,9 @@ darkstar = host "darkstar.kitenet.net" $ props & ipv6 "2001:4830:1600:187::2" & Hostname.sane & Apt.serviceInstalledRunning "swapspace" - ! Grub.cmdline_Linux_default "quiet" - -- Power consumption tuning + & Laptop.powertopAutoTuneOnBoot & Grub.cmdline_Linux_default "i915.enable_psr=1" + ! Grub.cmdline_Linux_default "quiet" & JoeySites.dkimMilter & JoeySites.postfixSaslPasswordClient diff --git a/propellor.cabal b/propellor.cabal index a76d63f0..e59a55a4 100644 --- a/propellor.cabal +++ b/propellor.cabal @@ -127,6 +127,7 @@ Library Propellor.Property.Journald Propellor.Property.Kerberos Propellor.Property.LetsEncrypt + Propellor.Property.Laptop Propellor.Property.List Propellor.Property.LightDM Propellor.Property.Locale diff --git a/src/Propellor/Property/Laptop.hs b/src/Propellor/Property/Laptop.hs new file mode 100644 index 00000000..a36bda18 --- /dev/null +++ b/src/Propellor/Property/Laptop.hs @@ -0,0 +1,28 @@ +module Propellor.Property.Laptop where + +import Propellor.Base +import qualified Propellor.Property.File as File +import qualified Propellor.Property.Apt as Apt +import qualified Propellor.Property.Systemd as Systemd + +-- | Makes powertop auto-tune the system for optimal power consumption on +-- boot. +powertopAutoTuneOnBoot :: RevertableProperty DebianLike DebianLike +powertopAutoTuneOnBoot = setup undo + `describe` "powertop auto-tune on boot" + where + setup = Systemd.enabled "powertop" + `requires` Apt.installed ["powertop"] + `requires` File.hasContent servicefile + [ "[Unit]" + , "Description=Powertop tunings" + , "[Service]" + , "ExecStart=/usr/sbin/powertop --auto-tune" + , "RemainAfterExit=true" + , "[Install]" + , "WantedBy=multi-user.target" + ] + undo = tightenTargets $ File.notPresent servicefile + `requires` check (doesFileExist servicefile) + (Systemd.disabled "powertop") + servicefile = "/etc/systemd/system/powertop.service" -- cgit v1.2.3