#!/system/bin/sh

## set rk808 THERMAL_REG 
i2cset -f -y 0 0x1b 0x22 0x1c
i2cget -f -y 0 0x1b 0x22
i2cset -f -y 0 0x1b 0x22 0x1c

echo 1 >/sys/class/mybuzzer/buzzer-1/on   

ssh_path=/data

while [ `mountpoint -q $ssh_path` ]
do 
    echo "$ssh_path not mounted!"        
    sleep 1
done
       
wantRes=`getprop ro.myResolution`
echo "wantRes is $wantRes" 

imgsPath=/system/resourceImgs/

function check_imgs_res () {
        imgs_res=resource-upt159_${1}.dtb.img
        echo "choice $imgs_res"
	if [ -f "$imgsPath/$imgs_res" ];then
		sr $1
 	fi
}

if [ ! -f "$ssh_path/myRes" ]; then
	check_imgs_res $wantRes
else
	nowRes=`cat $ssh_path/myRes`
	if [ "$nowRes" == "$wantRes" ] ; then
		echo "the same Res"
	else
		check_imgs_res $wantRes
	fi	
fi

## save last_log ##
setprop persist.sys.abc_switch 1

ip rule add from all lookup main pref 9999

myotg2host=`getprop ro.bst.myotg2host`
echo "myotg2host is $myotg2host" 

if [ "0" == "$myotg2host" ] ; then
		echo "set otg 2 adb"
        otg2host 0
else
		echo "set otg 2 host"
        otg2host 1
fi	

myftpd=`getprop ro.bst.myftpd`
echo "myftpd is $myftpd" 

if [ "1" == "$myftpd" ] ; then
		echo "set myftpd"
busybox tcpsvd -vE 0 21 busybox ftpd -w / &
fi	

mytpmon=`getprop ro.tpmon`
echo "ro.tpmon is $mytpmon" 

if [ "true" == "$mytpmon" ] ; then
		echo "set mytpmon"
/system/bin/tpmon &
fi

mount -o rw,remount /system
chmod 777 /system/bin/rtcSync
rtcSync &
mount -o ro,remount /system

while true
do
        if [ -f "/data/uptscript/upgrade.sh" ]; then
                echo "run upgrade.sh"
                chmod 777 /data/uptscript/upgrade.sh
                /data/uptscript/upgrade.sh

                sleep 1
                echo "remove upgrade.sh"
                rm /data/uptscript/upgrade.sh
        fi
        sleep 10
done
