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 "kiosk" "`eval_gettext "a simple webkiosk mode."`" "advanced" "false"
        ;;
    configure)
        if [ -n "$option_kiosk_value" ]; then
            # set an environment variable we can pick up later
            KIOSK="True"

            # install the webbrowser and a display manager that 
            # is capable to do a timed autologin in the client environment
            KIOSK_BROWSER=${KIOSK_BROWSER:-"iceweasel"}
            KIOSK_DM=${KIOSK_DM:-"gdm"}
            KIOSK_WM=${KIOSK_WM:-"metacity"}
            KIOSK_PACKAGES=${KIOSK_PACKAGES:-"$KIOSK_BROWSER $KIOSK_DM $KIOSK_WM"}
            # do not install recommended packages
            APT_GET_OPTS="$APT_GET_OPTS -o APT::Install-Recommends=false"

            EARLY_PACKAGES="$EARLY_PACKAGES $KIOSK_PACKAGES"

            # add the display manager to the whitelist
            if [ -n "$KIOSK_DM" ]; then
                if [ -n "$RCS_WHITELIST" ]; then
                    RCS_WHITELIST="$RCS_WHITELIST $KIOSK_DM"
                fi
                if [ -n "$RC2_WHITELIST" ]; then
                    RC2_WHITELIST="$RC2_WHITELIST $KIOSK_DM"
                fi
                if [ -n "$RC6_WHITELIST" ]; then
                    RC6_WHITELIST="$RC6_WHITELIST $KIOSK_DM"
                fi
                if [ -n "$RC0_WHITELIST" ]; then
                    RC0_WHITELIST="$RC0_WHITELIST $KIOSK_DM"
                fi
            fi
        fi
        ;;
    after-install)
        if [ "True" = "$KIOSK" ]; then
            # make the necessary directories writeable to the booted client
            echo 'copy_dirs="$copy_dirs /home"' >> $ROOT/etc/default/ltsp-client-setup
            echo 'rw_dirs="$rw_dirs /var/lib/gdm"' >> $ROOT/etc/default/ltsp-client-setup

            # create a kiosk user
            chroot $ROOT adduser --disabled-password --gecos ,,, kiosk

            # create a default xsession for that user
            echo "#!/bin/sh" > $ROOT/home/kiosk/.xsession
            # including sound
            #echo "pulseaudio -L module-detect -L module-rescue-streams -L module-native-protocol-unix -L module-volume-restore -n &" >> $ROOT/home/kiosk/.xsession
            # make sure we have a wm
            echo "$KIOSK_WM &" >> $ROOT/home/kiosk/.xsession
            echo "/usr/bin/$KIOSK_BROWSER --fullscreen" >> $ROOT/home/kiosk/.xsession

            # switch to the proper theme 
            #echo "include \"/usr/share/themes/Human/gtk-2.0/gtkrc\"" >$ROOT/home/kiosk/.gtkrc-2.0

            if [ "$KIOSK_DM" = "gdm" ]; then
                # create a custom configuration for gdm with autologin
                gdm_conf=$ROOT/etc/gdm/gdm.conf

                if ! egrep -q '^\[daemon]' $gdm_conf ; then
                    echo '[daemon]' >> $gdm_conf
                fi

                GDM_KIOSK_OPTS=${GDM_KIOSK_OPTS:-"AutomaticLoginEnable=true AutomaticLogin=kiosk TimedLoginEnable=true TimedLogin=kiosk TimedLoginDelay=5"}
                for line in $GDM_KIOSK_OPTS ; do
                    opt="$(echo $line | cut -d = -f 1)"
                    val="$(echo $line | cut -d = -f 2)"
                    if ! egrep -q ^"$opt"= $gdm_conf ; then
                        sed -i -e "s,\[daemon\],[daemon]\n$opt=,g" $gdm_conf
                    fi
                    sed -i -e "s,$opt=.*,$line,g" $gdm_conf
                done
            fi
        fi
        ;;
esac

