diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..f27f198
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+github: thodg
diff --git a/LICENSE.md b/LICENSE.md
index 250cdd5..0535628 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,19 +1,7 @@
# Adams license information
Adams - UNIX system administration tool written in Common Lisp
-Copyright 2013,2014,2018,2020 Thomas de Grivel <thoxdg@gmail.com>
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
## Adams dependencies license information
@@ -579,40 +567,6 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-### re
-
-Copyright 2014 Thomas de Grivel <thomas@lowh.net>
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-
-### str
-
-Copyright 2012-2015 Thomas de Grivel <thomas@lowh.net>
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-
### trivial-utf-8
Copyright (c) Marijn Haverbeke
diff --git a/Makefile b/Makefile
index 0e0c10c..4f8385d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,17 @@
-
+## Adams - UNIX system administration tool written in Common Lisp
+## Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
+
+PACKAGE = adams
+VERSION = 0.3.2
+RELEASE_DIR = ${PACKAGE}-${VERSION}
+RELEASE_TARBALL = ${PACKAGE}-${VERSION}.tar.gz
+RELEASE_DEPS_TARBALL = ${PACKAGE}-${VERSION}.deps.tar.gz
PROGRAM = build/adams
PREFIX = /usr/local
-LISP = sbcl
+LISP = sbcl --dynamic-space-size 2048
LISP_LOAD = ${LISP} --load
+CLEANFILES = build/*
+DISTCLEANFILES = ${RELEASE_DIR} ${RELEASE_TARBALL} ${RELEASE_DEPS_TARBALL}
all: ${PROGRAM}
@@ -15,10 +24,23 @@ build/systems.lisp: prepare-build.lisp adams.asd
${PROGRAM}: build.lisp config.lisp build/systems.lisp toplevel.lisp
LANG=C.UTF-8 ${LISP_LOAD} build.lisp --quit
+install:
+ install -m 0755 ${PROGRAM} ${PREFIX}/bin
+
+release: ${RELEASE_TARBALL} ${RELEASE_DEPS_TARBALL}
+
+${RELEASE_TARBALL}:
+ mkdir ${RELEASE_DIR}
+ find . -name build -prune -or -name '*.lisp' -or -name '*.asd' -or -name '*.md' | cpio -pd ${RELEASE_DIR}
+ tar czf ${RELEASE_TARBALL} ${RELEASE_DIR}
+
+${RELEASE_DEPS_TARBALL}:
+ tar czf ${RELEASE_DEPS_TARBALL} build/*.lisp
+
clean:
- rm -rf build/*
+ rm -rf ${CLEANFILES}
-install: ${PROGRAM}
- install -m 0755 ${PROGRAM} ${PREFIX}/bin
+distclean:
+ rm -rf ${DISTCLEANFILES}
-.PHONY: all clean deps install ${PROGRAM}
+.PHONY: all clean deps install ${PROGRAM} release
diff --git a/README.md b/README.md
index 484cd8e..3408ef9 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-Adams 0.1
-=========
+Adams 0.3.2
+===========
Adams is a UNIX system administration tool written in Common Lisp.
@@ -8,12 +8,6 @@ You describe your systems (hosts) using resources having properties.
The properties are then probed and synchronized by Adams using only
`/bin/sh` on the remote host, and `/usr/bin/ssh` on the control host.
-More viable alternatives include
-[Ansible](https://www.ansible.com/),
-[Chef](https://www.chef.io/)
-and
-[Puppet](https://puppet.com/).
-
Configuration example
---------------------
@@ -148,37 +142,11 @@ In your main script :
```
-ISC License
------------
-```
-;; Copyright YEAR AUTHOR <EMAIL>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
-```
-
-
-Contribute
-----------
-
-To contribute, fork this repository and send us a pull request.
-
-Please publish under the
-[ISC License](https://en.wikipedia.org/wiki/ISC_license)
-terms.
+[License](LICENSE.md)
+---------------------
Authors
-------
-Thomas de Grivel <thoxdg@gmail.com>
+Thomas de Grivel <thodg@kmx.io>
diff --git a/adams.asd b/adams.asd
index d6590f8..00eab78 100644
--- a/adams.asd
+++ b/adams.asd
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(defpackage :adams.system
(:use :cl :asdf))
@@ -67,6 +52,7 @@
(:file "linux" :depends-on ("commands" "defs"))
(:file "openbsd" :depends-on ("commands" "defs"))
(:file "freebsd" :depends-on ("commands" "defs"))
+ (:file "darwin" :depends-on ("commands" "defs"))
(:file "operations" :depends-on ("commands" "defs"))
(:file "probes" :depends-on ("commands" "defs"
"stat" "syntaxes"))
diff --git a/build.lisp b/build.lisp
index 8f03252..5f38baf 100644
--- a/build.lisp
+++ b/build.lisp
@@ -1,23 +1,14 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :common-lisp-user)
+(declaim (optimize (speed 1)
+ (space 1)
+ (safety 3)
+ (debug 3)
+ (compilation-speed 0)))
+
(defun compile-lisp (path)
(let* ((fasl (make-pathname :type "fasl" :defaults path))
(fasl (merge-pathnames fasl)))
diff --git a/config.lisp b/config.lisp
index 207c5fe..c039f50 100644
--- a/config.lisp
+++ b/config.lisp
@@ -1,2 +1,4 @@
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(declaim (optimize (debug 3) (safety 3) (speed 3)))
diff --git a/core/defs.lisp b/core/defs.lisp
index 064f98f..d2123a1 100644
--- a/core/defs.lisp
+++ b/core/defs.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -195,6 +180,7 @@
(probe-host-locale :properties (:locale))
(probe-host-packages :properties (:packages))
(probe-boot-time :properties (:boot-time))
+ (probe-host-homedir :properties (:homedir))
(probe-host-user :properties (:user))
(probe-hostname :properties (:hostname)))
((op-host-locale :properties (:locale))
@@ -261,3 +247,7 @@
`(loop
(unless (remf ,place ,indicator)
(return))))
+
+;; Shebang
+
+(set-dispatch-macro-character #\# #\! #'read-line)
diff --git a/core/helpers.lisp b/core/helpers.lisp
index f72ac9b..8955517 100644
--- a/core/helpers.lisp
+++ b/core/helpers.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2020 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -28,3 +13,20 @@
(when (zerop size)
(return))
(write-sequence buf out :end size))))))))
+
+(defun static-file (path &rest plist)
+ (resource 'file path
+ :content (read-file (hostname *host*) path)
+ plist))
+
+(defun static-directory (directory &rest plist)
+ (let* ((host-dir (truename (pathname (the string
+ (str (hostname) #\/)))))
+ (dir-path (str host-dir directory)))
+ (print dir-path)
+ (mapcar (lambda (path)
+ (let ((name (enough-namestring path host-dir)))
+ (resource 'file (str "/" name)
+ :content (read-file path)
+ plist)))
+ (directory dir-path))))
diff --git a/core/host.lisp b/core/host.lisp
index acf2908..5a17214 100644
--- a/core/host.lisp
+++ b/core/host.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -71,9 +56,26 @@
;; Host
-(defun hostname (&optional (host *host*))
+(defun hostname (&optional (host (current-host)))
(resource-id (the host host)))
+(defun homedir (user &optional (host (current-host)))
+ (str (etypecase (host-os host)
+ (os-darwin "/Users")
+ (os "/home"))
+ "/"
+ (etypecase user
+ (user (resource-id user))
+ (string user))))
+
+(defgeneric probe-host-homedir (host os))
+
+(defmethod probe-host-homedir (host (os os-unix))
+ '(:homedir "/home"))
+
+(defmethod probe-host-homedir (host (os os-darwin))
+ '(:homedir "/Users"))
+
;; Host shell
(defmethod host-shell ((host host))
diff --git a/core/include.lisp b/core/include.lisp
index 9690eac..da6142a 100644
--- a/core/include.lisp
+++ b/core/include.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2020 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -23,13 +8,13 @@
(let ((path (str parts)))
(when (probe-file path)
(return-from include/resolve-filename path)))))
- (try spec)
- (try spec ".adams")))
+ (try spec ".adams")
+ (try spec)))
(defun include/resolve-filename! (spec)
(or (include/resolve-filename spec)
(error "(include ~S) => file not found.~%
-Current directory : ~S" source *default-pathname-defaults*)))
+Current directory : ~S" spec *default-pathname-defaults*)))
(defun include (&rest sources)
(let* ((head (cons 'list nil))
diff --git a/core/operation.lisp b/core/operation.lisp
index cd34c7f..76e4ead 100644
--- a/core/operation.lisp
+++ b/core/operation.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -170,14 +155,13 @@
(defun print-diff (stream diff)
(dolist (item diff)
(destructuring-bind (property expected probed) item
- (declare (type symbol property)
- (type list expected probed))
+ (declare (type symbol property))
(write-str stream property #\Newline
" expected ")
- (print-list expected stream)
+ (prin1 expected stream)
(write-str stream #\Newline
" probed ")
- (print-list probed stream)
+ (prin1 probed stream)
(write-str stream #\Newline))))
(defmethod print-object ((c resource-operation-failed) stream)
diff --git a/core/os.lisp b/core/os.lisp
index 54e2a2f..0ffdace 100644
--- a/core/os.lisp
+++ b/core/os.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/core/probe.lisp b/core/probe.lisp
index 2fc2e8f..c9fc2be 100644
--- a/core/probe.lisp
+++ b/core/probe.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/core/properties.lisp b/core/properties.lisp
index a232b4b..d97f345 100644
--- a/core/properties.lisp
+++ b/core/properties.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/core/resource-container.lisp b/core/resource-container.lisp
index b102d5c..43636f4 100644
--- a/core/resource-container.lisp
+++ b/core/resource-container.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/core/resource.lisp b/core/resource.lisp
index d5ea4e5..a07c641 100644
--- a/core/resource.lisp
+++ b/core/resource.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/core/spec.lisp b/core/spec.lisp
index 6d9106a..13a2853 100644
--- a/core/spec.lisp
+++ b/core/spec.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -122,14 +107,33 @@ First value lists properties out of specification in the following format :
Second value lists properties in line with spec. Format is
(PROPERTY-NAME VALUE)"))
-(defmethod resource-diff ((res resource))
- (let ((specified-properties (specified-properties res))
- diff)
+(defvar *virtual-properties*
+ '(:after
+ :before)
+ "Special properties that will not be synchronized.")
+
+(declaim (type list *virtual-properties*))
+
+(defun diffable-properties (specified-properties)
+ (let ((properties))
(loop
(when (endp specified-properties)
- (return))
+ (return (nreverse properties)))
(let* ((property (pop specified-properties))
- (specified (pop specified-properties))
+ (specified (pop specified-properties)))
+ (unless (find property *virtual-properties* :test #'eq)
+ (push property properties)
+ (push specified properties))))))
+
+(defmethod resource-diff ((res resource))
+ (let* ((specified-properties (specified-properties res))
+ (properties (diffable-properties specified-properties))
+ diff)
+ (loop
+ (when (endp properties)
+ (return))
+ (let* ((property (pop properties))
+ (specified (pop properties))
(probed (get-probed res property))
(desc (describe-probed-property-value res property probed)))
(unless (match-specified-value res property specified desc (host-os *host*))
diff --git a/core/syntaxes.lisp b/core/syntaxes.lisp
index 60638a9..8b8d6b4 100644
--- a/core/syntaxes.lisp
+++ b/core/syntaxes.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/package.lisp b/package.lisp
index b195fca..efca103 100644
--- a/package.lisp
+++ b/package.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :cl-user)
@@ -115,6 +100,7 @@
#:resource-diff
;; Host
#:current-host
+ #:homedir
#:host
#:host-connect
#:host-disconnect
@@ -123,6 +109,8 @@
#:host-run
#:localhost
#:run
+ #:run-as-root
+ #:run-as-root-command
#:ssh-host
#:with-connected-host
#:with-host
@@ -143,6 +131,7 @@
#:ssh-authorized-key
#:stat
#:stat<1>
+ #:symlink
#:+timestamp-offset+
#:timestamp-to-universal-time
#:universal-time-to-timestamp
@@ -153,6 +142,8 @@
;; helpers
#:include
#:read-file
+ #:static-file
+ #:static-directory
#:str
))
diff --git a/prepare-build.lisp b/prepare-build.lisp
index 65c2147..3c8234a 100644
--- a/prepare-build.lisp
+++ b/prepare-build.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2020 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :common-lisp-user)
@@ -123,10 +108,17 @@
(defmethod collect-sources :around ((x asdf:component))
(let ((if-feature (asdf::component-if-feature x)))
- (if if-feature
- (when (find (the symbol if-feature) *features*)
- (call-next-method))
- (call-next-method))))
+ (etypecase if-feature
+ (null
+ (call-next-method))
+ (symbol
+ (when (find (the symbol if-feature) *features*)
+ (call-next-method)))
+ (cons
+ (cond ((string-equal 'not (first if-feature))
+ (unless (find (the symbol (second if-feature)) *features*)
+ (call-next-method)))
+ (t (error "Bad if-feature")))))))
#+nil (collect-sources :adams)
@@ -156,10 +148,11 @@
(let (dependencies)
(labels ((dfs (name)
(let ((sys (asdf:find-system name)))
- (when sys
+ (when (and sys (not (find sys dependencies)))
(locally (declare (type asdf:system sys))
+ (format t "~& ~A" sys) (force-output)
(map 'nil #'dfs (asdf:system-depends-on sys))
- (pushnew sys dependencies))))))
+ (push sys dependencies))))))
(dfs name)
(nreverse dependencies))))
@@ -180,6 +173,7 @@
(load-form `(load ,build-file)))
(format t "~& ~A~%" sys) (force-output)
(print load-form out)))
- (fresh-line out))))
+ (fresh-line out)
+ (force-output out))))
(write-build-systems-file :adams)
diff --git a/shell/sb-shell.lisp b/shell/sb-shell.lisp
index 9abbbee..e7627f9 100644
--- a/shell/sb-shell.lisp
+++ b/shell/sb-shell.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/shell/shell.lisp b/shell/shell.lisp
index 3f3e1cc..c4aa608 100644
--- a/shell/shell.lisp
+++ b/shell/shell.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -137,7 +122,7 @@ Error: ~S"
(shell-in (format nil " ; echo \"~%~A $?\"~%" delim) shell)
(let* ((prev nil)
(status
- (loop (let ((line (the string (shell-out/line shell))))
+ (loop (let ((line (shell-out/line shell)))
(when (or (null line)
(and (< len (length line))
(string= delim line :end2 len)))
@@ -160,7 +145,7 @@ Error: ~S"
(shell-log shell "| ~A~%" line))
(dolist (line err)
(shell-log shell "# ~A~&" line))
- (unless (= 0 status)
+ (unless (and status (= 0 status))
(shell-log shell " ⇒ ~D~%" status)))
(values status out err))))
diff --git a/test.lisp b/test.lisp
index 7da15f0..e57cce3 100644
--- a/test.lisp
+++ b/test.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :cl-user)
@@ -32,6 +17,11 @@
(adams:clear-resources)
(adams:clear-probed)
+(resource 'symlink "/home/dx/test-symlink"
+ :owner "dx"
+ :group "dx"
+ :target "../test")
+
(resource 'host "ams.kmx.io"
:user "root"
:hostname "ams"
diff --git a/toplevel.lisp b/toplevel.lisp
index 3396cc6..576873b 100644
--- a/toplevel.lisp
+++ b/toplevel.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/unix/commands.lisp b/unix/commands.lisp
index b5018a9..90868f2 100644
--- a/unix/commands.lisp
+++ b/unix/commands.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -54,3 +39,9 @@
(defun sudo (&rest command)
(run (apply #'sudo_ command)))
+
+(defun doas_ (&rest command)
+ (join-str " " "doas" command))
+
+(defun doas (&rest command)
+ (run (apply #'doas_ command)))
diff --git a/unix/darwin.lisp b/unix/darwin.lisp
new file mode 100644
index 0000000..0e48d54
--- /dev/null
+++ b/unix/darwin.lisp
@@ -0,0 +1,192 @@
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
+
+(in-package :adams)
+
+(in-re-readtable)
+
+(defmethod echo-command ((host t) (os os-darwin))
+ "printf %s ")
+
+(defmethod probe-hostname ((host host) (os os-darwin))
+ (list :hostname (run-1 "hostname -s")))
+
+(define-resource-class brew-pkg (pkg)
+ ()
+ ((probe-brew-pkg :properties (:ensure :flavor :version)))
+ ((op-brew-pkg :properties (:ensure :version))))
+
+(defgeneric probe-brew-pkg (resource os))
+
+(defgeneric op-brew-pkg (pkg os &key ensure version))
+
+(defmethod probe-host-packages ((host host) (os os-darwin))
+ (list :packages ()))
+
+(defmethod op-host-packages ((host host) (os os-darwin) &key packages)
+ nil)
+
+(defmethod op-hostname ((host host) (os os-unix) &key hostname)
+ (run-as-root "hostname -s " (sh-quote hostname)))
+
+(defmethod probe-group ((group group) (os os-darwin))
+ (let ((id (resource-id group))
+ (ensure :absent)
+ (gid nil))
+ (multiple-value-bind (out status)
+ (run "dscl . -read /Groups/" (sh-quote id))
+ (when (= 0 status)
+ (setq ensure :present)
+ (dolist (line out)
+ (re-bind "PrimaryGroupID: ([0-9]+)" (n) line
+ (setq gid (parse-number n)))))
+ (properties* ensure gid))))
+
+#+nil
+(probe (resource 'group "dx") :gid)
+
+(defmethod probe-user ((user user) (os os-darwin))
+ (let* ((id (resource-id user))
+ (sh-id (sh-quote id))
+ (ensure :absent)
+ uid
+ gid
+ shell
+ home)
+ (multiple-value-bind (out status)
+ (run "dscl . -read /Users/" sh-id)
+ (when (= 0 status)
+ (setq ensure :present)
+ (dolist (line out)
+ (re-bind #~|^UniqueID: ([0-9]+)| (n) line
+ (setq uid (parse-number n)))
+ (re-bind #~|^PrimaryGroupID: ([0-9]+)| (n) line
+ (setq gid (parse-number n)))
+ (re-bind #~|^UserShell: (/[^ \n]+)| (s) line
+ (setq shell s))
+ (re-bind #~|^NFSHomeDirectory: (/[^ \n]+)| (h) line
+ (setq home h)))))
+ (let ((realname (string-trim
+ '(#\Space #\Newline)
+ (second (run "dscl . -read /Users/" sh-id
+ " RealName")))))
+ (properties* ensure uid gid shell home realname))))
+
+#+nil
+(probe (resource 'user "root") :gid)
+
+(define-syntax id<1>-tr ((#'parse-integer gid) name)
+ #~|([0-9]+)[(]([^)]+)|)
+
+(defmethod probe-user-groups ((user user) (os os-darwin))
+ (let ((id (resource-id user))
+ (groups nil))
+ (unless (eq :absent (get-probed user :ensure))
+ (let ((user-gid (get-probed user :gid))
+ (user-group nil))
+ (with-id<1>-tr (gid name) (run "id " (sh-quote id)
+ " | tr ' ,=' '\\n'")
+ (when gid
+ (when (= user-gid gid)
+ (setq user-group (resource 'group name)))
+ (push (resource 'group name) groups)))
+ (setq groups (sort groups #'string< :key #'resource-id)
+ groups (if user-group
+ (cons user-group
+ (remove (resource-id user-group)
+ groups :key #'resource-id
+ :test #'string=))
+ groups)
+ groups (remove-if (lambda (x)
+ (find (resource-id x)
+ '("_lpoperator"
+ "com.apple.access_ssh"
+ "com.apple.sharepoint.group.1"
+ "com.apple.sharepoint.group.2"
+ "everyone"
+ "localaccounts")
+ :test #'string=))
+ groups))))
+ (properties* groups)))
+
+#+nil
+(probe (resource 'user "root") :groups)
+
+(defmethod op-update-group ((group group) (os os-darwin) &key ensure gid)
+ (let ((id (resource-id group)))
+ (run-as-root
+ (join-str
+ " "
+ "dscl ."
+ (ecase ensure
+ ((:absent) "-delete")
+ ((:present) "-create")
+ ((nil) "-change"))
+ (str "/Groups/" (sh-quote id))
+ (when gid
+ `("PrimaryGroupID"
+ ,(unless ensure
+ (sh-quote (get-probed group :gid)))
+ ,(sh-quote gid)))))))
+
+(defmethod op-update-user ((user user) (os os-darwin)
+ &key ensure uid gid realname home shell
+ login-class groups)
+ (declare (ignore login-class))
+ (sync-groups)
+ (let* ((id (resource-id user))
+ (sh-id (sh-quote id)))
+ (when ensure
+ (run-as-root
+ "dscl . "
+ (ecase ensure
+ ((:absent) "-delete ")
+ ((:present) "-create "))
+ (str "/Users/" sh-id)))
+ (when uid
+ (run-as-root
+ "dscl . -create /Users/" sh-id
+ " UniqueID "
+ (sh-quote uid)))
+ (when gid
+ (run-as-root
+ "dscl . -create /Users/" sh-id
+ " PrimaryGroupID "
+ (sh-quote gid)))
+ (when home
+ (run-as-root
+ "dscl . -create /Users/" sh-id
+ " NFSHomeDirectory "
+ (sh-quote home)))
+ (when shell
+ (run-as-root
+ "dscl . -create /Users/" sh-id
+ " UserShell "
+ (sh-quote shell)))
+ (dolist (group (get-probed user :groups))
+ (unless (find (resource-id group) groups)
+ (run-as-root
+ "dscl . -delete /Groups/" (sh-quote (resource-id group))
+ " GroupMembership " sh-id)))
+ (dolist (group groups)
+ (run-as-root
+ "dscl . -append /Groups/" (sh-quote group)
+ " GroupMembership " sh-id))))
+
+#+nil
+(clear-resources)
+
+#+nil
+(describe-probed (resource 'openbsd-pkg "emacs"))
+
+#+nil
+(probe-host-packages *host* (host-os *host*))
+
+#+nil
+(probe *host* :packages)
+
+#+nil
+(map nil #'describe-probed (probe-installed-packages))
+
+#+nil
+(run "pkg_info -q | grep emacs-")
diff --git a/unix/debian.lisp b/unix/debian.lisp
index a9d3f54..734e4b9 100644
--- a/unix/debian.lisp
+++ b/unix/debian.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/unix/defs.lisp b/unix/defs.lisp
index fb32d1b..7bb5065 100644
--- a/unix/defs.lisp
+++ b/unix/defs.lisp
@@ -1,41 +1,26 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
;; Group
(define-resource-class group () ()
- ((probe-group-in-/etc/group :properties (:ensure :name :passwd :gid :members)))
+ ((probe-group :properties (:ensure :name :passwd :gid :members)))
((op-update-group :properties (:ensure :gid))))
-(defgeneric probe-group-in-/etc/group (resource os))
+(defgeneric probe-group (resource os))
(defgeneric op-update-group (resource os &key ensure gid))
;; User
(define-resource-class user (resource-container)
()
- ((probe-user-in-/etc/passwd :properties (:ensure :login :uid :gid :realname
- :home :shell))
- (probe-user-groups-in-/etc/group :properties (:groups)))
+ ((probe-user :properties (:ensure :login :uid :gid :realname
+ :home :shell))
+ (probe-user-groups :properties (:groups)))
((op-update-user :properties (:ensure :uid :gid :realname :home :shell
- :login-class :groups))))
+ :login-class :groups))))
(defgeneric probe-user-in-/etc/passwd (resource os))
(defgeneric probe-user-groups-in-/etc/group (resource os))
@@ -94,6 +79,19 @@
(defgeneric op-file-ensure (resource os &key ensure))
(defgeneric op-file-content (resource os &key content))
+;; Symbolic link
+
+(define-resource-class symlink (vnode)
+ ()
+ ((probe-symlink-target :properties (:target)))
+ ((op-symlink-ensure :properties (:ensure))
+ (op-symlink-target :properties (:target)))
+ ((:op-properties (:ensure :target))))
+
+(defgeneric probe-symlink-target (resource os))
+(defgeneric op-symlink-ensure (resource os &key ensure))
+(defgeneric op-symlink-target (resource os &key target))
+
;; Directory
(define-resource-class directory (vnode)
diff --git a/unix/freebsd.lisp b/unix/freebsd.lisp
index 7fb3042..9b34175 100644
--- a/unix/freebsd.lisp
+++ b/unix/freebsd.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/unix/linux.lisp b/unix/linux.lisp
index be4b6b3..4d2f441 100644
--- a/unix/linux.lisp
+++ b/unix/linux.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/unix/openbsd.lisp b/unix/openbsd.lisp
index 64908d3..6ba2960 100644
--- a/unix/openbsd.lisp
+++ b/unix/openbsd.lisp
@@ -1,32 +1,23 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
(in-re-readtable)
+(defmethod echo-command ((host t) (os os-openbsd))
+ "echo -E -n ")
+
+(defmethod run-as-root-command ((host t) (os os-openbsd))
+ "doas ")
+
(defmethod probe-hostname ((host host) (os os-openbsd))
(list :hostname (run-1 "hostname -s")))
(define-resource-class openbsd-pkg (pkg)
()
((probe-openbsd-pkg :properties (:ensure :flavor :version)))
- ((op-openbsd-pkg :properties (:ensure))))
+ ((op-openbsd-pkg :properties (:ensure :version))))
(define-syntax pkg_info<1> (name version flavor installed)
#~|\s*([^-\s]+(?:-[^-0-9\s][^-\s]+)*)-([0-9][^-\s]*)(?:-([^-\s]+))?( \(installed\))?|
@@ -43,11 +34,11 @@
(let ((id (resource-id pkg))
(ensure :absent))
(with-openbsd-pkg-id (id-name id-version id-flavor) (list id)
- ;(format t "~&id-name ~S id-flavor ~S~%" id-name id-flavor)
+ (format t "~&id-name ~S id-flavor ~S~%" id-name id-flavor)
(multiple-value-bind (version flavor)
(with-pkg_info<1> (name version flavor installed)
(run "pkg_info | egrep " (sh-quote (str "^" id-name)))
- ;(format t "~&name ~S version ~S flavor ~S installed ~S~%" name version flavor installed)
+ (format t "~&name ~S version ~S flavor ~S installed ~S~%" name version flavor installed)
(when (and (string= id-name name)
(or (and (null id-flavor) (null flavor))
(and id-flavor flavor
@@ -58,34 +49,26 @@
(return (values version flavor))))
(return (properties* ensure version flavor))))))
-(defmethod merge-property-values ((pkg openbsd-pkg)
- (property (eql :versions))
- (old list)
- (new list))
- (sort (remove-duplicates (append old new))
- #'string<))
-
(defmethod match-specified-value ((res host)
(property (eql :packages))
(specified list)
(probed list)
(os os-openbsd))
- (format t "~&match-specified-value specified ~S~%" specified)
- (format t "~&match-specified-value probed ~S~%" probed)
- (force-output)
- (with-openbsd-pkg-id (name version flavor) specified
- (unless (find name probed :test #'string=)
- (return nil)))
+ (dolist (pkg-id specified)
+ (unless (find pkg-id probed :test #'string=)
+ (return-from match-specified-value nil)))
t)
-(defmethod op-openbsd-pkg ((pkg openbsd-pkg) (os os-openbsd) &key ensure)
+(defmethod op-openbsd-pkg ((pkg openbsd-pkg) (os os-openbsd) &key ensure version)
(with-openbsd-pkg-id (id-name id-version id-flavor) (list (resource-id pkg))
- (when (and id-flavor (not id-version))
- (probe pkg :version))
+ (setq version
+ (or version
+ id-version
+ (progn (probe pkg :version)
+ (get-probed pkg :version))))
(let ((pkg-string (str id-name
- (when (or id-version id-flavor)
- `(#\- ,(or id-version
- (get-probed pkg :version))))
+ (when version
+ `(#\- ,version))
(when id-flavor
`(#\- ,id-flavor)))))
(cond
@@ -111,16 +94,17 @@
(defmethod op-host-packages ((host host) (os os-openbsd) &key packages)
(with-host host
- (with-openbsd-pkg-id (name version flavor) packages
- (let ((pkg (resource 'openbsd-pkg name
- :ensure :installed)))
- (when version
- (resource 'openbsd-pkg name
- :version version))
- (when flavor
- (resource 'openbsd-pkg name
- :flavor flavor))
- (sync pkg)))))
+ (dolist (pkg-id packages)
+ (with-openbsd-pkg-id (name version flavor) (list pkg-id)
+ (let ((pkg (resource 'openbsd-pkg pkg-id
+ :ensure :installed)))
+ (when version
+ (resource 'openbsd-pkg pkg-id
+ :version version))
+ (when flavor
+ (resource 'openbsd-pkg pkg-id
+ :flavor flavor))
+ (sync pkg))))))
#+nil
(clear-resources)
diff --git a/unix/operations.lisp b/unix/operations.lisp
index 735a8df..fdd219c 100644
--- a/unix/operations.lisp
+++ b/unix/operations.lisp
@@ -1,28 +1,35 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
+;; Echo
+
+(defgeneric echo-command (host os))
+
+(defmethod echo-command ((host t) (os t))
+ "echo -n ")
+
+(defun echo_ (&rest parts)
+ (let* ((host (current-host))
+ (cmd (echo-command host (host-os host))))
+ (str cmd (sh-quote parts))))
+
+(defun echo (&rest parts)
+ (run (echo_ parts)))
+
+;; Run as root
+
+(defgeneric run-as-root-command (host os))
+
+(defmethod run-as-root-command ((host t) (os os-unix))
+ "sudo ")
+
(defun run-as-root (&rest command)
- (apply #'run
- (unless (equal "root" (get-probed (current-host) :user))
- "sudo ")
- command))
+ (let* ((host (current-host))
+ (prefix (unless (equal "root" (get-probed host :user))
+ (run-as-root-command host (get-probed host :os)))))
+ (apply #'run prefix command)))
;; Host operations
@@ -56,13 +63,19 @@
(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)))
(when gid `("-g" ,(sh-quote gid)))
(when login-class `("-L" ,(sh-quote login-class)))
- (when groups `("-S" ,(join-str "," (mapcar #'sh-quote
+ (when groups `("-G" ,(join-str "," (mapcar #'sh-quote
groups))))
(when shell `("-s" ,(sh-quote shell)))
(when uid `("-u" ,(sh-quote uid)))
@@ -70,6 +83,30 @@
;; VNode
+(defgeneric vnode-owner (res))
+
+(defmethod vnode-owner ((res vnode))
+ (let ((owner-spec (get-specified res :owner)))
+ (when owner-spec
+ (resource 'user owner-spec))))
+
+(defgeneric vnode-group (res))
+
+(defmethod vnode-group ((res vnode))
+ (let ((group-spec (get-specified res :group)))
+ (when group-spec
+ (resource 'user group-spec))))
+
+(defgeneric sync-owner-and-group (res))
+
+(defmethod sync-owner-and-group ((res vnode))
+ (let ((owner (vnode-owner res))
+ (group (vnode-group res)))
+ (when group
+ (sync group))
+ (when owner
+ (sync owner))))
+
(defmethod op-chown ((res vnode) (os os-unix) &key uid gid owner group
&allow-other-keys)
(when (stringp owner)
@@ -80,10 +117,10 @@
(assert (= uid (get-probed owner :uid))))
(when (and gid group)
(assert (= gid (get-probed group :gid))))
- (when owner
- (sync owner))
(when group
(sync group))
+ (when owner
+ (sync owner))
(let ((u (or (when owner (resource-id owner))
uid))
(g (or (when group (resource-id group))
@@ -96,12 +133,32 @@
(defmethod op-chmod ((res vnode) (os os-unix) &key mode
&allow-other-keys)
+ (sync-owner-and-group res)
(run "chmod " (octal (mode-permissions mode)) " "
(sh-quote (resource-id res))))
;; File
+(defun path-parent-directory (&rest path-parts)
+ (let* ((path (the string (str path-parts)))
+ (sep (position #\/ path
+ :from-end t
+ :end (1- (length path))
+ :test #'char=)))
+ (if sep
+ (subseq path 0 sep)
+ "/")))
+
+(defgeneric parent-directory (x))
+
+(defmethod parent-directory ((res vnode))
+ (let* ((path (resource-id res))
+ (parent-path (path-parent-directory path)))
+ (resource 'directory parent-path)))
+
(defmethod op-file-ensure ((res file) (os os-unix) &key ensure)
+ (sync-owner-and-group res)
+ (sync (parent-directory res))
(let* ((id (resource-id res))
(sh-id (sh-quote id)))
(ecase ensure
@@ -110,14 +167,42 @@
((nil)))))
(defmethod op-file-content ((res file) (os os-unix) &key content)
+ (sync-owner-and-group res)
+ (sync (parent-directory res))
(let ((id (resource-id res)))
- (run "echo -n " (sh-quote content) " > " (sh-quote id))
+ (run (echo_ content) " > " (sh-quote id))
+ (when-let (after (get-specified res :after))
+ (funcall (the function after) res os))
(clear-probed res)))
+;; Symlink
+
+(defmethod op-symlink-ensure ((res symlink) (os os-unix)
+ &key ensure)
+ (sync-owner-and-group res)
+ (sync (parent-directory res))
+ (let* ((id (resource-id res))
+ (sh-id (sh-quote id))
+ (target (get-specified res :target))
+ (sh-target (sh-quote target)))
+ (ecase ensure
+ ((:absent) (run "rm " sh-id))
+ ((:present) (run "ln -s " sh-target " " sh-id))
+ ((nil)))))
+
+(defmethod op-symlink-target ((res symlink) (os os-unix)
+ &key target)
+ (let* ((id (resource-id res))
+ (sh-id (sh-quote id))
+ (sh-target (sh-quote target)))
+ (run "ln -sf " sh-target " " sh-id)))
+
;; Directory
(defmethod op-directory-ensure ((res directory) (os os-unix)
&key ensure)
+ (sync-owner-and-group res)
+ (sync (parent-directory res))
(let* ((id (resource-id res))
(sh-id (sh-quote id)))
(ecase ensure
diff --git a/unix/probes.lisp b/unix/probes.lisp
index bf30d72..4c62883 100644
--- a/unix/probes.lisp
+++ b/unix/probes.lisp
@@ -1,26 +1,11 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
;; Group
-(defmethod probe-group-in-/etc/group ((group group) (os os-unix))
+(defmethod probe-group ((group group) (os os-unix))
(let ((id (resource-id group))
(ensure :absent))
(multiple-value-bind #1=(name passwd gid members)
@@ -32,7 +17,7 @@
;; User
-(defmethod probe-user-in-/etc/passwd ((user user) (os os-unix))
+(defmethod probe-user ((user user) (os os-unix))
(let ((id (resource-id user))
(ensure :absent))
(multiple-value-bind #1=(login pass uid gid realname home shell)
@@ -46,7 +31,7 @@
(return (values* #1#))))
(properties* (ensure . #1#)))))
-(defmethod probe-user-groups-in-/etc/group ((user user) (os os-unix))
+(defmethod probe-user-groups ((user user) (os os-unix))
(let ((id (resource-id user))
groups)
(unless (eq :absent (get-probed user :ensure))
@@ -76,10 +61,10 @@
(defmethod probe-vnode-using-ls ((vnode vnode) (os os-unix))
(let ((id (resource-id vnode))
(ensure :absent))
- (multiple-value-bind #1=(mode links owner group size mtime)
+ (multiple-value-bind #1=(mode links owner group size mtime target)
(with-ls<1>-lT #.(cons 'name '#1#)
- (ls "-ldT" (sh-quote id))
- (when (string= id name)
+ (ls "-ldT" id)
+ (when (string= id (the string name))
(setq mode (mode (mode-permissions mode))
owner (resource 'user owner)
group (resource 'group group)
@@ -144,6 +129,14 @@
:file-too-large))))
(properties* content)))
+;; Symlink
+
+(defmethod probe-symlink-target ((symlink symlink) (os os-unix))
+ (let ((target (string-trim '(#\Newline)
+ (run-1 "readlink "
+ (sh-quote (resource-id symlink))))))
+ (properties* target)))
+
;; Directory
(defmethod probe-directory-content ((dir directory) (os os-unix))
diff --git a/unix/ssh.lisp b/unix/ssh.lisp
index f6c3c0a..0dda1af 100644
--- a/unix/ssh.lisp
+++ b/unix/ssh.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
diff --git a/unix/stat.lisp b/unix/stat.lisp
index 703ffea..28ec881 100644
--- a/unix/stat.lisp
+++ b/unix/stat.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -144,4 +129,7 @@
(defmethod match-specified-value ((resource vnode) (property (eql :mode))
specified probed os)
- (= (mode-fixnum specified) (mode-fixnum probed)))
+ (or (eq specified probed)
+ (and specified
+ probed
+ (= (mode-fixnum specified) (mode-fixnum probed)))))
diff --git a/unix/syntaxes.lisp b/unix/syntaxes.lisp
index 0e438ce..74b54aa 100644
--- a/unix/syntaxes.lisp
+++ b/unix/syntaxes.lisp
@@ -1,20 +1,5 @@
-;;
-;; adams - system administrator written in Common Lisp
-;;
-;; Copyright 2013,2014,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
+;; Adams - UNIX system administration tool written in Common Lisp
+;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
(in-package :adams)
@@ -41,10 +26,11 @@
group
(#'sh-parse-integer size)
(#'chronicity:parse time)
- name)
- #~|^([-a-zA-Z]{10})\s+([0-9]+)\s+(\S+)\s+(\S+)\s+([0-9]+)\s+(\S+\s+\S+ \S+ \S+)\s+(.+)$|
+ name
+ target)
+ #~|^([-a-zA-Z]{10})\s+([0-9]+)\s+(\S+)\s+(\S+)\s+([0-9]+)\s+(\S+\s+\S+ \S+ \S+)\s+(.+?)(?: -> (.*))?$|
"Syntax for `ls -lT` output. See ls(1)."
- (values name mode links owner group size time))
+ (values name mode links owner group size time target))
(define-syntax stat<1>-r ((#'sh-parse-integer
dev ino mode links uid gid rdev size)