#!/bin/sh
# (C) MandrakeSoft
# Chmouel Boudjnah <chmouel@mandrakesoft.com>
#
# $Id: Xsetup_0,v 1.12 2005/06/12 14:35:57 flepied Exp $

# (tmb) optimus hack for mga5 live media (mga#15734)
# hardcoded from /etc/init.d/functions (to be faster and dash compliant)
strstr() {
  [ "${1#*$2*}" = "$1" ] && return 1
  return 0
}

cmdline=$(cat /proc/cmdline)
if strstr "$cmdline" optimus; then
    /usr/bin/xrandr --auto
fi

if [ -x /etc/X11/xinit/fixkeyboard ]; then
    /etc/X11/xinit/fixkeyboard
fi

if [ -x /etc/X11/xinit.d/numlock ]; then
    /etc/X11/xinit.d/numlock &
fi

for i in /etc/X11/xsetup.d/*.xsetup ; do
    [ -d $i ] && continue

    if [ -x $i ]; then
	if grep -q "# to be sourced" $i; then
	    . $i
	else
	    $i &
	fi
    fi
done

if [ -f /usr/share/mga/backgrounds/default.jpg ]; then
# check XAUTHORITY as an euristic way to detect whether Xorg and thus xinitrc scripts are called from sddm
        if [ -n "${XAUTHORITY##/var/run/sddm*}" ]; then
                /usr/bin/xloadimage -onroot -fullscreen /usr/share/mga/backgrounds/default.jpg
        fi
fi
# Xsetup_0 ends here
