home · contact · privacy
Improve plomlombot-irc setup.
[config] / all_new_2018 / 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/all_new_2018/apt-mark/"
8
9 dpkg-query -Wf '${Package} ${Priority}\n' | grep ' required' | sed 's/ required//' > /tmp/list_white_unsorted
10 for target in "$@"; do
11     path="${config_tree_prefix}${target}"
12     cat "${path}" | while read line; do
13         if [ ! $(echo "${line}" | cut -c1) = "#" ]; then
14             echo "${line}" >> /tmp/list_white_unsorted
15         fi
16     done
17 done
18 sort /tmp/list_white_unsorted > /tmp/list_white
19 dpkg-query -Wf '${Package}\n' > /tmp/list_all_packages
20 sort /tmp/list_all_packages > /tmp/foo
21 mv /tmp/foo /tmp/list_all_packages
22 comm -3 /tmp/list_all_packages /tmp/list_white > /tmp/list_black
23 apt-mark auto `cat /tmp/list_black`
24 DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove
25 rm /tmp/list_all_packages /tmp/list_white_unsorted /tmp/list_white /tmp/list_black