#!/bin/sh
#The script gets a list of all packages getting installed by the desktop task.
#It then looks into the Installed-Size field of each package using apt-cache,
#sums the size up and prints it.
#
#CAUTION: Programm uses und deletes fixed file /tmp/packetlist (possible
#symlink attack?). It propably only works with standard locale and needs
#about 10 seconds to finish in this version.
#
#used programms: apt-get, nl, grep, cut, sed, echo, bc, head, tail, apt-cache
#used packages: apt, coreutils, grep, sed, bc
#tested on Debian Sarge

PACKETLIST=/tmp/packetlist
apt-get install `tasksel --task-packages desktop` --just-print > $PACKETLIST

END=`nl $PACKETLIST | grep 'newly' | cut -c -6 | sed 's/ *//'`
END=`echo $END-1 | bc -l`
BEGIN=`nl $PACKETLIST | grep NEW | cut -c -6 | sed 's/ *//'`
BEGIN=`echo $END-$BEGIN | bc -l`

echo `head --lines=$END $PACKETLIST | tail --lines=$BEGIN` > $PACKETLIST

i=1
SIZE=0

while [ `cut -d ' ' -f $i $PACKETLIST` != "" 2>/dev/null ]
do 
  PACKETSIZE=`apt-cache show abiword-common | grep Installed-Size | cut -c 17-`
  SIZE=`echo $PACKETSIZE+$SIZE | bc -l`
  i=`echo $i+1 | bc -l`
done

rm $PACKETLIST
echo Size of task desktop is $SIZE kb
