#!	/bin/sh
# Please make sure this file can be executed by both "bash" and "ash".

readonly ADMINDIR=/var/lib/dpkg
readonly LIBDIR=/root
readonly tmpfile=/var/tmp/pkgseltmp-$$

# Build profiles menu
echo -n "result=\$(whiptail --clear --backtitle \"Debian Installation\" \
 --title \"Please Select Profile\" --menu \
 \"Please select the kind of installation you want:\" 0 0 0 " >$tmpfile
for i in $LIBDIR/profiles/* ; do
 name=$(basename $i); descr=$(head -1 $i)
 echo -n "\"$name\" \"$descr\" " >>$tmpfile
done
echo -n "\"Custom\" \"Select the tasks you will perform with this system.\" " \
 >>$tmpfile
echo -n "2>&1 1>/dev/tty)" >>$tmpfile

. $tmpfile
rm -f $tmpfile

if [ -z $result ]; then
 exit 1
fi

if [ "$result" != "Custom" ]; then
 tail +2 $LIBDIR/profiles/$result |dpkg --set-selections --admindir=$ADMINDIR
 exit 0
fi

# Build tasks menu
echo -n "result=\$(whiptail --clear --backtitle \"Debian Installation\" \
 --title \"Please Select Software Categories\" --checklist \
 \"Please select the tasks you will perform with this system:\n
Note: the following selections install only a minimal subset of 
the hundreds of packages in the Debian distribution. You may 
select others later using 'dselect'. \" 0 76 0 " >$tmpfile
for i in $LIBDIR/tasks/* ; do
 name=$(basename $i); descr=$(head -1 $i)
 echo -n " \"$name\" \"$descr\" off " >>$tmpfile
done
echo -n "2>&1 1>/dev/tty)" >>$tmpfile

. $tmpfile
rm -f $tmpfile

for i in $result; do
 # Strip quotes.
 a=$(eval echo $i)
 tail +2 $LIBDIR/tasks/$a |dpkg --set-selections --admindir=$ADMINDIR
done
