summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Locale.hs
diff options
context:
space:
mode:
authorSean Whitton2015-11-24 20:15:24 -0700
committerJoey Hess2015-11-26 07:09:03 -0400
commit2969b3b07f2eeb3472f237c6723b75007c34481e (patch)
tree4e461c7ae6cb1d852a382120702f91f97b58497c /src/Propellor/Property/Locale.hs
parentefa7e792a3873e27ac99efa9026eb01d8f69af2a (diff)
properties to select and generate locales
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name> (cherry picked from commit ee14ef80cf9ab761b07fbc40f549ad5c7c72f6cb)
Diffstat (limited to 'src/Propellor/Property/Locale.hs')
-rw-r--r--src/Propellor/Property/Locale.hs39
1 files changed, 39 insertions, 0 deletions
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 <spwhitton@spwhitton.name>
+
+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