#!/bin/sh
#
# Install selected tasks.

set -e

pkglibdir=/usr/lib/debian-edu-install

. $pkglibdir/debian-edu-common

load_config

task_install() {
    task="$1"

    print "info: Installing '$task' using noninteractive frontend."
    export DEBIAN_FRONTEND=noninteractive
    tasksel install $task || error "failed to install $task"
}

pkg_exists() {
    pkg="$1"
    if apt-cache show "$pkg" 2>/dev/null | grep -q "Package: $pkg" ; then
	:
    else
	false
    fi
}

if pkg_exists education-common ; then
    print "info: Package education-common found.  Continuing."
    :
else
    print "info: Missing package education-common.  Jumping back."
    jump_to 125 debian-edu-insert-cd # Jump back and ask for the CD
fi

# Make sure the tasksel tasks are available before calling tasksel to
# install them.
apt-get -y install education-tasks

print "info: Got profile '$PROFILE'"
for value in `echo $PROFILE |sed 's/ /-/g' | sed 's/,-/ /g'`; do
    print "info: Testing profile '$value'"
    case $value in
	Standalone)
	    task_install education-standalone
	    ;;
	Workstation)
	    task_install education-workstation
	    ;;
	Thin-Client-Server|LTSP-server)
	    task_install education-thin-client-server
	    ;;
	Main-Server|Server)
	    task_install education-main-server
	    ;;
	XTerminal)
	    ;;
	*)
	    error "unknown profile '$value'"
	    ;;
    esac
done

# If pcmcia is working, this is a laptop, and we should install the laptop
# task. (Bug #551)
if [ -e /proc/bus/pccard/drivers -a -z "$LESSDISKS_START_STOP_DAEMON" ]; then
    task_install education-laptop
fi

exit 0
