#! /bin/sh
#
# chkconfig: 35 29 10
# description:	Modify the i8xx and i9xx BIOS video modes
#
### BEGIN INIT INFO
# Provides: 915resolution
# Short-Description: Modify the i8xx and i9xx BIOS video modes
# Description: Modify the i8xx and i9xx BIOS video modes
### END INIT INFO


# Source function library.
. /etc/rc.d/init.d/functions

prog=915resolution

if [ -f /etc/sysconfig/$prog ]; then
    . /etc/sysconfig/$prog
fi

CHIPSET=""

if [ -f /etc/X11/xorg.conf ]; then
   CHIPSET=`grep "Intel [[:digit:]]\{3\}" /etc/X11/xorg.conf | sed 's/.*Intel \([[:digit:]]\{3\}\).*/\1/g'`
   if ! (echo $CHIPSET | egrep -q "845|865|855|852|915|945"); then
      exit 0
   fi
fi

if [ "$MODE" = "" ]; then
   exit 0
fi

XYRESO=""

if [ "$XRESO" = "" ] || [ "$YRESO" = "" ] ; then
   if [ -f /etc/X11/xorg.conf ]; then
      XYRESO=`egrep "(ModelName|Identifier).*\"LCD Panel [[:digit:]]*x[[:digit:]]*\"" /etc/X11/xorg.conf |\
              grep -v "#" |\
	      sed 's/.*LCD Panel \([[:digit:]]*\)x\([[:digit:]]*\).*/\1,\2/g' |\
	      sort | uniq | head`
      if [ "$XYRESO" = "" ]; then
         exit 0
      else
         XRESO=`echo $XYRESO | cut -f1 -d,`
         YRESO=`echo $XYRESO | cut -f2 -d,`
      fi
   else
      exit 0
   fi
fi


start() 
{
        echo -n $"Starting $prog: "
	daemon /usr/sbin/915resolution $MODE $XRESO $YRESO $BIT >/dev/null
	echo -n "${XRESO}x${YRESO}"
	touch /var/lock/subsys/$prog
	echo
}

# See how we were called.
case "$1" in
  start)
	start
        ;;
  stop)
        ;;
  restart|reload)
	start
	;;
  status)
  	status $prog
	;;
  *)
        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
esac

exit 0
