#!/bin/bash
#
# atimodconfig:	Install FireGL accelerated driver upon first boot
#
# chkconfig: 012345 06 99
#
# description: 	aticonfig builds and installs the ATI FireGL \
#		accelerated driver for the installed graphics card. 
#
export LANG=C

# Determine Source function library (RH vs. SUSE)
if [ -f /etc/rc.status ] ; then
        . /etc/rc.status
        rc_reset
        function PASS()
        {
                rc_status -v
        }
        function FAIL()
        {
                rc_failed
                rc_status -v
                exit -1
        }
else    # Assume RH distro
        . /etc/init.d/functions
        function PASS()
        {
                action "" /bin/true
        }
        function FAIL()
        {
                action "" /bin/false
                exit -1
        }
fi

prog="atimodconfig"
RETVAL=0

current_kernel=$(uname -r)
mod_dir="/lib/modules/${current_kernel}/kernel/drivers/char/drm"
homedir="/opt/hp/graphics/ati"

case "$1" in 
 start)
        echo -n $"Starting $prog: "
        runlevel=$(set -- $(runlevel); eval "echo \$$#")

	# If a FireGL card is installed, configure it...
	if [ $( lspci | grep -qi ATI && echo 1 || echo 0 ) = 1  ]
	then
           if [ ! -f ${mod_dir}/fglrx.o -a ! -f ${mod_dir}/fglrx.ko ]
           then
                # Module is not in place for current kernel 
	        ${homedir}/configure	
           fi
        else 
        # no ATI card, turn this script off:
        /sbin/chkconfig --del $prog > /dev/null
        fi

        ;;

esac
PASS
exit $RETVAL
