#!/bin/sh

export DISPLAY=:0

case "$1" in
start)
	# We don't want this script to block the rest of the boot process
	if [ "$2" != "background" ]; then
		$0 $1 background &
	else
		if [ ! -d /home/root/.chromium/Default ]
		then
			if [ -f /home/root/.chromium/virtualkeyboard.tar ]
			then
				echo "Installing xontab Virtual Keyboard Extension for Chromium"
				(cd /home/root/.chromium; tar xf virtualkeyboard.tar)
			fi
		fi
	
		while [  -f /var/run/starting_xserver ]
		do
			sleep 1;
		done

		export CHROME_DEVEL_SANDBOX=/usr/sbin/chrome-devel-sandbox
		export LD_LIBRARY_PATH=/usr/lib/chrome
		ROTATION=`sconfig rotation`

		CHROMIUM_URL="http://www.garz-fricke.com"
		if [ -f /etc/chromium.conf ]
		then
			CHROMIUM_URL="--kiosk `cat /etc/chromium.conf`"
		fi	

		CHROME_EXTRA_ARGS=""
		if [ -e "/usr/lib/libgsl-fsl.so.1" ] ; then
			CHROME_EXTRA_ARGS="--disable-gpu"
		fi

		if [ "${ROTATION}" != "0" ] ; then
			CHROME_EXTRA_ARGS="--disable-gpu"
		fi

		CHROME_EXTRA_ARGS="${CHROME_EXTRA_ARGS} --use-gl=egl --disable-translate --no-first-run --incognito --user-data-dir=/home/root/.chromium/"

		start-stop-daemon -m -p /var/run/chromium.pid -b -a /usr/bin/chrome/chrome -S -- ${CHROME_EXTRA_ARGS} ${CHROMIUM_URL}
	fi
	;;
stop)
	start-stop-daemon -p /var/run/chromium.pid -K
	;;
*)
	echo "Usage: /etc/init.d/chromium {start|stop}" >&2
	exit 1
	;;
esac






