diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-25 12:33:13 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-25 12:37:19 -0700 |
commit | af8737025f27927fa27b9173c37d10145b1a8785 (patch) | |
tree | 7a1a26e7555578e9d6847f3f851bd16fb90fb8c0 /src/property/hostname.lisp | |
parent | c4316097570c8a3b961b6aa08280eb92e4a16ae8 (diff) | |
download | consfigurator-af8737025f27927fa27b9173c37d10145b1a8785.tar.gz |
add CONSFIGURATOR.PROPERTY.HOSTNAME
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/hostname.lisp')
-rw-r--r-- | src/property/hostname.lisp | 55 |
1 files changed, 55 insertions, 0 deletions
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)) |