#!/bin/sh

source /etc/sysconfig/config;
source /etc/sysconfig/helpers/functions

MODULE=maximfb

# chkconfig flag
CHKDEV=fb

IS_ON=/bin/chkconfig
IS_MODULE=/bin/chkmodule
CONFIG=/var/config

ERR=0

case "$1" in
    "start")
		if $IS_ON $CHKDEV
		then
			echo "Loading framebuffer ..."
			# this will be overwritten if it exist in options file
			MODPARAMS=
			if [ -e ${CONFIG}/${CHKDEV}.options ]
			then
				source ${CONFIG}/${CHKDEV}.options
			fi
			load_module ${MODULE} ${MODPARAMS}
			if [ "X$?" != "X0" ]
			then 
				ERR=1
			fi
			if [ ! -e /dev/tty0 ]
			then 
				ln -s /dev/ttyS0 /dev/tty0
			fi

		fi
        ;;
    "stop")
        echo "Unloading framebuffer ..."
		if $IS_ON $CHKDEV
		then
			lsmod | grep -sq ^`echo "$MODULE" |tr '-' '_'`
			if [ $? -eq 0 ]
			then	
				rmmod ${MODULE}
			fi
		fi
        ;;
    *)
        echo "Syntax is $0 start | stop"
        exit 255;
        ;;
esac

if [ "X${ERR}" != "X0" ]
then
	echo "failed";
else 
	echo "done"
fi

exit $ERR
