case "$MODE" in
    commandline)
        # add a commandline switch to ltsp-build-client (advanced "false" means 
        # we dont expect any value, callig --kiosk is enough, we could enhance
        # the plugin to use --kiosk kde for example to install kdm and konqueror
        # instead if we'd set it to true
        add_option "mythbuntu" "`eval_gettext "create a Mythbuntu fat client."`" "advanced" "false"
        add_option "mythbuntu-user-credentials" "`eval_gettext "Mythbuntu: specify login credentials as username:password"`" "advanced" "true"
    ;;
    
    configure)
        
if [ -n "$option_mythbuntu_value" ]; then
    # set an environment variable we can pick up later
    MYTHTV="True"
    if [ -n "$option_mythbuntu_user_credentials_value" ]; then
        MBCRED="$option_mythbuntu_user_credentials_value"
    fi
    if [ ! -n "$MBCRED" ]; then
        echo "You must specify --mythbuntu-user-credentials!"
        exit 100
    fi
fi
	
	
    if [ -n "$MYTHTV" ]; then
        # stuff from 000-basic-configuration
        # FIXME: not sure if this should be in here
        # maybe we should just filter the Ubuntu defaults
        # (eg similar to how the init scripts are filtered)
        COMPONENTS="main restricted universe multiverse"
        EARLY_PACKAGES="mythbuntu-diskless-client"
        # we don't need some stuff in ltsp-client-setup
        # those items are disabled in /etc/lts.conf (see below)
        RCS_WHITELIST=""
        RC2_WHITELIST=""
        RC6_WHITELIST=""
        RC0_WHITELIST=""
        OVERRIDE_EXPORTS="true"
        export DEBIAN_PRIORITY=critical
    fi 
	
	
	;;
    
    after-install)
        if [ -n "$MYTHTV" ]; then
            # install our mythbuntu stuff
            LC_ALL=C chroot $ROOT apt-get $APT_GET_OPTS install mythbuntu-desktop mythtv-frontend mythplugins xfce4-terminal mythbuntu-common
            # create directory
            mkdir -p $ROOT/etc/defaults/
            
            # create a frontend user with sudo privileges
            MBUSER=`echo $MBCRED | cut -d : -f 1`
            MBSECRET=`echo $MBCRED | cut -d : -f 2`

            LC_ALL=C chroot $ROOT adduser --disabled-password --gecos ,,, $MBUSER
            LC_ALL=C chroot $ROOT usermod -a -G adm,admin,audio,operator,video,mythtv $MBUSER
        
            # set password
            echo ${MBUSER}:${MBSECRET} |  LC_ALL=C chroot $ROOT chpasswd
           
            # make sudo behave
            chmod u+w ${ROOT}/etc/sudoers
            echo "# Members of the admin group may gain root privileges" >> $ROOT/etc/sudoers
            echo "%admin ALL=(ALL) ALL" >> $ROOT/etc/sudoers
            chmod u-w $ROOT/etc/sudoers

            # add mysql.txt
            mkdir -p $ROOT/etc/mythtv/
            if [ -e /etc/mythtv/mysql.txt ]; then 
                cp /etc/mythtv/mysql.txt $ROOT/etc/mythtv/mysql.txt
            else
                echo "WARNING: /etc/mythtv/mysql.txt not found!"
            fi

        fi
    ;;

    finalization)
        if [ -n "$MYTHTV" ]; then
            # create lts.conf
            cat <<EOF >> $ROOT/etc/lts.conf
[default]
SOUND=false
LOCALDEV=false
SYSLOG=local
CONFIGURE_FSTAB=false
EOF

        cat <<EOF >> $ROOT/etc/default/NetworkManager
# mythbuntu-diskless does not need network-manager. it breaks the connectin
# used to boot the client which is a very bad thing
exit 0
EOF

        cat <<EOF > $ROOT/etc/fstab
/dev/root   /       aufs    defaults                0   0
proc        /proc   proc    defaults                0   0
tmpfs       /tmp    tmpfs   defaults,nosuid,nodev   0   0
EOF

        blacklist_rc() {
            for i in "$@"; do
                # first remove all sym links, then add K links back
                chroot $ROOT update-rc.d -f $i remove || true
                if [ -f ${ROOT}/etc/init.d/${i} ]; then
                    for runlevel in 0 1 2 3 4 5 6 S; do
                        chroot $ROOT ln -sf /etc/init.d/${i} /etc/rc${runlevel}.d/K80${i} || true
                    done
                fi
            done
        }

        # do not start ltsp-client-core
        blacklist_rc ltsp-client-core apparmor nbd-client

    fi
    ;;
esac

