Commit 010e418ca5180927290445dc821018fa136ea735

Thomas de Grivel 2023-01-25T23:34:31

shpkg uninstall

diff --git a/bin/shpkg b/bin/shpkg
index a7d7619..94be2aa 100755
--- a/bin/shpkg
+++ b/bin/shpkg
@@ -53,6 +53,10 @@ elif [ "x$1" = "xremove" ] ||
     verbose shpkg_uninstall "$@"
     verbose shpkg_remove "$@"
     exit
+elif [ "x$1" = "xuninstall" ]; then
+    shift
+    verbose shpkg_uninstall "$@"
+    exit
 elif [ "x$1" = "xupdate" ]; then
     verbose shpkg_update
     exit
diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index eee441c..093a87e 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -349,7 +349,21 @@ shpkg_install_dependencies () {
 # TODO: remove metadata about installed packages
 shpkg_uninstall () {
     for REPO; do
-        :
+        SHPKG_REPO_DIR="$(shpkg_dir "${REPO}")"
+	SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"
+        if [ -f "${SHPKG_REPO_INSTALLED}" ]; then
+            verbose cd "${SHPKG_DIR}"
+            grep -v : "${SHPKG_REPO_INSTALLED}" |
+                cut -d '(' -f 2 |
+                cut -d ')' -f 1 |
+                while read F; do
+                    if grep -E "^SHA256 \\($F\\) = " "${SHPKG_REPO_INSTALLED}" |
+                            "${SHPKG_SHA256}" -c; then
+                        verbose rm "$F"
+                    fi
+                done
+            verbose rm "${SHPKG_REPO_INSTALLED}"
+        fi
     done
 }