From efa7e792a3873e27ac99efa9026eb01d8f69af2a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 25 Nov 2015 14:21:03 -0400 Subject: make trivial since it updates the password each time --- src/Propellor/Property/Postfix.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Propellor/Property/Postfix.hs b/src/Propellor/Property/Postfix.hs index 5e265e6f..20492dc6 100644 --- a/src/Propellor/Property/Postfix.hs +++ b/src/Propellor/Property/Postfix.hs @@ -162,7 +162,7 @@ saslAuthdInstalled = setupdaemon -- -- The password is taken from the privdata. saslPasswdSet :: Domain -> User -> Property HasInfo -saslPasswdSet domain (User user) = withPrivData src ctx $ \getpw -> +saslPasswdSet domain (User user) = withPrivData src ctx $ \getpw -> trivial $ property ("sasl password for " ++ uatd) $ getpw $ \pw -> makeChange $ withHandle StdinHandle createProcessSuccess p $ \h -> do hPutStrLn h (privDataVal pw) -- cgit v1.2.3 From 2969b3b07f2eeb3472f237c6723b75007c34481e Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 24 Nov 2015 20:15:24 -0700 Subject: properties to select and generate locales Signed-off-by: Sean Whitton (cherry picked from commit ee14ef80cf9ab761b07fbc40f549ad5c7c72f6cb) --- src/Propellor/Property/Locale.hs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Propellor/Property/Locale.hs (limited to 'src') diff --git a/src/Propellor/Property/Locale.hs b/src/Propellor/Property/Locale.hs new file mode 100644 index 00000000..7cc98ed1 --- /dev/null +++ b/src/Propellor/Property/Locale.hs @@ -0,0 +1,39 @@ +-- | Maintainer: Sean Whitton + +module Propellor.Property.Locale where + +import Propellor.Base +import Propellor.Property.File + +import Data.List (isPrefixOf) + +-- | Select a locale for a list of global locale variables. +-- +-- A locale variable is of the form `LC_BLAH`, `LANG` or `LANGUAGE`. See `man 5 +-- locale`. +selectedFor :: String -> [String] -> Property NoInfo +locale `selectedFor` vars = + trivial $ cmdProperty "update-locale" args + `requires` available locale + `describe` (locale ++ " locale selected") + where + args = zipWith (++) vars (repeat ('=':locale)) + +-- | Ensures a locale is generated. +-- +-- Assumes a locale is available to be generated. That is, a commented out +-- entry for the locale and an accompanying charset is present in +-- /etc/locale.gen. +-- +-- Per Debian bug #684134 we cannot ensure a locale is generated by means of +-- Apt.reConfigure. So localeAvailable edits /etc/locale.gen manually. +available :: String -> Property NoInfo +available locale = + fileProperty (locale ++ " locale generated") go "/etc/locale.gen" + `onChange` cmdProperty "dpkg-reconfigure" ["-f", "noninteractive", "locales"] + where + go = foldr step [] + step l ls = + if ("# " ++ locale) `isPrefixOf` l + then drop 2 l : ls + else l:ls -- cgit v1.2.3 From 61cc4bab7d8e7cb37d0fb67740257c0e1828751c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 25 Nov 2015 19:25:45 -0700 Subject: locale props use descriptive types & revertable Signed-off-by: Sean Whitton (cherry picked from commit 6d10045ba74c1dc45e6aab4bae8b4757751c1920) --- src/Propellor/Property/Locale.hs | 60 ++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/Propellor/Property/Locale.hs b/src/Propellor/Property/Locale.hs index 7cc98ed1..b179094f 100644 --- a/src/Propellor/Property/Locale.hs +++ b/src/Propellor/Property/Locale.hs @@ -7,33 +7,63 @@ import Propellor.Property.File import Data.List (isPrefixOf) +type Locale = String +type LocaleVariable = String + -- | Select a locale for a list of global locale variables. -- -- A locale variable is of the form `LC_BLAH`, `LANG` or `LANGUAGE`. See `man 5 -- locale`. -selectedFor :: String -> [String] -> Property NoInfo -locale `selectedFor` vars = - trivial $ cmdProperty "update-locale" args - `requires` available locale - `describe` (locale ++ " locale selected") +-- +-- Note that reverting this property does not make a locale unavailable. That's +-- because it might be required for other Locale.selectedFor statements. +selectedFor :: Locale -> [LocaleVariable] -> RevertableProperty NoInfo +locale `selectedFor` vars = select deselect where - args = zipWith (++) vars (repeat ('=':locale)) + select = + trivial $ cmdProperty "update-locale" selectArgs + `requires` available locale + `describe` (locale ++ " locale selected") + deselect = + trivial $ cmdProperty "update-locale" vars + `describe` (locale ++ " locale deselected") + selectArgs = zipWith (++) vars (repeat ('=':locale)) --- | Ensures a locale is generated. +-- | Ensures a locale is generated (or, if reverted, ensure it's not). -- --- Assumes a locale is available to be generated. That is, a commented out --- entry for the locale and an accompanying charset is present in +-- Fails if a locale is not available to be generated. That is, a commented out +-- entry for the locale and an accompanying charset must be present in -- /etc/locale.gen. -- -- Per Debian bug #684134 we cannot ensure a locale is generated by means of -- Apt.reConfigure. So localeAvailable edits /etc/locale.gen manually. -available :: String -> Property NoInfo -available locale = - fileProperty (locale ++ " locale generated") go "/etc/locale.gen" - `onChange` cmdProperty "dpkg-reconfigure" ["-f", "noninteractive", "locales"] +available :: Locale -> RevertableProperty NoInfo +available locale = (ensureAvailable ensureUnavailable) where - go = foldr step [] - step l ls = + f = "/etc/locale.gen" + desc = (locale ++ " locale generated") + ensureAvailable = + property desc $ (lines <$> (liftIO $ readFile f)) + >>= \locales -> + if locale `presentIn` locales + then ensureProperty $ + fileProperty desc (foldr uncomment []) f + `onChange` regenerate + else return FailedChange -- locale unavailable for generation + ensureUnavailable = + fileProperty (locale ++ " locale not generated") (foldr comment []) f + `onChange` regenerate + + uncomment l ls = if ("# " ++ locale) `isPrefixOf` l then drop 2 l : ls else l:ls + comment l ls = + if locale `isPrefixOf` l + then ("# " ++ l) : ls + else l:ls + + l `presentIn` ls = any (l `isPrefix`) ls + l `isPrefix` x = (l `isPrefixOf` x) || (("# " ++ l) `isPrefixOf` x) + + regenerate = cmdProperty "dpkg-reconfigure" ["-f", "noninteractive", "locales"] -- cgit v1.2.3 From 38049b96f6e9d21e49ec159ee4998191a5b247cf Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 25 Nov 2015 19:58:24 -0700 Subject: improve Haddock for Locale.selectedFor Signed-off-by: Sean Whitton (cherry picked from commit ca016d391e2419856e1efc40cc977af6a99af7d6) --- src/Propellor/Property/Locale.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Propellor/Property/Locale.hs b/src/Propellor/Property/Locale.hs index b179094f..420dafb4 100644 --- a/src/Propellor/Property/Locale.hs +++ b/src/Propellor/Property/Locale.hs @@ -12,8 +12,12 @@ type LocaleVariable = String -- | Select a locale for a list of global locale variables. -- --- A locale variable is of the form `LC_BLAH`, `LANG` or `LANGUAGE`. See `man 5 --- locale`. +-- A locale variable is of the form @LC_BLAH@, @LANG@ or @LANGUAGE@. See @man 5 +-- locale@. One might say +-- +-- > & "en_GB.UTF-8" `Locale.selectedFor` ["LC_PAPER", "LC_MONETARY"] +-- +-- to select the British English locale for paper size and currency conventions. -- -- Note that reverting this property does not make a locale unavailable. That's -- because it might be required for other Locale.selectedFor statements. -- cgit v1.2.3 From a60b5da1736cb9d8e5921219c0d4eddaa0c88861 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 25 Nov 2015 19:59:19 -0700 Subject: shorten reference to locale manpage Signed-off-by: Sean Whitton (cherry picked from commit ad7c9338306094f2d8187107417dd9331cb8f8a0) --- src/Propellor/Property/Locale.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Propellor/Property/Locale.hs b/src/Propellor/Property/Locale.hs index 420dafb4..c1040780 100644 --- a/src/Propellor/Property/Locale.hs +++ b/src/Propellor/Property/Locale.hs @@ -12,8 +12,8 @@ type LocaleVariable = String -- | Select a locale for a list of global locale variables. -- --- A locale variable is of the form @LC_BLAH@, @LANG@ or @LANGUAGE@. See @man 5 --- locale@. One might say +-- A locale variable is of the form @LC_BLAH@, @LANG@ or @LANGUAGE@. See +-- @locale(5)@. One might say -- -- > & "en_GB.UTF-8" `Locale.selectedFor` ["LC_PAPER", "LC_MONETARY"] -- -- cgit v1.2.3