#!/bin/sh
# /etc/rc.d/rc.4

# This file is executed by init(8) when the system is being
# initialized for run level 4 (XDM/KDM/GDM)

# Version:@(#)/etc/rc.d/rc.4 2.00 02/17/93
#
# Author:	Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
# At least 47% rewritten by: Patrick J. Volkerding <volkerdi@slackware.com>

# modified for colorized screen messages and local needs
source /etc/shell-colors

log_cleanup ()
{
# kdm and xdm do not rotate logs with each new session
# as does the Xorg.{DISPLAY}.log. This routine imitates
# the way the Xorg logs are rotated.
if [ -e $1 ]; then
  mv -f $1 $1.old
fi
}

echo
# Tell the viewers what's going to happen...
echo -e "${BOLDGREEN}Starting the X graphical environment...${COLOR_RESET}"

# Try to use GNOME's gdm session manager. This comes first because if
# gdm is on the machine then the user probably installed it and wants
# to use it by default:
if [ -x /usr/bin/gdm ]; then
  echo "Using GDM."
  echo
  exec /usr/bin/gdm -nodaemon
elif [ -x /usr/sbin/gdm ]; then
  # Someone thought that gdm looked prettier in /usr/sbin,
  # so look there, too:
  echo "Using GDM."
  echo
  exec /usr/sbin/gdm -nodaemon
fi

# Like gdm, if somebody installs slim then that manager is preferred.
if [ -x /usr/bin/slim ]; then
  echo "Using SLiM."
  echo
  exec /usr/bin/slim -nodaemon
elif [ -x /usr/sbin/slim ]; then
  # Just to be sure, a second possible location
  echo "Using SLiM."
  echo
  exec /usr/sbin/slim -nodaemon
fi

# Like gdm and slim, if somebody installs the Trinity login manager then that manager is preferred.
if [ -x PREFIX/bin/tdm ]; then
  echo "Using TDM (Trinity Login Manager)."
  echo
  log_cleanup "/var/log/tdm.log"
  exec PREFIX/bin/tdm -nodaemon -error /var/log/tdm.log
fi

# Not there? OK, try to use KDE's kdm session manager.
if [ -x /opt/kde/bin/kdm ]; then
  echo "Using KDM."
  echo
  log_cleanup "/var/log/kdm.log"
  exec /opt/kde/bin/kdm -nodaemon
elif [ -x /opt/kde3/bin/kdm ]; then
  echo "Using KDM."
  echo
  log_cleanup "/var/log/kdm.log"
  exec /opt/kde3/bin/kdm -nodaemon
elif [ -x /usr/bin/kdm ]; then
  echo "Using KDM."
  echo
  log_cleanup "/var/log/kdm.log"
  exec /usr/bin/kdm -nodaemon
fi

# If all you have is XDM, I guess it will have to do:
if [ -x /usr/bin/xdm ]; then
  echo "Using XDM."
  echo
  log_cleanup "/var/log/xdm.log"
  exec /usr/bin/xdm -nodaemon
elif [ -x /usr/X11R6/bin/xdm ]; then
  echo "Using XDM."
  echo
  log_cleanup "/var/log/xdm.log"
  exec /usr/X11R6/bin/xdm -nodaemon
fi

# error
echo
echo -e "${BOLDRED}Hey, GDM, SLIM, KDM, or XDM are not executable or don't exist.${COLOR_RESET}"
echo "Can't use runlevel 4 without one of those installed."
echo
echo -e "Toggle to another console ( ${BOLDWHITE}[${BOLDGREEN}Ctrl-${BOLDWHITE}] ${BOLDGREEN}Alt-F6${COLOR_RESET} ) to obtain access to your system."
sleep 10

# All done.
