Avoid file-rc being considered for removal by deborphan
[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 if ! [ -x $target/usr/bin/deborphan ] ; then
13   echo "Warning: deborphan not installed"
14   exit 0
15 fi
16
17 # avoid file-rc being considered for removal by deborphan
18 if [ -d $target/usr/share/file-rc -a -x $target/usr/bin/deborphan ] ; then
19   echo "Adding file-rc to keep-list of deborphan to avoid accidental removal"
20   $ROOTCMD deborphan --add-keep file-rc || /bin/true
21 fi
22
23 # remove all packages not necessary anymore:
24 $ROOTCMD apt-get -y --purge autoremove
25
26 # remove packages until deborphan does not find anymore:
27 while [ "$($ROOTCMD deborphan)" != "" ] ; do
28   $ROOTCMD apt-get -y --purge remove $($ROOTCMD deborphan)
29 done
30
31 # make sure we don't have any removed but not-yet-purged packages left,
32 # otherwise GRMLBASE/03-get-sources might try to download unavailable
33 # packages and will fail doing so
34 PURGE_PACKAGES=$($ROOTCMD dpkg --list | awk '/^rc/ {print $2}')
35
36 if [ -n "$PURGE_PACKAGES" ] ; then
37   $ROOTCMD dpkg --purge $PURGE_PACKAGES
38 fi
39
40 ## END OF FILE #################################################################
41 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2