Commit 779c83c1b14fd55d0c118cce835a1314d5786128

Thomas de Grivel 2022-03-28T20:15:00

useradd -m only if directory does not exist

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/unix/operations.lisp b/unix/operations.lisp
index 359a869..472fff3 100644
--- a/unix/operations.lisp
+++ b/unix/operations.lisp
@@ -78,7 +78,13 @@
    (join-str " "
              (ecase ensure
                ((:absent)  "userdel")
-               ((:present) "useradd -m")
+               ((:present) `("useradd"
+                             ,(unless (eq :present
+                                          (get-probed
+                                           (resource 'directory (homedir
+                                                                 user))
+                                           :ensure))
+                                "-m")))
                ((nil)      "usermod"))
              (when realname `("-c" ,(sh-quote realname)))
              (when home `("-d" ,(sh-quote home)))