#!/bin/bash

#log everything
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/var/log/groovix/greeter-setup.log 2>&1


echo GKDEBUG starting $0 at `date`

. /usr/share/groovix/global.conf

groovix-reset-station

#populate current-display so groovix vnc and other utils know which display we're on
GDISP=`echo $DISPLAY | sed "s/://" | sed "s/\..*//"`
echo $GDISP > /var/lib/groovix/session-info/current-display

if [ "$GX_NUMLOCK_ON" = "true" ] ; then
        numlockx on
elif [ "$GX_NUMLOCK_ON" = "false" ] ; then
        numlockx off
fi


#start screensaver if desired
if [ "$GX_SCREENSAVER_RUN_DURING_LOGIN_SCREEN" = "true" ] ; then
	groovix-screensaver-root-command xscreensaver
fi

#start cmon if desired
if [ "$GX_CMON_ENABLE" = "true" ] ; then
	cmon-daemon &
fi

#start vnc remove desktop if desired
if [ "$GX_REMOTE_DESKTOP_ENABLE" = "true" ] ; then
	killall x11vnc
	pkill -f websockify

        x11vnc -xkb -auth /var/run/lightdm/root/\:$GDISP -display :$GDISP -passwdfile /etc/groovix/remote-desktop.pw  -forever -shared  &
	websockify --web=/usr/share/groovix-remote-desktop/www/ :5820 :5900 &
fi



