#! /bin/sh

### BEGIN INIT INFO
# Provides:        set-xorg
# Required-Start:  $local_fs $remote_fs
# Required-Stop:   $local_fs $remote_fs
# Default-Start:   2 3 4 5
# Default-Stop:
# Short-Description: setting xorg.conf
### END INIT INFO

DESC="setting xorg.conf"
NAME=set-xorg
VIV_CONF=65-vivante.conf

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions


do_start()
{
   for CMDLINE_OPT in $(cat /proc/cmdline); do
	   case ${CMDLINE_OPT} in
	
	   cpu=*)
	       CPU=${CMDLINE_OPT#cpu=}
	       ;;
	
	   board=*)
	       BOARD=${CMDLINE_OPT#board=}
	       ;;
	   esac
   done

if [ -d /usr/share/X11/xorg.conf.d ] ; then
   cd /usr/share/X11/xorg.conf.d && rm -f conf ${VIV_CONF}

   if   [ "${CPU}" = "7D" ] ; then
	   ln -s /usr/share/vivante/X11/xorg.conf/xorg-mx7d.conf ${VIV_CONF}

   elif [ "${CPU}" = "7ULP" ] ; then
	   ln -s /usr/share/vivante/X11/xorg.conf/xorg-mx7ulp.conf ${VIV_CONF}

   elif [ "${CPU}" = "6SX" ] ; then
	   ln -s /usr/share/vivante/X11/xorg.conf/xorg-mx6sx.conf ${VIV_CONF}

   elif [ "${CPU}" = "51" ] ; then
	   ln -s /usr/share/vivante/X11/xorg.conf/xorg-mx51.conf ${VIV_CONF}

   else
	   ln -s /usr/share/vivante/X11/xorg.conf/xorg-mx6.conf ${VIV_CONF}

   fi
fi

   cd /usr/lib/arm-linux-gnueabihf/vivante/common && rm -f libOpenVG.so

   if   [ "${CPU}" = "6DL" ] ; then
	   ln -s libOpenVG.3d.so libOpenVG.so
   elif [ "${CPU}" = "6SX" ] ; then
	   ln -s libOpenVG.2d.so libOpenVG.so
   else
	   ln -s libOpenVG.3d.so libOpenVG.so
   fi

}

case "$1" in
   start)
   log_daemon_msg "Starting $DESC:" "$NAME"
   do_start
   log_end_msg 0
	exit 0
      ;;

   reload|force-reload)
      echo "Error: argument '$1' not supported" >&2
      exit 3
      ;;

   stop)
      echo
      ;;

   restart)
      $0 start
      echo
      ;;

   *)
      echo "Usage: $0 start|stop" >&2
      exit 3
      ;;
esac

:
