#! /bin/sh
### BEGIN INIT INFO
# Provides:          oem-config
# Required-Start:    $remote_fs $syslog $time hal
# Required-Stop:     $remote_fs $syslog $time hal
# X-Start-Before:    gdm kdm xdm
# X-Stop-After:      gdm kdm xdm
# Default-Start:
# Default-Stop:
# Short-Description: End-user configuration after initial OEM installation
# Description:       Run on the first boot after shipping to the end user to
#                    reconfigure the system for them; removes itself
#                    thereafter.
### END INIT INFO

set -e

PATH="/usr/local/sbin:/usr/sbin:/sbin${PATH:+:$PATH}"

# Exit if the package is not installed
if ! type oem-config-firstboot >/dev/null 2>&1; then
	exit 0
fi

debug=
for x in $(cat /proc/cmdline); do
	case $x in
		debug-oem-config)
			debug=--debug
			;;
	esac
done

case $1 in
	start)
		export LANG=en_US.UTF-8
        /usr/lib/libgconf2-4/gconfd-2 &
        gconftool-2 --type=int --set /spider/key_setting/left_key_short_press 4
        gconftool-2 --type=int --set /spider/key_setting/right_key_short_press 1
        #gconftool-2 --type=string --set /spider/action_setting/mouse_left_action  "ctrl"
        #gconftool-2 --type=string --set /spider/action_setting/mouse_right_action  "mouse_right"
		read_event &
		do_calibrate_touchscreen --init
        gconftool-2 --type=int --set /spider/key_setting/left_key_short_press 0

		# Make the splash screen go away if necessary.
		DO_NOT_SWITCH_VT=yes /etc/init.d/usplash start || true
		sp_key_action &
        pidd=$( pidof read_event)
        kill -9 $pidd
		# Reconfigure the system (starts a temporary display
		# manager).
		oem-config-firstboot $debug </dev/console >/dev/console 2>&1
		
		# The lateboot cmds may need some setup after user config
		# has completed 
		if [ -x /usr/sbin/lateboot-setup ]; then
			/usr/sbin/lateboot-setup
		fi
		rm -rf /tmp/.sp_key_action.lock
		pidd=$( pidof sp_key_action)
		kill -9 $pidd

		pidd=$( pidof gconfd-2)
		kill -9 $pidd

        #pidd=$( pidof read_event)
        #kill -9 $pidd

		;;
esac

exit 0
