TIP Démarrer une session graphique automatiquement

Un article de Gentoo Linux Wiki.

[modifier] Les scripts

Dans /etc/inittab, ajouter à la fin :

Fichier : /etc/inittab
xu:b:once:/etc/X11/startUS.sh

Créer le fichier /etc/init.d/xuser contenant :

Fichier : /etc/init.d/xuser
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
 
# This script is largely inspired from /etc/init.d/xdm
#
# Don't forget to set XUSER to the desired username in /etc/conf.d/xuser
#
# Yoann Aubineau
# yoann@yaubi.com
# 2004.03.10
 
# Start X Font Server before X
depend() {
        use xfs hotplug
}
 
start() {
        USER="$(echo ${XUSER} | awk '{ print tolower($1) }')"
 
        ebegin "Starting X session for ${USER}"
        save_options "user" "${USER}"
 
        /sbin/telinit b &>/dev/null
        eend 0
}
 
stop() {
        local retval=0
        local curvt="$(fgconsole)"
 
        ebegin "Stopping X session"
 
        rm -f ${svcdir}/options/xuser/user
 
        if [ "$(ps -A | grep -e "startx")" ]
        then
                start-stop-daemon --stop \
                        --name "startx"
                retval=$?
        fi
 
        #switch back to original vt
        chvt "${curvt}" &>/dev/null
 
        eend ${retval} "Error stopping ${myservice}."
 
        return ${retval}
}

Créer le fichier /etc/X11/startUS.sh contenant :

Fichier : /etc/X11/startUS.sh
#!/bin/sh
 
source /etc/init.d/functions.sh
source /etc/profile
 
if [ -e ${svcdir}/options/xuser/user ]
then
        retval=0
 
        USER="`cat ${svcdir}/options/xuser/user`"
        export GDK_USE_XFT=1
        /sbin/start-stop-daemon --start --background \
                --exec "/bin/su" -- - ${USER} -l -c "/usr/X11R6/bin/startx &> /dev/null"
 
        retval=$?
 
        #wait; sleep 2
 
        if [ "${retval}" -ne 0 ]
        then
                einfo "ERROR: could not start the X session..."
                killall -9 "startx" &> /dev/null
        fi
fi

Remplacer le service xdm par xuser :

Code : Remplacement de xdm
rc-update del xdm
chmod 755 /etc/init.d/xuser
rc-update add xuser default
chmod 755 /etc/X11/startUS.sh


Créer le fichier /etc/conf.d/xuser contenant :

Fichier : /etc/conf.d/xuser
# Config file for /etc/init.d/xuser
 
XUSER=yoann #type your username here