#!/bin/sh

################################################################################
#      Copyright (C) 2009-2010 OpenELEC.tv
#      http://www.openelec.tv
#
#  This Program is free software; you can 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 Program 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
#  along with OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

# starting xorg
#
# runlevels: openelec

. /etc/profile

  XORG_ARGS="-s 0 -nr -noreset -allowMouseOpenFail -nocursor -nolisten tcp"

  [ "$DEBUG" = yes ] && XORG_ARGS="$XORG_ARGS -logverbose 6 -verbose 6"

(
  progress "creating directories needed for Xorg"

    mkdir -p /var/cache/xkb
    mkdir -p /var/lib
    mkdir -m 1777 -p /tmp/.ICE-unix
    chown root:root /tmp/.ICE-unix

    if [ "$GPUTYPE" = "NVIDIA" ]; then
      ln -sf /usr/lib/libGL_nvidia.so.1 /var/lib/libGL.so
      ln -sf /usr/lib/xorg/modules/extensions/libglx_nvidia.so /var/lib/libglx.so
      XORG_ARGS="$XORG_ARGS -ignoreABI"
    else
      ln -sf /usr/lib/libGL_mesa.so.1 /var/lib/libGL.so
      ln -sf /usr/lib/xorg/modules/extensions/libglx_mesa.so /var/lib/libglx.so
    fi

  progress "starting xorg"

    XORG_ARGS="$XORG_ARGS -config $XORG_CONF"
    Xorg $DISPLAY vt01 $XORG_ARGS > /dev/null 2>&1

)&