#!/bin/bash

#########################################

CHRDIR=/chroot

PACKAGES="rsyslog dbus sysklogd"

#########################################

PARTIAL=/var/cache/apt/archives/partial

function update_head
{
    echo "-------------------------------------------------------------------------------"
    echo "*** Removing unneccessary packages from $1..."
    echo "-------------------------------------------------------------------------------"
}

# gather from all the chroots
if [ -d $CHRDIR ]; then
    CHROOTS=`ls $CHRDIR`
fi

for CHR in $CHROOTS; do

    if [ -d $CHRDIR/$CHR/etc/apt ]; then
	    update_head "$CHR chroot"
	    [ -d $CHRDIR/$CHR$PARTIAL ] || mkdir $CHRDIR/$CHR$PARTIAL
	    for PKG in $PACKAGES; do
		echo "*** $PKG:"
		chroot $CHRDIR/$CHR apt-get remove --purge $PKG
	    done
    fi

done

echo "Finished."
