#!/bin/sh

script_path=`echo $0 | awk -F '/' '{for(i=2;i<NF;i++) printf"/"$i}'`
echo $script_path

SET=`cat $script_path/set.ini | ./busybox grep "ScreenSoftRotationSet:" | ./busybox grep -v grep | sed 's/ScreenSoftRotationSet://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
ANGLE=`cat $script_path/set.ini | ./busybox grep "RotationAngle:" | ./busybox grep -v grep | sed 's/RotationAngle://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

[ -e "/mnt/mtd/Flags/ScreenSoftRotationFlag" ] && rm /mnt/mtd/Flags/ScreenSoftRotationFlag
if [ "$SET" = "yes" ]; then
	if [ "$ANGLE" = 90 ]; then
		angle=1
	elif [ "$ANGLE" = 180 ]; then
		angle=2
	elif [ "$ANGLE" = 270 ]; then
		angle=3
	else
		angle=0
	fi
	echo "RotationAngle:$angle" >> /mnt/mtd/Flags/ScreenSoftRotationFlag
fi
