How to autostart X Windows without a graphical login manager

This Howto shows you howto setup you computer to automatically start X Windows when you use non-graphical login.

Requirements

 * 'expect' is needed for the shell script
 * http://expect.nist.gov/

Steps
case `tty` in  /dev/tty[1])       echo -n "Start X [Yn]? "       expect \           -c 'stty raw' \           -c 'set timeout 5' \           -c 'expect -nocase n {exit 1} -re . {exit 0}'       if [ $? = 0 ] ; then           startx           echo -n "Log out [Yn]? "           expect \               -c 'stty raw' \               -c 'set timeout 5' \               -c 'expect -nocase n {exit 1} -re . {exit 0}'           if [ $? = 0 ] ; then               logout           fi       fi       echo   ;; esac
 * 1) Login as user that you wish to have X autostart
 * 2) if you use bash; edit ~/.bash_profile; or you shells rc file
 * 3) Add the following to the end of the file
 * This code shouldn't load X unless X is not open and you are just logging in


 * Be sure to have a .Xdefault in you home directory to start you windows manager See: Guide to configuring X windows

From HowTo Wiki, a Wikia wiki.