User:NoobCp/Start X at Boot
Or with a prompt:
if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then while true; do read -p 'Do you want to start X? (y/n): ' case $REPLY in [Yy]) exec xinit -- /usr/bin/X -nolisten tcp vt7 ;; [Nn]) break ;; *) printf '%s\n' 'Please answer y or n.' ;; esac done fi
The user will be logged out when X is killed. In order to avoid this, remove the
exec part from the script.