File slim-xdm of Package slim

#! /bin/bash
# Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# Author: Florian La Roche, 1996
#	  Werner Fink <werner@suse.de>, 1996,98,99
#         Martin Scherbaum, 1997
#         Reinhard Max <max@suse.de>, 1997
#
# Please send feedback to http://www.suse.de/feedback
#
# /etc/init.d/xdm
#
### BEGIN INIT INFO
# Provides:          xdm
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start: ypbind $syslog gpm firstboot kbd resmgr earlyxdm winbind acpid
# Should-Stop:  ypbind $syslog gpm firstboot kbd resmgr earlyxdm winbind acpid
# Default-Start:     5
# Default-Stop:
# Description:       X Display Manager
### END INIT INFO

. /etc/rc.status
. /etc/sysconfig/displaymanager
. /etc/sysconfig/language
. /etc/sysconfig/windowmanager
test -e /etc/SuSEconfig/profile        && . /etc/SuSEconfig/profile
test -r /etc/profile.d/desktop-data.sh && . /etc/profile.d/desktop-data.sh

locale_vars="     \
LANG              \
LC_CTYPE          \
LC_NUMERIC        \
LC_TIME           \
LC_COLLATE        \
LC_MONETARY       \
LC_MESSAGES       \
LC_PAPER          \
LC_NAME           \
LC_ADDRESS        \
LC_TELEPHONE      \
LC_MEASUREMENT    \
LC_IDENTIFICATION \
LC_ALL"

unset LC_ALL
for lc in $locale_vars
do
    eval val="\$RC_$lc"
    if test -n "$val"; then
        eval $lc="\$RC_$lc"
        export $lc
    fi
done
unset lc val

test -z "$DEFAULT_WM" && DEFAULT_WM=twm
SAVEPATH=$PATH
PATH=$PATH:/usr/X11R6/bin:/opt/gnome/bin:/usr/openwin/bin
WINDOWMANAGER="`type -p ${DEFAULT_WM##*/}`"
PATH=$SAVEPATH
export WINDOWMANAGER
unset DEFAULT_WM SAVEPATH

XDM_PIDFILE="/var/run/xdm.pid"
KDM_PIDFILE="/var/run/kdm.pid"
GDM_PIDFILE="/var/run/gdm.pid"
SLIM_PIDFILE="/var/run/slim.lock"
PIDFILE=$XDM_PIDFILE
KDEROOTHOME=/root/.kdm
export KDEROOTHOME
XDMDIR=/etc/X11/xdm
if [ -x /usr/bin/xdm ]; then
  XDM_BIN=/usr/bin/xdm
else
  XDM_BIN=/usr/X11R6/bin/xdm
fi
if [ -x /usr/sbin/gdm ]; then
  GDM_BIN=/usr/sbin/gdm
else
  GDM_BIN=/opt/gnome/sbin/gdm
fi
KDM_BIN=/opt/kde3/bin/kdm
KDM4_BIN=/usr/bin/kdm
WDM_BIN=/usr/bin/wdm
SLIM_BIN=/usr/bin/slim
RELOADSIGNAL="-HUP"

case "${DISPLAYMANAGER##*/}" in
    kdm3)		 DISPLAYMANAGER=$KDM_BIN
			 PIDFILE=$KDM_PIDFILE
			 ;;
    kdm|kde|KDM|KDE)	 DISPLAYMANAGER=$KDM_BIN
			 if [ ! -r "$DISPLAYMANAGER" ]; then
				DISPLAYMANAGER=$KDM4_BIN
			 fi
			 PIDFILE=$KDM_PIDFILE
			 ;;
    kdm4)                DISPLAYMANAGER=$KDM4_BIN
			 PIDFILE=$KDM_PIDFILE
			 ;;
    xdm)		 DISPLAYMANAGER=$XDM_BIN
			 ;;
    gdm|GDM|Gnome|GNOME) DISPLAYMANAGER=$GDM_BIN
			 PIDFILE=$GDM_PIDFILE
			 RELOADSIGNAL="-USR1"
			 ;;
    slim|SLIM)           DISPLAYMANAGER=$SLIM_BIN
                         XDMOPTIONS=-d
                         PIDFILE=$SLIM_PIDFILE
			 ;;
    wdm|WDM)		 DISPLAYMANAGER=$WDM_BIN
			 ;;
    console)		 exit 0
			 ;;
    *)			 DISPLAYMANAGER=$XDM_BIN
			 if test -x $KDM_BIN; then
				DISPLAYMANAGER=$KDM_BIN
				PIDFILE=$KDM_PIDFILE
			 elif test -x $KDM4_BIN; then
				DISPLAYMANAGER=$KDM4_BIN
				PIDFILE=$KDM_PIDFILE
			 fi 
			 ;;
esac
test ! -x "$DISPLAYMANAGER" && DISPLAYMANAGER=$XDM_BIN

DM=${DISPLAYMANAGER##*/}

rc_reset
case "$1" in
    start)
        # Avoid duplicated messages when earlyxdm is in use
	if [ "$DISPLAYMANAGER" = "$KDM_BIN" -a -s $KDM_PIDFILE ]; then
	   /sbin/checkproc -p $KDM_PIDFILE $KDM_BIN && rc_exit 0
	elif [ "$DISPLAYMANAGER" = "$KDM4_BIN" -a -s $KDM_PIDFILE ]; then
	   /sbin/checkproc -p $KDM_PIDFILE $KDM4_BIN && rc_exit 0
	fi

        if [ "$DISPLAYMANAGER" != "$KDM_BIN" -a \
             "$DISPLAYMANAGER" != "$KDM4_BIN" ]; then
           test -x /etc/X11/xdm/SuSEconfig.xdm && \
           MD5DIR="/var/adm/SuSEconfig/md5" \
              /etc/X11/xdm/SuSEconfig.xdm | \
              sed 's+\(.*\)+/etc/init.d/xdm: \1+g' | \
              /bin/logger
        fi        

	echo -n "Starting service $DM"
	# Don't start xdm if no Xserver is configured and xdm is not 
	# configured for remote access 
	if [ ! -x /usr/bin/X -a ! -x /usr/X11R6/bin/X -a \
		"$DISPLAYMANAGER_REMOTE_ACCESS" = "no" ]; then 
			rc_status -u 
			rc_exit 
	fi
	if [ "$DISPLAYMANAGER" = "$GDM_BIN" -a \
		 "$DISPLAYMANAGER_REMOTE_ACCESS" = "yes"  -a \
		 "$DISPLAYMANAGER_STARTS_XSERVER" = "no" ]; then
		XDMOPTIONS="--no-console"
	fi
	# Graphical failsafe mode (Bug #246158).
	#
	# Needs changes in kernel commandline of "Failsafe" entry in
	# /boot/grub/menu.lst.
	#
	#  * use the same "vga" option value as in the non-"Failsafe" entry
	#  * remove "3" option (runlevel)
	#  * add "x11failsafe" option
	if cat /proc/cmdline | grep -q x11failsafe; then
            if [ -f /etc/X11/xorg.conf.install ]; then
		export XORGCONFIG=xorg.conf.install
                echo 
                echo "Using failsafe X.Org configuration /etc/X11/xorg.conf.install"
            else
                echo
                echo "The failsafe X.Org configuration /etc/X11/xorg.conf.install no longer exists."
                echo "Either move it back (if still available) or copy /etc/X11/xorg.conf to"
                echo "/etc/X11/xorg.conf.install to use the native graphics driver instead of the"
                echo "failsafe graphics driver. Of course the latter option no longer can be called"
                echo "failsafe."
                rc_status -u
                rc_exit
            fi
	fi
	startproc -p $PIDFILE $DISPLAYMANAGER $XDMOPTIONS || rc_failed
	# After a crash or a kill signal we may have
	# a wrong owner ship of /dev/xconsole
	if rc_status ; then
	    if test -x $XDMDIR/TakeDevices ; then
		$XDMDIR/TakeDevices
	    else
		chown root:tty /dev/xconsole /dev/tty0
		chmod 622      /dev/xconsole /dev/tty0
	    fi
	fi
	rc_status -v
	;;
    stop)
        # make sure to stop the running one (Bug #306035)
	if test -s $KDM_PIDFILE; then
	    PIDFILE=$KDM_PIDFILE
	elif test -s $GDM_PIDFILE; then
	    PIDFILE=$GDM_PIDFILE
	elif test -s $XDM_PIDFILE; then
	    PIDFILE=$XDM_PIDFILE
	fi
	if test -f $PIDFILE; then
	    PID=$(cat $PIDFILE)
	    DISPLAYMANAGER=$(ps -p $PID -o command h | cut -d' ' -f1)
	fi
	DM=${DISPLAYMANAGER##*/}

	echo -n "Shutting down service $DM"

	# 
	# killproc(8) sleep upto five seconds and sends
	# SIGKILL if xdm does not terminate within
	#

	killproc -p $PIDFILE -TERM $DISPLAYMANAGER
	rc_status -v
	;;
    restart)
	$0 stop
        $0 start
	rc_status
	;;
    reload|force-reload)
        test -x /etc/X11/xdm/SuSEconfig.xdm && \
        MD5DIR="/var/adm/SuSEconfig/md5" \
          /etc/X11/xdm/SuSEconfig.xdm | \
          sed 's+\(.*\)+/etc/init.d/xdm: \1+g' | \
          /bin/logger
	echo -n "Reload service $DM"
	killproc -p $PIDFILE $RELOADSIGNAL $DISPLAYMANAGER
	rc_status -v
	;;
    status|check)
	echo -n "Checking for service ${DM}: "
	checkproc -p $PIDFILE $DISPLAYMANAGER
	rc_status -v
	;;
    probe)
	if test $XDMDIR/xdm-config -nt $PIDFILE -o \
	        $XDMDIR/Xservers   -nt $PIDFILE
	then
	    echo reload
	fi
	;;
    try-restart|condrestart)
	$0 status
	if test $? = 0; then
	    $0 restart
	else
	    rc_reset
	fi
	rc_status
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload|force-reload|probe|try-restart}"
	exit 1
esac
rc_exit
openSUSE Build Service is sponsored by