summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Locale.hs
blob: 7cc98ed1db1908baefadc6fd1ea4b86f39951d1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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