-- | 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