#!/bin/sh

export HOSTNAME="TARGET"
export ROOTFS_VERSION=$(cat /etc/VERSION)

hostname $HOSTNAME

case "$1" in
	start|"")
            #Configure CPU temperature limits for Automotive grade CPU (default is industrial)
            echo 125000 > /sys/class/thermal/thermal_zone0/trip_point_1_temp
            echo 115000 > /sys/class/thermal/thermal_zone0/trip_point_0_temp
            #execute launch script if it exists
	    if [ -f /app/bin/applaunch.sh ]; then
			echo "Launching app..."
			# Copy /app/bin/applaunch to /tmp and execute
			# NOTE: This means it can dismount the UBI filesystems if it wants to...
			cp /app/bin/applaunch.sh /tmp
			cp /app/bin/settings.sh /tmp
			/tmp/applaunch.sh &
		else
			# Turn LCD backlights full on
			echo 0 > /sys/class/pwm/pwmchip2/export
			echo 100000 > /sys/class/pwm/pwmchip2/pwm0/period
			echo 1 > /sys/class/pwm/pwmchip2/pwm0/enable
			echo 100000 > /sys/class/pwm/pwmchip2/pwm0/duty_cycle
			# and show test pattern on screen
			fb-test
		fi
		;;

	stop)
		;;

	restart|reload)
		"$0" stop
		"$0" start
		;;

	*)
		echo $"Usage: $0 {start|stop|restart}"
		exit 1
esac

exit $?
