#!/bin/sh
# /etc/init.d/checkrotate
#
### BEGIN INIT INFO
# Provides:          checkrotate
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     5
# Default-Stop:      0 6
# Short-Description: Sets display orientation
# Description:       Configures kernel and ROS for correct orientation
### END INIT INFO

case "$1" in
  start)
		/usr/sbin/mmarotate
		ROTATE=$?
		
		if [ "${ROTATE}" = "0" ]; then
			/usr/sbin/setrotation 0 init
		elif [ "${ROTATE}" = "3" ]; then
			#not supported by framebuffer yet, default to landscape
			/usr/sbin/setrotation 0 init
		elif [ "${ROTATE}" = "4" ]; then
			/usr/sbin/setrotation 90 init
		elif [ "${ROTATE}" = "7" ]; then
			/usr/sbin/setrotation 270 init
		fi
  ;;
	stop)
		/usr/sbin/mmarotate
		ROTATE=$?
	
		if [ "${ROTATE}" = "0" ]; then
			/usr/sbin/setrotation 0 stop
		elif [ "${ROTATE}" = "3" ]; then
			#not supported by framebuffer yet, default to landscape
			/usr/sbin/setrotation 0 stop
		elif [ "${ROTATE}" = "4" ]; then
			/usr/sbin/setrotation 90 stop
		elif [ "${ROTATE}" = "7" ]; then
			/usr/sbin/setrotation 270 stop
		fi
  ;;
  *)
	echo "Usage /etc/init.d/checkrotate [start]"
	exit -1
  ;;
esac

exit 0
