aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-04-01 12:54:29 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-04-01 15:47:54 -0700
commit6ddbb0f222980f0f8f54284ea8bb5e4d94f68b80 (patch)
treec7ff11abed91c37de58a0a394864549d5b50586e
parentc9b0ce53bd72ddd34be7ec4ee8a14bb710ebd8fb (diff)
downloadconsfigurator-6ddbb0f222980f0f8f54284ea8bb5e4d94f68b80.tar.gz
add FILE:CONTAINS-EQUALS-CONF & rename property for conf-space files
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--src/package.lisp3
-rw-r--r--src/property/file.lisp15
-rw-r--r--src/property/sshd.lisp2
3 files changed, 17 insertions, 3 deletions
diff --git a/src/package.lisp b/src/package.lisp
index f6808d6..336cfcd 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -222,7 +222,8 @@
#:host-data-uploaded
#:secret-uploaded
#:host-secret-uploaded
- #:contains-conf-pairs
+ #:contains-equals-conf
+ #:contains-space-conf
#:contains-shell-conf
#:contains-ini-settings
#:regex-replaced-lines
diff --git a/src/property/file.lisp b/src/property/file.lisp
index 56009d6..3c3e5f3 100644
--- a/src/property/file.lisp
+++ b/src/property/file.lisp
@@ -241,7 +241,7 @@ Other arguments:
finally (return (nconc new-lines accum)))))
args))))
-(defprop contains-conf-pairs :posix (file &rest pairs)
+(defprop contains-space-conf :posix (file &rest pairs)
"Where FILE is a config file in which keys and values are separated by spaces
and there are no sections, and PAIRS is a list of even length of alternating
keys and values, set each of these keys and values in FILE.
@@ -254,6 +254,19 @@ uncommented and used to set the value, if it exists."
:parse-kv #?/^(\S+) (.+)/
:new-kv (lambda (k v) #?"${k} ${v}"))))
+(defprop contains-equals-conf :posix (file &rest pairs)
+ "Where FILE is a config file in which keys and values are separated by \" = \"
+and there are no sections, and PAIRS is a list of even length of alternating
+keys and values, set each of these keys and values in FILE.
+
+If there are any other lines which set values for the same keys, they will be
+commented out; the first commented or uncommented line for each key will be
+uncommented and used to set the value, if it exists."
+ (:desc (format nil "~A has ~{~A = ~A~^, ~}" file pairs))
+ (:apply (simple-conf-update file pairs
+ :parse-kv #?/^(\S+) = (.+)/
+ :new-kv (lambda (k v) #?"${k} = ${v}"))))
+
(defprop contains-shell-conf :posix (file &rest pairs)
"Where FILE is a shell config file, like those in /etc/default, and PAIRS is a
list of even length of alternating keys and values, set each of these keys and
diff --git a/src/property/sshd.lisp b/src/property/sshd.lisp
index e0807b2..f24d837 100644
--- a/src/property/sshd.lisp
+++ b/src/property/sshd.lisp
@@ -28,4 +28,4 @@
"Set key--value pairs in /etc/ssh/sshd_config."
(:desc (format nil "sshd configured ~{~A ~A~^, ~}" pairs))
(:apply
- (apply #'file:contains-conf-pairs "/home/spwhitton/tmp/config" pairs)))
+ (apply #'file:contains-space-conf "/home/spwhitton/tmp/config" pairs)))