#!/bin/sh

# $Id: xfree86-common.init 2186 2005-02-11 07:11:05Z branden $

# Copyright 2003, 2004 Branden Robinson <branden@debian.org>.
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with
# the Debian operating system, in /usr/share/common-licenses/GPL;  if
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA

set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin
SOCKET_DIR=/tmp/.X11-unix
ICE_DIR=/tmp/.ICE-unix

do_restorecon () {
  # Restore file security context (SELinux).
  if which restorecon >/dev/null 2>&1; then
    restorecon "$1"
  fi
}

set_up_socket_dir () {
  echo -n "Setting up X server socket directory $SOCKET_DIR..."
  if [ -e $SOCKET_DIR ] && ! [ -d $SOCKET_DIR ]; then
    mv $SOCKET_DIR $SOCKET_DIR.$$
  fi
  mkdir -p $SOCKET_DIR
  chown 0:0 $SOCKET_DIR
  chmod 1777 $SOCKET_DIR
  do_restorecon $SOCKET_DIR
  echo "done."
}

set_up_ice_dir () {
  echo -n "Setting up ICE socket directory $ICE_DIR..."
  if [ -e $ICE_DIR ] && ! [ -d $ICE_DIR ]; then
    mv $ICE_DIR $ICE_DIR.$$
  fi
  mkdir -p $ICE_DIR
  chown 0:0 $ICE_DIR
  chmod 1777 $ICE_DIR
  do_restorecon $ICE_DIR
  echo "done."
}

case "$1" in
  start)
    set_up_socket_dir
    set_up_ice_dir
  ;;

  restart|reload|force-reload)
    /etc/init.d/xfree86-common start
  ;;

  stop)
   :
  ;;

  *)
    echo "Usage: /etc/init.d/xfree86-common {start|stop|restart|reload|force-reload}"
    exit 1
    ;;
esac

exit 0

# vim:set ai et sts=2 sw=2 tw=80:
