summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2015-11-26 07:21:05 -0400
committerJoey Hess2015-11-26 07:21:05 -0400
commitd519f507c006071972cfa193963980c7f28b09e9 (patch)
tree265bfa656e74acb31f5ba3a9051000c81fa2e7c6 /src
parent08a03bb4555e28ea7ebe5445d6dd250b06b18f45 (diff)
parentcb97f272633f44edb9ad53982ea9f4bdb8c7192e (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Locale.hs73
-rw-r--r--src/Propellor/Property/Postfix.hs2
2 files changed, 74 insertions, 1 deletions
diff --git a/src/Propellor/Property/Locale.hs b/src/Propellor/Property/Locale.hs
new file mode 100644
index 00000000..c1040780
--- /dev/null
+++ b/src/Propellor/Property/Locale.hs
@@ -0,0 +1,73 @@
+-- | Maintainer: Sean Whitton <spwhitton@spwhitton.name>
+
+module Propellor.Property.Locale where
+
+import Propellor.Base
+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
+-- @locale(5)@. 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.
+selectedFor :: Locale -> [LocaleVariable] -> RevertableProperty NoInfo
+locale `selectedFor` vars = select <!> deselect
+ where
+ 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 (or, if reverted, ensure it's not).
+--
+-- 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 :: Locale -> RevertableProperty NoInfo
+available locale = (ensureAvailable <!> ensureUnavailable)
+ where
+ 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"]
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)