#!/bin/sh

list=""
db=/var/lib/apt/delayed.txt

if test "$1" != ""; then
	apt-get install $* || {
		shift
		read -p "Soll '$*' vorgemerkt werden [j/n]? " p
		if test "$p" = "j"; then
			echo $* >> $db
		fi
		exit
	}
fi

test -f $db.run && exit
touch $db.run

trap "rm -f $db.run; exit" 0 1 2 5 15

for pkg in `cat $db`; do
	read -p "Installation von $pkg [j/n]? " p
	if test "$p" = "j"; then
		list="$list $pkg"
	fi
done

if test "$list" != ""; then
	echo "Installiere $list..."
	apt-get install $list && {
		for pkg in $list; do
			grep -v $pkg $db > $db.tmp && mv $db.tmp $db
		done
	}
fi

rm -f $db.run

