DEBORPHAN/98-clean-chroot: be more verbose about executed steps
[grml-live.git] / etc / grml / fai / config / scripts / DEBORPHAN / 98-clean-chroot
index a5515f0..42ed9c2 100755 (executable)
@@ -9,13 +9,30 @@
 set -u
 set -e
 
 set -u
 set -e
 
+if ! [ -x $target/usr/bin/deborphan ] ; then
+  echo "Warning: deborphan not installed"
+  exit 0
+fi
+
 # remove all packages not necessary anymore:
 # remove all packages not necessary anymore:
+echo "Executing apt-get -y --purge autoremove"
 $ROOTCMD apt-get -y --purge autoremove
 
 # remove packages until deborphan does not find anymore:
 while [ "$($ROOTCMD deborphan)" != "" ] ; do
 $ROOTCMD apt-get -y --purge autoremove
 
 # remove packages until deborphan does not find anymore:
 while [ "$($ROOTCMD deborphan)" != "" ] ; do
-  $ROOTCMD apt-get -y --purge remove $(deborphan)
+  echo "Executing deborphan"
+  $ROOTCMD apt-get -y --purge remove $($ROOTCMD deborphan)
 done
 
 done
 
+# make sure we don't have any removed but not-yet-purged packages left,
+# otherwise GRMLBASE/03-get-sources might try to download unavailable
+# packages and will fail doing so
+PURGE_PACKAGES=$($ROOTCMD dpkg --list | awk '/^rc/ {print $2}')
+
+if [ -n "$PURGE_PACKAGES" ] ; then
+  echo "Getting rid of packages which have been removed but not yet purged: $PURGE_PACKAGES"
+  $ROOTCMD dpkg --purge $PURGE_PACKAGES
+fi
+
 ## END OF FILE #################################################################
 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2
 ## END OF FILE #################################################################
 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2