#!/bin/sh
#
# Install common packages before the rest

set -e

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

. $pkglibdir/debian-edu-common

load_config

pkgs_install() {
    pkgs="$*"

    print "info: Installing $pkgs using noninteractive frontend."
    export DEBIAN_FRONTEND=noninteractive
    for pkg in $pkgs ; do
        echo $pkg install | dpkg --set-selections
    done
}

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

pkgs_install education-common

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)
	    pkgs_install education-standalone
	    ;;
	Workstation)
	    pkgs_install education-workstation
	    ;;
	Thin-Client-Server|LTSP-server)
	    pkgs_install education-thin-client-server
	    ;;
	Main-Server|Server)
	    pkgs_install education-main-server
	    ;;
	Barebone)
	    pkgs_install education-networked
	    ;;
	*)
	    error "unknown profile '$profile'"
	    ;;
    esac
done

# If pcmcia is working, this is a laptop, and we should install the laptop
# task. (Bug #551)
# but dont install the laptop task if we're installing into a lessdisks-chroot
if [ -e /proc/bus/pccard/drivers -a -z "$LESSDISKS_START_STOP_DAEMON" ]; then
    pkgs_install education-laptop
fi

exit 0
