From 1522d270077abad43a6d8d7fea2bd8163ed912fd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 17 Jul 2017 12:51:40 -0400 Subject: Propellor.Property.LightDM.autoLogin: Made revertable. * Propellor.Property.LightDM.autoLogin: Made revertable. (minor API change) * Propellor.Property.Conffile: Added lacksIniSetting. This commit was sponsored by Jack Hill on Patreon. --- debian/changelog | 3 +++ src/Propellor/Property/ConfFile.hs | 14 ++++++++++++++ src/Propellor/Property/LightDM.hs | 14 +++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index d70018cc..e8b0358c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,9 @@ propellor (4.4.0) UNRELEASED; urgency=medium * Propellor.Property.Timezone: New module, contributed by Sean Whitton. * Propellor.Property.Sudo.enabledFor: Made revertable. (minor API change) + * Propellor.Property.LightDM.autoLogin: Made revertable. + (minor API change) + * Propellor.Property.Conffile: Added lacksIniSetting. -- Joey Hess Sun, 16 Jul 2017 12:07:15 -0400 diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index ce092ec9..76d52bd9 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -9,6 +9,7 @@ module Propellor.Property.ConfFile ( IniSection, IniKey, containsIniSetting, + lacksIniSetting, hasIniSection, lacksIniSection, iniFileContains, @@ -93,6 +94,19 @@ containsIniSetting f (header, key, value) = adjustIniSection go (l:ls) = if isKeyVal l then confline : ls else l : go ls isKeyVal x = (filter (/= ' ') . takeWhile (/= '=')) x `elem` [key, '#':key] +-- | Removes a key=value setting from a section of an .ini file. +-- Note that the section heading is left in the file, so this is not a +-- perfect reversion of containsIniSetting. +lacksIniSetting :: FilePath -> (IniSection, IniKey, String) -> Property UnixLike +lacksIniSetting f (header, key, value) = adjustIniSection + (f ++ " section [" ++ header ++ "] lacks " ++ key ++ "=" ++ value) + header + (filter (/= confline)) + id + f + where + confline = key ++ "=" ++ value + -- | Ensures that a .ini file exists and contains a section -- with a given key=value list of settings. hasIniSection :: FilePath -> IniSection -> [(IniKey, String)] -> Property UnixLike diff --git a/src/Propellor/Property/LightDM.hs b/src/Propellor/Property/LightDM.hs index 44f0e9f0..d471d314 100644 --- a/src/Propellor/Property/LightDM.hs +++ b/src/Propellor/Property/LightDM.hs @@ -10,8 +10,12 @@ installed :: Property DebianLike installed = Apt.installed ["lightdm"] -- | Configures LightDM to skip the login screen and autologin as a user. -autoLogin :: User -> Property DebianLike -autoLogin (User u) = "/etc/lightdm/lightdm.conf" `ConfFile.containsIniSetting` - ("Seat:*", "autologin-user", u) - `describe` "lightdm autologin" - `requires` installed +autoLogin :: User -> RevertableProperty DebianLike DebianLike +autoLogin (User u) = (setup cleanup) + `describe` ("lightdm autologin for " ++ u) + where + cf = "/etc/lightdm/lightdm.conf" + setting = ("Seat:*", "autologin-user", u) + setup = cf `ConfFile.containsIniSetting` setting + `requires` installed + cleanup = tightenTargets $ cf `ConfFile.lacksIniSetting` setting -- cgit v1.2.3