2 # This script removes all Debian packages that are not of Priority
3 # "required" or not depended on by packages of priority "required"
4 # or not listed in the argument-selected files of apt-mark/.
6 debian_version="bookworm"
8 config_tree_prefix="${HOME}/config/${debian_version}"
9 aptmark_dir="${config_tree_prefix}/apt-mark"
11 dpkg-query -Wf '${Package} ${Priority}\n' | grep ' required' | sed 's/ required//' > /tmp/list_white_unsorted
12 for target in "$@"; do
13 path="${aptmark_dir}/${target}"
14 cat "${path}" | while read line; do
15 if [ ! $(echo "${line}" | cut -c1) = "#" ]; then
16 echo "${line}" >> /tmp/list_white_unsorted
20 sort /tmp/list_white_unsorted > /tmp/list_white
21 dpkg-query -Wf '${Package}\n' > /tmp/list_all_packages
22 sort /tmp/list_all_packages > /tmp/foo
23 mv /tmp/foo /tmp/list_all_packages
24 comm -3 /tmp/list_all_packages /tmp/list_white > /tmp/list_black
25 apt-mark auto `cat /tmp/list_black`
26 DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove
27 rm /tmp/list_all_packages /tmp/list_white_unsorted /tmp/list_white /tmp/list_black
29 # Somehow, auto-mounts get undone by all of this, so re-mount /etc/fstab.