aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--consfigurator.asd1
-rw-r--r--doc/hosts.rst3
-rw-r--r--src/package.lisp9
-rw-r--r--src/property/hostname.lisp55
4 files changed, 67 insertions, 1 deletions
diff --git a/consfigurator.asd b/consfigurator.asd
index 3ba1e9c..4f72b70 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -48,6 +48,7 @@
(:file "src/property/installer")
(:file "src/property/grub")
(:file "src/property/u-boot")
+ (:file "src/property/hostname")
(:file "src/connection/shell-wrap")
(:file "src/connection/fork")
(:file "src/connection/rehome")
diff --git a/doc/hosts.rst b/doc/hosts.rst
index f3af469..af5104b 100644
--- a/doc/hosts.rst
+++ b/doc/hosts.rst
@@ -28,7 +28,8 @@ all of those properties are defined. This minimises the risk of any clashes.
Many attributes, however, will be shared across properties, and should use
keyword symbols. The semantics of these attributes are documented here:
-- ``:HOSTNAME``: the host's hostname
+- ``:HOSTNAME``: the host's hostname -- if the host has a domain name, then
+ the FQDN, not just the part before the first dot
- ``:DATA``: items of prerequisite data required by the host
diff --git a/src/package.lisp b/src/package.lisp
index 192fc23..9b39949 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -525,6 +525,15 @@
(:export #:u-boot-install-rockchip
#:u-boot-installed-rockchip))
+(defpackage :consfigurator.property.hostname
+ (:use #:cl #:consfigurator)
+ (:local-nicknames (#:cmd #:consfigurator.property.cmd)
+ (#:container #:consfigurator.property.container)
+ (#:file #:consfigurator.property.file))
+ (:export #:configured
+ #:mailname-configured
+ #:search-configured))
+
(defpackage :consfigurator.connection.local
(:use #:cl #:consfigurator #:alexandria)
(:export #:local-connection))
diff --git a/src/property/hostname.lisp b/src/property/hostname.lisp
new file mode 100644
index 0000000..3930b96
--- /dev/null
+++ b/src/property/hostname.lisp
@@ -0,0 +1,55 @@
+;;; Consfigurator -- Lisp declarative configuration management system
+
+;;; Copyright (C) 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.hostname)
+(named-readtables:in-readtable :consfigurator)
+
+(defun domain (hostname)
+ (subseq hostname (min (length hostname) (1+ (position #\. hostname)))))
+
+(defpropspec configured :posix
+ (&optional (hostname (get-hostname)) (domain (domain hostname))
+ &aux (short (car (split-string hostname :separator "."))))
+ "Set the hostname in the standard Debian way.
+When HOSTNAME is an FQDN, DOMAIN is the domain part of the hostname,
+defaulting to everything after the first dot. (For some hosts, the domain
+should rather be the whole hostname.)"
+ (:desc "Hostname configured")
+ `(seqprops
+ (on-change (file:has-content "/etc/hostname" ,short)
+ (container:when-contained (:hostname)
+ (cmd:single ,(strcat "hostname " short))))
+ (file:contains-conf-tab
+ "/etc/hosts"
+ ,@(and (plusp (length domain))
+ `("127.0.1.1" ,(strcat hostname " " short)))
+ "127.0.0.1" "localhost")))
+
+(defproplist mailname-configured :posix (&optional (mailname (get-hostname)))
+ "Sets the mailname to MAILNAME.
+The FQDN is a good choice for unclustered machines which do not have
+publically advertised MX records; in other cases it will often be better to
+use only the domain name portion of the hostname."
+ (:desc "/etc/mailname configured")
+ (file:has-content "/etc/mailname" mailname))
+
+(defproplist search-configured :posix (&optional (domain (domain (get-hostname))))
+ "Set the default DOMAIN for hostname lookup in /etc/resolv.conf.
+DOMAIN defaults to everything after the first dot of the machine's hostname,
+which is assumed to be an FQDN."
+ (:desc "Search domain in /etc/resolv.conf configured")
+ (file:contains-conf-space "/etc/resolv.conf" "search" domain))