#!/bin/bash

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

CHRDIR=/chroot

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

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

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

# do it in /
[ -d $PARTIAL ] || mkdir $PARTIAL
apt-get update >/dev/null
apt-get autoclean >/dev/null

for CHR in $CHROOTS; do

    if [ -d $CHRDIR/$CHR/etc/apt ]; then
	    [ -d $CHRDIR/$CHR$PARTIAL ] || mkdir $CHRDIR/$CHR$PARTIAL
	    chroot $CHRDIR/$CHR apt-get update >/dev/null
	    chroot $CHRDIR/$CHR apt-get autoclean >/dev/null
    fi

done
