home · contact · privacy
Add some missing stuff.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 12 Aug 2024 16:31:58 +0000 (18:31 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 12 Aug 2024 16:31:58 +0000 (18:31 +0200)
testing/setup_scripts/misc.sh
testing/setup_scripts/purge_nonrequireds.sh [new file with mode: 0755]

index 64a891642d201f75ad1b630e5e30d5f319223362..f6d2367af7c3f50972b1d7161aabd177fd1d09c2 100644 (file)
@@ -14,7 +14,7 @@ expect_n_args() {
     explainer="$2"
     shift 2
     if [ "$#" -lt "${min_args}" ]; then
-        echo "Need at least ${1} arguments … ${explainer}"
+        echo "Need at least ${min_args} arguments … ${explainer}"
         false
     fi
 }
diff --git a/testing/setup_scripts/purge_nonrequireds.sh b/testing/setup_scripts/purge_nonrequireds.sh
new file mode 100755 (executable)
index 0000000..48065fc
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+# This script removes all Debian packages that are not of Priority
+# "required" or not depended on by packages of priority "required"
+# or not listed in the argument-selected files of apt-mark/.
+set -e
+. ./misc.sh
+
+# FIXME packages listed twice in the aptmark_dir get blacklisted?
+
+dpkg-query -Wf '${Package} ${Priority}\n' | grep ' required' | sed 's/ required//' > /tmp/list_white_unsorted
+for target in "$@"; do
+    path="${aptmark_dir}/${target}"
+    cat "${path}" | while read line; do
+        if [ ! $(echo "${line}" | cut -c1) = "#" ]; then
+            echo "${line}" >> /tmp/list_white_unsorted
+        fi
+    done
+done
+sort /tmp/list_white_unsorted > /tmp/list_white
+dpkg-query -Wf '${Package}\n' > /tmp/list_all_packages
+sort /tmp/list_all_packages > /tmp/foo
+mv /tmp/foo /tmp/list_all_packages
+comm -3 /tmp/list_all_packages /tmp/list_white > /tmp/list_black
+apt-mark auto `cat /tmp/list_black`
+DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove
+rm /tmp/list_all_packages /tmp/list_white_unsorted /tmp/list_white /tmp/list_black
+
+# Somehow, auto-mounts get undone by all of this, so re-mount /etc/fstab.
+# TODO: Find out why.
+mount -a