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/Propellor/Property/Locale.hs') 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