#!/bin/bash

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

CHRDIR=/chroot

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

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

function update_head
{
    echo "-------------------------------------------------------------------------------"
    echo "*** TEST upgrade $1..."
    echo "-------------------------------------------------------------------------------"
}

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

# do it in /
update_head "root system"
[ -d $PARTIAL ] || mkdir $PARTIAL
apt-get upgrade -s

for CHR in $CHROOTS; do

    if [ -d $CHRDIR/$CHR/etc/apt ]; then
	    update_head "$CHR chroot"
	    [ -d $CHRDIR/$CHR$PARTIAL ] || mkdir $CHRDIR/$CHR$PARTIAL
	    chroot $CHRDIR/$CHR apt-get upgrade -s
    fi

done

echo "Finished."
