diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-04-01 23:29:00 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-04-01 23:33:53 -0700 |
commit | bcbd84a22ce5e15c0bf195f837fec1cd0e14591f (patch) | |
tree | 0a26c374b32616772ea642d5b4678c944e03c14b /src/property/locale.lisp | |
parent | e736bb553d404ba03c4e2d4cc58d8d1db9b6a85e (diff) | |
download | consfigurator-bcbd84a22ce5e15c0bf195f837fec1cd0e14591f.tar.gz |
add LOCALE:AVAILABLE and LOCALE:SELECTED-FOR
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/locale.lisp')
-rw-r--r-- | src/property/locale.lisp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/property/locale.lisp b/src/property/locale.lisp new file mode 100644 index 0000000..950deef --- /dev/null +++ b/src/property/locale.lisp @@ -0,0 +1,77 @@ +;;; Consfigurator -- Lisp declarative configuration management system + +;;; Copyright (C) 2015, 2021 Sean Whitton <spwhitton@spwhitton.name> + +;;; This file is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3, or (at your option) +;;; any later version. + +;;; This file is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. + +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +(in-package :consfigurator.property.locale) +(named-readtables:in-readtable :consfigurator) + +(defprop %available :posix (locale) + (:desc (declare (ignore locale)) "/etc/locale.gen updated") + (:apply + (assert-euid-root) + (file:map-file-lines + "/etc/locale.gen" + (lambda (lines) + (loop with found + for line in lines + for start = (re:scan #?/\Q${locale}\E\b/ line) + if start + collect (subseq line start) and do (setq found t) + else + collect line + finally (unless found + (failed-change + #?"${locale} not found in /etc/locale.gen"))))))) + +(defproplist available :posix (locale) + "Ensure that the locale LOCALE is generated and available. + +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 this property edits /etc/locale.gen manually." + (apt:installed "locales") + (on-change (%available locale) + (cmd:single "locale-gen"))) + +(defprop selected-for :posix (locale &rest locale-variables) + "Select a locale for a list of global locale variables. + +A locale variable is of the form LC_FOO, LANG or LANGUAGE. See locale(5). +One might say + + (locale:selected-for \"en_GB.UTF-8\" \"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 applications of this property." + (:desc (format nil "~A locale selected for ~{~A~^ ~}" + locale locale-variables)) + (:hostattrs + (declare (ignore locale locale-variables)) + (os:required 'os:debianlike)) + (:apply + (ignoring-hostattrs (available locale)) + (with-change-if-changes-file ("/etc/default/locale") + (run "update-locale" + (mapcar (lambda (v) (strcat v "=" locale)) locale-variables)))) + (:unapply + (declare (ignore locale)) + (with-change-if-changes-file ("/etc/default/locale") + (run "update-locale" locale-variables)))) |