aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-04-01 23:29:00 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-04-01 23:33:53 -0700
commitbcbd84a22ce5e15c0bf195f837fec1cd0e14591f (patch)
tree0a26c374b32616772ea642d5b4678c944e03c14b
parente736bb553d404ba03c4e2d4cc58d8d1db9b6a85e (diff)
downloadconsfigurator-bcbd84a22ce5e15c0bf195f837fec1cd0e14591f.tar.gz
add LOCALE:AVAILABLE and LOCALE:SELECTED-FOR
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--consfigurator.asd1
-rw-r--r--debian/copyright4
-rw-r--r--src/package.lisp10
-rw-r--r--src/property/locale.lisp77
4 files changed, 90 insertions, 2 deletions
diff --git a/consfigurator.asd b/consfigurator.asd
index 9c00b25..8ef2293 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -37,6 +37,7 @@
(:file "src/property/gnupg")
(:file "src/property/ssh")
(:file "src/property/sshd")
+ (:file "src/property/locale")
(:file "src/connection/shell-wrap")
(:file "src/connection/fork")
(:file "src/connection/rehome")
diff --git a/debian/copyright b/debian/copyright
index 6d94ea5..0351f31 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,8 +1,8 @@
Consfigurator
Lisp declarative configuration management system
-Copyright (C)2020-2021 Sean Whitton
-Copyright (C)2021 David Bremner
+Copyright (C)2015, 2020-2021 Sean Whitton
+Copyright (C)2021 David Bremner
This program is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
diff --git a/src/package.lisp b/src/package.lisp
index 63f39af..2a64cc3 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -320,6 +320,16 @@
#:configured
#:no-passwords))
+(defpackage :consfigurator.property.locale
+ (:use #:cl #:consfigurator)
+ (:local-nicknames (#:re #:cl-ppcre)
+ (#:os #:consfigurator.property.os)
+ (#:apt #:consfigurator.property.apt)
+ (#:cmd #:consfigurator.property.cmd)
+ (#:file #:consfigurator.property.file))
+ (:export #:available
+ #:selected-for))
+
(defpackage :consfigurator.connection.shell-wrap
(:use #:cl #:consfigurator)
(:export #:shell-wrap-connection #:connection-shell-wrap))
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))))