case "$MODE" in
    commandline)
        # Add a command line switch to ltsp-build-client that installs desktop
        # meta-packages so that diskless workstations can everything locally
        add_option "fat-client" "`eval_gettext "run most or all applications locally"`" "advanced" "false"
        add_option "fat-client-desktop" "`eval_gettext "run most or all applications locally"`" "advanced" "true"
    ;;

    configure)
        # Check what the sysadmin chose to install. If (s)he is lazy and didn't
        # specify one, then we install the desktop meta-packages that are
        # already installed on the server.

        if [ -n "$option_fat_client_desktop_value" ]; then
            FAT_CLIENT_DESKTOPS="$(echo $option_fat_client_desktop_value | tr ',' ' ')"
        elif [ -n "$option_fat_client_value" ]; then
            FAT_CLIENT_DESKTOPS=""

            # Code taken from 030-artwork
            for cdd in ed k l myth x; do
                if [ $(dpkg-query -W --showformat='${Package}' ${cdd}ubuntu-desktop 2>/dev/null) ]; then
                    if dpkg -l | grep -q "${cdd}ubuntu-desktop"; then
                        FAT_CLIENT_DESKTOPS="$FAT_CLIENT_DESKTOPS ${cdd}ubuntu-desktop"
                    fi
                fi
            done
        else
            # If fat client isn't enabled, just continue
            return 0
        fi

        FAT_CLIENT_DESKTOPS=${FAT_CLIENT_DESKTOPS:-ubuntu-desktop}
        ;;

    before-install)
        if [ -z "$FAT_CLIENT_DESKTOPS" ]; then
            return 0
        fi

        # Reenable recommented packages installation for fat clients
        APT_GET_OPTS=$(echo "$APT_GET_OPTS" | sed 's/--no-install-recommends//')
    ;;

    after-install)
        if [ -z "$FAT_CLIENT_DESKTOPS" ]; then
            return 0
        fi

        # Tag that the user requested a fat chroot, so that we can set
        # appropriate defaults when the clients boot
        echo FAT_CLIENT_DESKTOPS="'$(echo $FAT_CLIENT_DESKTOPS)'" >> $ROOT/etc/ltsp_fat_chroot

        # Notify the user about the different defaults
        echo "--fat-client was specified, all clients will boot as fat clients by default."
        echo "To modify this behavior, put LTSP_FATCLIENT=False in lts.conf."

        # Install the packages
        for package in ubuntu-standard $FAT_CLIENT_DESKTOPS; do
            echo "Installing $package"
            chroot $ROOT apt-get $APT_GET_OPTS install $package
        done
    ;;
esac
