From 826de8e624c9119f2908dbd17d876c6ed5632425 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 3 Aug 2015 21:23:24 -0700 Subject: LightDM.autoLogin property Signed-off-by: Sean Whitton (cherry picked from commit ef71b6dc6356bf5cb66bbb367bb3525df8742a53) --- src/Propellor/Property/LightDM.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/Propellor/Property/LightDM.hs diff --git a/src/Propellor/Property/LightDM.hs b/src/Propellor/Property/LightDM.hs new file mode 100644 index 00000000..b3756f6e --- /dev/null +++ b/src/Propellor/Property/LightDM.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE FlexibleInstances #-} + +module Propellor.Property.LightDM where + +import Propellor +import qualified Propellor.Property.File as File + +-- | Configures LightDM to skip the login screen and autologin as a user. +autoLogin :: User -> Property NoInfo +autoLogin (User u) = "/etc/lightdm/lightdm.conf" `File.containsConfPair` + ("SeatDefaults", "autologin-user", u) + `describe` "lightdm autologin" -- cgit v1.2.3 From f8dc9b294dbc114255129113f84fabde6dac46cc Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 16 Aug 2015 17:47:21 -0700 Subject: ConfFile.containsIniPair property plus scaffolding for other generic conf file properties (cherry picked from commit 86b077b7a21efd5484dfaeee3c31fc5f3c151f6c) --- propellor.cabal | 3 +- src/Propellor/Property/ConfFile.hs | 72 ++++++++++++++++++++++++++++++++++++++ src/Propellor/Property/LightDM.hs | 4 +-- 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/Propellor/Property/ConfFile.hs diff --git a/propellor.cabal b/propellor.cabal index f00e5594..640d0293 100644 --- a/propellor.cabal +++ b/propellor.cabal @@ -73,7 +73,8 @@ Library Propellor.Property.Apt Propellor.Property.Cmd Propellor.Property.Hostname - Propellor.Property.Chroot + Propellor.Property.Chroot + Propellor.Property.ConfFile Propellor.Property.Cron Propellor.Property.Debootstrap Propellor.Property.Dns diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs new file mode 100644 index 00000000..72996c74 --- /dev/null +++ b/src/Propellor/Property/ConfFile.hs @@ -0,0 +1,72 @@ +module Propellor.Property.ConfFile (containsIniPair) where + +import Propellor +import Propellor.Property.File + +import Data.List (isPrefixOf, foldl') + +type SectionStart = Line -> Bool -- ^ find the line that is the start of the + -- wanted section (eg, == "") +type SectionPast = Line -> Bool -- ^ find a line that indicates we are past + -- the section (eg, a new section header) +type AdjustSection = [Line] -> [Line] -- ^ run on all lines in the section, + -- including the SectionStart line and any + -- SectionEnd line; can add/delete/modify + -- lines, or even delete entire section +type InsertSection = [Line] -> [Line] -- ^ if SectionStart does not find the + -- section in the file, this is used to + -- insert the section somewhere within it + +adjustSection + :: String + -> SectionStart + -> SectionPast + -> AdjustSection + -> InsertSection + -> FilePath + -> Property NoInfo +adjustSection desc start past adjust insert f = + fileProperty desc go f + where + go ls = let (pre, wanted, post) = foldl' find ([], [], []) ls + in if null wanted + then insert ls + else pre ++ (adjust wanted) ++ post + find (pre, wanted, post) l + | null wanted && null post && (not . start) l = + (pre ++ [l], wanted, post) + | (start l && null wanted && null post) + || ((not . null) wanted && null post && (not . past) l) = + (pre, wanted ++ [l], post) + | otherwise = (pre, wanted, post ++ [l]) + +iniHeader :: String -> String +iniHeader header = '[' : header ++ "]" + +adjustIniSection + :: String + -> String + -> AdjustSection + -> InsertSection + -> FilePath + -> Property NoInfo +adjustIniSection desc header = + adjustSection + desc + (== iniHeader header) + ("[" `isPrefixOf`) + +containsIniPair :: FilePath -> (String, String, String) -> Property NoInfo +containsIniPair f (header, key, value) = + adjustIniSection + (f ++ " section [" ++ header ++ "] contains " ++ key ++ "=" ++ value) + header + go + (++ [confheader, confline]) + f + where + confheader = iniHeader header + confline = key ++ "=" ++ value + go [] = [confline] + go (l:ls) = if isKeyVal l then confline : ls else l : (go ls) + isKeyVal x = (filter (/= ' ') . takeWhile (/= '=')) x `elem` [key, '#':key] diff --git a/src/Propellor/Property/LightDM.hs b/src/Propellor/Property/LightDM.hs index b3756f6e..09f7165d 100644 --- a/src/Propellor/Property/LightDM.hs +++ b/src/Propellor/Property/LightDM.hs @@ -3,10 +3,10 @@ module Propellor.Property.LightDM where import Propellor -import qualified Propellor.Property.File as File +import qualified Propellor.Property.ConfFile as ConfFile -- | Configures LightDM to skip the login screen and autologin as a user. autoLogin :: User -> Property NoInfo -autoLogin (User u) = "/etc/lightdm/lightdm.conf" `File.containsConfPair` +autoLogin (User u) = "/etc/lightdm/lightdm.conf" `ConfFile.containsIniPair` ("SeatDefaults", "autologin-user", u) `describe` "lightdm autologin" -- cgit v1.2.3 From 47059b7358a94e06dadc44b76b5b81d560dadd80 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 20 Aug 2015 10:13:18 -0400 Subject: layout --- propellor.cabal | 2 +- src/Propellor/Property/ConfFile.hs | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/propellor.cabal b/propellor.cabal index 640d0293..317f30d8 100644 --- a/propellor.cabal +++ b/propellor.cabal @@ -73,7 +73,7 @@ Library Propellor.Property.Apt Propellor.Property.Cmd Propellor.Property.Hostname - Propellor.Property.Chroot + Propellor.Property.Chroot Propellor.Property.ConfFile Propellor.Property.Cron Propellor.Property.Debootstrap diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index 72996c74..b2d96d29 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -5,17 +5,17 @@ import Propellor.Property.File import Data.List (isPrefixOf, foldl') -type SectionStart = Line -> Bool -- ^ find the line that is the start of the - -- wanted section (eg, == "") -type SectionPast = Line -> Bool -- ^ find a line that indicates we are past - -- the section (eg, a new section header) -type AdjustSection = [Line] -> [Line] -- ^ run on all lines in the section, - -- including the SectionStart line and any - -- SectionEnd line; can add/delete/modify - -- lines, or even delete entire section -type InsertSection = [Line] -> [Line] -- ^ if SectionStart does not find the - -- section in the file, this is used to - -- insert the section somewhere within it +-- | find the line that is the start of the wanted section (eg, == "") +type SectionStart = Line -> Bool +-- | find a line that indicates we are past the section +-- (eg, a new section header) +type SectionPast = Line -> Bool +-- | run on all lines in the section, including the SectionStart line; +-- can add/delete/modify lines, or even delete entire section +type AdjustSection = [Line] -> [Line] +-- | if SectionStart does not find the section in the file, this is used to +-- insert the section somewhere within it +type InsertSection = [Line] -> [Line] adjustSection :: String @@ -29,9 +29,9 @@ adjustSection desc start past adjust insert f = fileProperty desc go f where go ls = let (pre, wanted, post) = foldl' find ([], [], []) ls - in if null wanted - then insert ls - else pre ++ (adjust wanted) ++ post + in if null wanted + then insert ls + else pre ++ (adjust wanted) ++ post find (pre, wanted, post) l | null wanted && null post && (not . start) l = (pre ++ [l], wanted, post) -- cgit v1.2.3 -- cgit v1.2.3 From 0a08f4a1541b3711861a67ff660d60d3f5d668e3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 20 Aug 2015 10:14:18 -0400 Subject: include lightdm module (and formatting) --- propellor.cabal | 1 + src/Propellor/Property/LightDM.hs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/propellor.cabal b/propellor.cabal index 317f30d8..ad02c6b3 100644 --- a/propellor.cabal +++ b/propellor.cabal @@ -97,6 +97,7 @@ Library Propellor.Property.Prosody Propellor.Property.Reboot Propellor.Property.List + Propellor.Property.LightDM Propellor.Property.Scheduled Propellor.Property.Service Propellor.Property.Ssh diff --git a/src/Propellor/Property/LightDM.hs b/src/Propellor/Property/LightDM.hs index 09f7165d..156a2a82 100644 --- a/src/Propellor/Property/LightDM.hs +++ b/src/Propellor/Property/LightDM.hs @@ -8,5 +8,5 @@ import qualified Propellor.Property.ConfFile as ConfFile -- | Configures LightDM to skip the login screen and autologin as a user. autoLogin :: User -> Property NoInfo autoLogin (User u) = "/etc/lightdm/lightdm.conf" `ConfFile.containsIniPair` - ("SeatDefaults", "autologin-user", u) - `describe` "lightdm autologin" + ("SeatDefaults", "autologin-user", u) + `describe` "lightdm autologin" -- cgit v1.2.3 From 6aba3026c44b9c9cf63468927aa57c197f6444fa Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 20 Aug 2015 10:29:08 -0400 Subject: propellor spin --- src/Propellor/Property/ConfFile.hs | 33 ++++++++++++++++++++++++++------- src/Propellor/Property/LightDM.hs | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index b2d96d29..df723eea 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -1,4 +1,13 @@ -module Propellor.Property.ConfFile (containsIniPair) where +module Propellor.Property.ConfFile ( + SectionStart, + SectionPast, + AdjustSection, + InsertSection, + adjustSection, + IniSection, + IniKey, + containsIniSetting, +) where import Propellor import Propellor.Property.File @@ -17,8 +26,9 @@ type AdjustSection = [Line] -> [Line] -- insert the section somewhere within it type InsertSection = [Line] -> [Line] +-- | Adjusts a section of conffile. adjustSection - :: String + :: Desc -> SectionStart -> SectionPast -> AdjustSection @@ -40,12 +50,19 @@ adjustSection desc start past adjust insert f = (pre, wanted ++ [l], post) | otherwise = (pre, wanted, post ++ [l]) -iniHeader :: String -> String +-- | Name of a section of a Windows-style .ini file. This value is put +-- in square braces to generate the section header. +type IniSection = String + +-- | Name of a configuration setting within a Windows-style .init file. +type IniKey = String + +iniHeader :: IniSection -> String iniHeader header = '[' : header ++ "]" adjustIniSection - :: String - -> String + :: Desc + -> IniSection -> AdjustSection -> InsertSection -> FilePath @@ -56,8 +73,10 @@ adjustIniSection desc header = (== iniHeader header) ("[" `isPrefixOf`) -containsIniPair :: FilePath -> (String, String, String) -> Property NoInfo -containsIniPair f (header, key, value) = +-- | Ensures that a Windows-style .ini file exists and contains a section +-- with a key=value setting. +containsIniSetting :: FilePath -> (IniSection, IniKey, String) -> Property NoInfo +containsIniSetting f (header, key, value) = adjustIniSection (f ++ " section [" ++ header ++ "] contains " ++ key ++ "=" ++ value) header diff --git a/src/Propellor/Property/LightDM.hs b/src/Propellor/Property/LightDM.hs index 156a2a82..b779ba4d 100644 --- a/src/Propellor/Property/LightDM.hs +++ b/src/Propellor/Property/LightDM.hs @@ -7,6 +7,6 @@ import qualified Propellor.Property.ConfFile as ConfFile -- | Configures LightDM to skip the login screen and autologin as a user. autoLogin :: User -> Property NoInfo -autoLogin (User u) = "/etc/lightdm/lightdm.conf" `ConfFile.containsIniPair` +autoLogin (User u) = "/etc/lightdm/lightdm.conf" `ConfFile.containsIniSetting` ("SeatDefaults", "autologin-user", u) `describe` "lightdm autologin" -- cgit v1.2.3 From 544a3111dd805fdcaddabe06a7d5c841e15faac5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 20 Aug 2015 10:30:20 -0400 Subject: headers --- src/Propellor/Property/ConfFile.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Propellor/Property/ConfFile.hs b/src/Propellor/Property/ConfFile.hs index df723eea..1a2503dd 100644 --- a/src/Propellor/Property/ConfFile.hs +++ b/src/Propellor/Property/ConfFile.hs @@ -1,9 +1,11 @@ module Propellor.Property.ConfFile ( + -- * Generic conffiles with sections SectionStart, SectionPast, AdjustSection, InsertSection, adjustSection, + -- * Windows .ini files IniSection, IniKey, containsIniSetting, -- cgit v1.2.3