. /etc/rc.d/init.d/functions


case $1 in


	8)
		VALID="yes"
		;;
	15)
		VALID="yes"
		;;
	16)
		VALID="yes"
		;;
	24)
		VALID="yes"
		;;
	*)	echo ""
		echo "usage:	fb_setup_x <color-depth>"
		echo "	(ex. fb_setup_x 16)"
		echo ""
		VALID="no"
		;;
esac

# --------------------- Configuration Modification Code ------------------------------

if [ $VALID = "yes" ]; then
	if [ -n "`( cat /etc/X11/XF86Config | grep fbdev )`" ]; then
		STARTLINE=`cat -n /etc/X11/XF86Config | grep "Subsection" -w |awk ' {print $1;}'`
		STOPLINE=`cat -n /etc/X11/XF86Config | grep "EndSubsection" -w |awk ' {print $1;}'`
		SPOT=1

		echo -n "Searching for Frame Buffer Configuration Section"
		success="no"
		for ignore in $STARTLINE
		do
			echo -n "."
			BEGIN=`echo $STARTLINE | awk ' {print $'$SPOT'; } '`
			END=`echo $STOPLINE | awk ' {print $'$SPOT'; } '`
			if [ -n "`( cat /etc/X11/XF86Config | awk ' NR=='$BEGIN',NR=='$END' { print $0; } ' |grep "Modes" |grep \"default\" )`" ]; then
				LINE=`cat -n /etc/X11/XF86Config | awk ' NR=='$BEGIN',NR=='$END' { print $0; } ' | grep -i "Depth"|awk ' {print $1}'`
				cp /etc/X11/XF86Config /etc/X11/XF86Config.bak
				cat /etc/X11/XF86Config | awk ' NR=='$LINE' {print "	Depth	"'$1'; next; } { print $0; } ' > /tmp/Xconfig 
				mv /tmp/Xconfig /etc/X11/XF86Config	
				success="yes"
			fi
		SPOT=`expr $SPOT + 1`
		done
		if [ $success = "yes" ]; then
			echo ""
			echo -n "FrameBuffer section found and configured for "$1"-bit color"
			action "" /bin/true
		fi
	else
		echo ""
		echo "	No FrameBuffer configuration Section" 
		echo "	could be found in /etc/X11/XF86Config"
		echo ""
	fi
elif [ VALID="no" ] & [ $1 ]; then
	echo "  The currently supported color depths are:"
	echo "  8 (256 Colors) 15 (32K Colors) 16 (64K Colors)"
	echo "  24 (16.7 Million Colors)"
fi

