#
#  go2linux:/etc/profile.d/smartx
#
#  Start X Window with automated selection of free graphics console
#
#  Written by Evseev/EBCEEB at Aug 2003
#

function smartx()
{
    if [ -z "`which startx 2>/dev/null`" ]; then
	echo Error: cannot find \"startx\", may be X Window is not installed, abort.
	return 2
    fi

    for n in 0 1 2 3 4 5 6 7; do
	echo Debug: checking graphics console $n...
        test -e /tmp/.X${n}-lock && continue
	echo Information: found free graphics console $n
        startx -- :$n
        found=1
        return 0
    done

    echo Error: no more free graphics consoles, stop.
    return 1
}

export -f smartx

## EOF ##
