#!/bin/sh

# Require libshell
. shell-error
. shell-quote
. shell-config
. shell-var

readonly WM="/usr/bin/startxfce4"
readonly PR="/usr/bin/profilerunner"

# Turn on libshell verbose mode
verbose=1

# Start time
start="$(date '+%s')"


# Remote desktop profile runner
verbose "Run profilerunner: $PR"

if [ -x "$PR" ]; then
"$PR" &
fi

verbose "Run screen locker"
if which alterator-tc-lock >/dev/null 2>&1; then
    alterator-tc-lock
fi

verbose "Run Window manager: $WM"
if [ -x "$WM" ]; then
"$WM"
fi

# End time
end="$(date '+%s')"

# Calc run time
run_time=$((end - start))

# If session runs few seconds, stop and ask user some action
readonly PAUSE_TIME=10

if [ $run_time -lt $PAUSE_TIME ]; then
    xmessage -center -buttons 'Ok!' 'You have exit. Restarting...'
fi
