#!/bin/bash
#
# autostart is execute at login 
# (executed by .xinitrc)
#

### source liblinuxlive
MOUNTDIR=livecd
. /$MOUNTDIR/live/liblinuxlive

### get run=... from kernel parameter
RUN=$( cmdline_value run )

### run not defined -> exit
if [ ! $RUN ]; then
    if [ -x /usr/bin/psi-menu ]; then
	/usr/bin/psi-menu &
    else
	xterm -geometry 100x30+100+100 &
    fi
fi

### functions
poweroff_system()
{
    Xdialog --yesno '\nShutdown your PC now ?\n' 0 0
    if [ "$?" = "0" ]; then
	poweroff
	sleep 20
    fi
}    

### rdesktop, afterwards ask to poweroff
if [ "$RUN" = "rdesktop" ]; then
    while [ "" = "" ]; do
	rdesktop $RDESKTOP_OPT -d PSICH -f -u win_username -a24 -x lan -r sound:local winterm1
	poweroff_system
    done
fi

### nx client, afterwards aks to poweroff
if [ "$RUN" = "nxclient" ]; then
    while [ "" = "" ]; do
	nxclient
	NXDOWN=""
	while [ ! $NXDOWN ]; do
	    sleep 1
	    ps wwaux | grep -v grep | grep -q nxssh
	    [ "$?" = "1" ] && NXDOWN=yes
	done
	killall nxclient
	poweroff_system
    done
fi

### start what is given by "run"
$RUN &