#!/bin/sh
###########################################################################
# Tries to guess some defaults for ltsp-build-client.conf.
#
# Copyright (C) 2010 Alkis Georgopoulos <alkisg@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# On Debian GNU/Linux systems, the complete text of the GNU General
# Public License can be found in `/usr/share/common-licenses/GPL'.
###########################################################################

# Source the sch-scripts common functions and variables.
if [ ! -f ./scripts/common/common.sh ]; then
    cd /usr/share/sch-scripts
fi
. ./scripts/common/common.sh

if [ -f /etc/ltsp/ltsp-build-client.conf ]; then
    . /etc/ltsp/ltsp-build-client.conf || die "Συντακτικό σφάλμα στο αρχείο /etc/ltsp/ltsp-build-client.conf."
fi

ARCH=${ARCH:-$(dpkg --print-architecture)}
echo "Arch=$ARCH"

# Has the user selected thin or fat clients?
if [ -z "$FAT_CLIENT_DESKTOPS" ]; then
    echo "Type=thin"
else
    echo "Type=fat"
fi

# Guess what desktop environments the user wants in the chroot.
for desktop in ubuntu-desktop edubuntu-desktop xubuntu-desktop \
    kubuntu-desktop lubuntu-desktop; do
    result=False
    if [ -n "$FAT_CLIENT_DESKTOPS" ]; then
        for d in $FAT_CLIENT_DESKTOPS; do
            if [ $d = $desktop ]; then
                result=True
                break
            fi
        done
    elif [ -n "$(dpkg-query -W -f '${Version}' $desktop 2>/dev/null)" ]; then
        result=True
    fi
    echo "$desktop=$result"
done

# Check the package lists that the user wants.
for list in /etc/sch-scripts/koina.list /etc/sch-scripts/dimotiko.list \
    /etc/sch-scripts/gymnasio.list /etc/sch-scripts/lykeio.list; do
    result=False
    if [ -n "$PACKAGE_LISTS" ]; then
        for l in $PACKAGE_LISTS; do
            if [ $l = $list ]; then
                result=True
                break
            fi
        done
    else
        packagename=${list%.*}
        packagename=${packagename##*/}
        if [ $packagename = koina ] || [ -n "$(dpkg-query -W -f '${Version}' $packagename 2>/dev/null)" ]; then
            result=True
        fi
    fi
    echo "$list=$result"
done
