Hash :
b0ab5bb5
Author :
Thomas de Grivel
Date :
2022-12-04T18:50:53
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
;; cl-unix-cybernetics
;; Copyright 2013-2022 Thomas de Grivel <thodg@kmx.io>
;;
;; Permission is hereby granted to use this software granted
;; the above copyright notice and this permission paragraph
;; are included in all copies and substantial portions of this
;; software.
;;
;; THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
;; PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
;; AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
;; THIS SOFTWARE.
(in-package :cl-unix-cybernetics)
;; Group
(define-resource-class group () ()
((probe-group :properties (:ensure :name :passwd :gid :members)))
((op-update-group :properties (:ensure :gid))))
(defgeneric probe-group (resource os))
(defgeneric op-update-group (resource os &key ensure gid))
;; User
(define-resource-class user (resource-container)
()
((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))))
(defgeneric probe-user-in-/etc/passwd (resource os))
(defgeneric probe-user-groups-in-/etc/group (resource os))
(defgeneric op-update-user (resource os &key ensure uid gid realname home shell
login-class
groups))
(defmethod resource-before-p ((r1 group) (r2 user))
t)
;; Filesystem virtual node
(define-resource-class vnode ()
()
((probe-vnode-using-ls :properties (:ensure :group :links :mode :mtime
:owner :size))
(probe-vnode-using-stat :properties (:atime :blocks :blksize :ctime
:dev :ensure :flags :gid
:ino :links :mode :mtime
:rdev :size :uid)))
((op-chmod :properties (:mode))
(op-chown :properties (:uid :gid :owner :group))))
(defgeneric probe-vnode-using-ls (resource os))
(defgeneric probe-vnode-using-stat (resource os))
(defgeneric op-chmod (resource os &key mode &allow-other-keys))
(defgeneric op-chown (resource os &key uid gid owner group &allow-other-keys))
;; File
(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar *cksum-legacy-algorithms*
'(:cksum))
(defvar *cksum-algorithms*
`(:md5 :rmd160 :sha1 :sha224 :sha256 :sha384 :sha512
,@*cksum-legacy-algorithms*)))
(defvar *probe-file-content-size-limit* (* 1024 1024))
(define-resource-class file (vnode)
()
((probe-file-content :properties (:content))
. #.(let ((algorithms))
(dolist (algorithm *cksum-algorithms*)
(push `(,(sym 'probe-file-cksum- algorithm)
:properties (,algorithm))
algorithms))
(nreverse algorithms)))
((op-file-ensure :properties (:ensure))
(op-file-content :properties (:content)))
((:op-properties (:content :ensure :mode :uid :gid :owner :group))))
(defgeneric probe-file-content (resource os))
(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)
()
((probe-directory-content :properties (:content)))
((op-directory-ensure :properties (:ensure)))
((:op-properties (:ensure :mode :uid :gid :owner :group))))
(defgeneric probe-directory-content (resource os))
(defgeneric op-directory-ensure (resource os &key ensure))
;; Mounted filesystems
(define-resource-class mount ()
()
((probe-mount :properties (:mounted-device
:mounted-mount-point
:mounted-fstype
:mounted-options))
(probe-fstab :properties (:fstab-device
:fstab-mount-point
:fstab-fstype
:fstab-options
:fstab-freq
:fstab-passno))))
(defgeneric probe-mount (resource os))
(defgeneric probe-fstab (resource os))
;; Process
(define-resource-class process ()
()
((probe-ps-auxww :properties (:user :pid :cpu :mem :vsz :rss :tt :state
:start :time :cmd))))
(defmethod probe-ps-auxww (process os))
;; Software package
(define-resource-class pkg)
(defgeneric probe-installed-packages (host os))