aboutsummaryrefslogtreecommitdiff
path: root/src/property/apt.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-03-09 09:58:54 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-03-09 09:58:54 -0700
commit68235a27f4f1d9c71327e800bfa3f8579989ddde (patch)
tree3365f8d047fd0c2a44c39028cb6dd6eb4e6425b9 /src/property/apt.lisp
parent2f07b4ef28c4fc724e2fc02f8d7ea1c862c09ea2 (diff)
downloadconsfigurator-68235a27f4f1d9c71327e800bfa3f8579989ddde.tar.gz
add APT:REMOVED
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/apt.lisp')
-rw-r--r--src/property/apt.lisp48
1 files changed, 39 insertions, 9 deletions
diff --git a/src/property/apt.lisp b/src/property/apt.lisp
index 75009a6..fe5e655 100644
--- a/src/property/apt.lisp
+++ b/src/property/apt.lisp
@@ -18,12 +18,18 @@
(in-package :consfigurator.property.apt)
(named-readtables:in-readtable :interpol-syntax)
+
+;;;; Macros
+
(defmacro with-maybe-update (form)
`(handler-case ,form
(run-failed ()
(apt-get :princ "update")
,form)))
+
+;;;; Properties
+
(defprop installed :posix (&rest packages)
"Ensure all of the apt packages PACKAGES are installed."
(:desc #?"apt installed @{packages}")
@@ -31,18 +37,42 @@
(declare (ignore packages))
(os:required 'os:debianlike))
(:check
- (all-installed packages))
+ (all-installed-p packages))
(:apply
(with-maybe-update (apt-get :princ "-y" "install" packages))))
-(defun all-installed (packages)
- (loop
- with n = 0
- with lines = (runlines :env '(:LANG "C") "apt-cache" "policy" packages)
- for line in lines
- when (re:scan #?/^\s+Installed:\s+(?!\(none\))/ line)
- do (incf n)
- finally (return (= n (length packages)))))
+(defprop removed :posix (&rest packages)
+ "Ensure all of the apt packages PACKAGES are removed."
+ (:desc #?"apt removed @{packages}")
+ (:hostattrs
+ (declare (ignore packages))
+ (os:required 'os:debianlike))
+ (:check
+ (none-installed-p packages))
+ (:apply
+ (apt-get :princ "-y" "remove" packages)))
+
+
+;;;; Reports on installation status
+
+(defun apt-cache-policy (packages)
+ (runlines :env '(:LANG "C") "apt-cache" "policy" packages))
+
+(defparameter apt-cache-policy-installed #?/^\s+Installed:\s+(?!\(none\))/)
+
+(defun all-installed-p (packages)
+ (loop with n = 0
+ for line in (apt-cache-policy packages)
+ when (re:scan apt-cache-policy-installed line)
+ do (incf n)
+ finally (return (= n (length packages)))))
+
+(defun none-installed-p (packages)
+ (loop for line in (apt-cache-policy packages)
+ never (re:scan apt-cache-policy-installed line)))
+
+
+;;;; Utilities
(defun apt-get (&rest args)
(apply #'run