home · contact · privacy
135196bfd771be13e8377b9e3bb7a360c646e68e
[config] / bookworm / setup_scripts / purge_nonrequireds.sh
1 #!/bin/sh
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/.
5 set -e
6
7 config_tree_prefix="${HOME}/config/bullseye"
8 aptmark_dir="${config_tree_prefix}/apt-mark"
9
10 dpkg-query -Wf '${Package} ${Priority}\n' | grep ' required' | sed 's/ required//' > /tmp/list_white_unsorted
11 for target in "$@"; do
12     path="${aptmark_dir}/${target}"
13     cat "${path}" | while read line; do
14         if [ ! $(echo "${line}" | cut -c1) = "#" ]; then
15             echo "${line}" >> /tmp/list_white_unsorted
16         fi
17     done
18 done
19 sort /tmp/list_white_unsorted > /tmp/list_white
20 dpkg-query -Wf '${Package}\n' > /tmp/list_all_packages
21 sort /tmp/list_all_packages > /tmp/foo
22 mv /tmp/foo /tmp/list_all_packages
23 comm -3 /tmp/list_all_packages /tmp/list_white > /tmp/list_black
24 apt-mark auto `cat /tmp/list_black`
25 DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove
26 rm /tmp/list_all_packages /tmp/list_white_unsorted /tmp/list_white /tmp/list_black
27
28 # Somehow, auto-mounts get undone by all of this, so re-mount /etc/fstab.
29 # TODO: Find out why.
30 mount -a