#!/bin/sh
#
# Handle the fact that the debian-edu-install/profile value is
# multiselect.
#
# Mapping:
#   Main-Server                             	   => Main-Server
#   Main-Server + Workstation               	   => Main-Server+Workstation
#   Main-Server + Thin-Client-Server        	   => Main-Server+Thin-Client-Server
#   Main-Server + Workstation + Thin-Client-Server => Main-Server+Thin-Client-Server
#   Workstation                        => Workstation
#   Thin-Client-Server                 => Workstation+Thin-Client-Server
#   Workstation + Thin-Client-Server   => Workstation+Thin-Client-Server
#   Standalone                         => Standalone
#   Barebone                           => Barebone

. /usr/share/debconf/confmodule

log() {
    logger -t 20debian-edu "$@"
}

error() {
    log "error: $@"
}

info() {
    log "info: $@"
}

get_table() {
    PROFILE="$1"
    info "Got profile '$PROFILE'"
    for value in `echo $PROFILE |sed 's/ /-/g' | sed 's/,-/ /g'`; do
	info "Testing profile '$value'"
	case $value in
            Main-Server|Server)                 got_serv=s ;;
            Thin-Client-Server|LTSP-server)     got_ltsp=l ;;
            Workstation)                        got_work=w ;;
            Standalone)                         got_stan=a ;;
            Barebone)                           got_bare=b ;;
            *)
	        error "unknown profile '$profile'"
	    ;;
        esac
    done

    case "$got_serv$got_ltsp$got_work$got_stan$got_bare" in
	s)   echo /etc/autopartkit/Main-Server.table
	;;
	sw)  echo /etc/autopartkit/Main-Server+Workstation.table
	;;
	sl)  echo /etc/autopartkit/Main-Server+Thin-Client-Server.table
	;;
	slw) echo /etc/autopartkit/Main-Server+Thin-Client-Server.table
	;;
	w)   echo /etc/autopartkit/Workstation.table
	;;
	l)   echo /etc/autopartkit/Workstation+Thin-Client-Server.table
	;;
	lw)  echo /etc/autopartkit/Workstation+Thin-Client-Server.table
	;;
        a)   echo /etc/autopartkit/Standalone.table
        ;;
        b)   echo /etc/autopartkit/Barebone.table
	;;
	esac
}

db_get "debian-edu-install/profile"

TABLE=`get_table "$RET"`

db_set autopartkit/partition_table "$TABLE"

exit 0
