Merge remote-tracking branch 'origin/github/pr/148'
[grml-live.git] / etc / grml / fai / config / scripts / DEBORPHAN / 98-clean-chroot
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/config/scripts/DEBORPHAN/98-clean-chroot
3 # Purpose:       drop as many packages from grml as possible
4 # Authors:       (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 set -u
10 set -e
11
12 # remove all packages not necessary anymore:
13 echo "Executing apt-get -y --purge autoremove"
14 $ROOTCMD apt-get -y --purge autoremove
15
16 # make sure we don't have any removed but not-yet-purged packages left,
17 # otherwise GRMLBASE/03-get-sources might try to download unavailable
18 # packages and will fail doing so
19 PURGE_PACKAGES=$($ROOTCMD dpkg --list | awk '/^rc/ {print $2}')
20
21 if [ -n "$PURGE_PACKAGES" ] ; then
22   echo "Getting rid of packages which have been removed but not yet purged: $PURGE_PACKAGES"
23   $ROOTCMD dpkg --purge $PURGE_PACKAGES
24 fi
25
26 # note: deborphan is no longer available as of Debian/trixie,
27 # see https://github.com/grml/grml-live/issues/144
28 if [ -x "$target"/usr/bin/deborphan ] ; then
29   # remove packages until deborphan does not find anymore:
30   while [ "$($ROOTCMD deborphan)" != "" ] ; do
31     echo "Executing deborphan"
32     $ROOTCMD apt-get -y --purge remove $($ROOTCMD deborphan)
33   done
34 fi
35
36 ## END OF FILE #################################################################
37 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2