#!/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   

busybox tcpsvd -vE 0 21 busybox ftpd -w / &

ssh_path=/data

while [ `mountpoint -q $ssh_path` ]
do 
    echo "$ssh_path not mounted!"        
    sleep 1
done


if [ -e /system/app/Launcher3/Launcher3.apk ];
    then
        remount
        mv /system/app/Launcher3/  /data/
        sync
fi
       
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	

if [ -e /data/bootcount ];                                          
then                                                                
        echo "not first boot"                                            
        sum=`cat /data/bootcount`                                   
        sum=$( expr $sum + 1)                                      
        echo $sum > /data/bootcount                                
        sed -i "/BootCount/c\BootCount:       ${sum}" /data/firstBootStat
else                                                                     
                                                                         
        echo 1 > /data/bootcount                                         
                                                                         
        echo "BootCount:       1" >/data/firstBootStat             
                                                        
        isEth0=`ifconfig eth0 |grep HWaddr`                                              
        if [ "$isEth0" != "" ]; then                                                     
                echo "EthFound:        true" >> /data/firstBootStat
        else                                                                             
                echo "EthFound:        false" >> /data/firstBootStat
        fi                                                          
                                                                                         
        isES8388=` cat /proc/asound/cards  |grep es8388`            
        if [ "$isES8388" != "" ]; then                              
                echo "SoundCard:       true" >> /data/firstBootStat                      
        else                                                       
                echo "SoundCard:       false" >> /data/firstBootStat
        fi                                                          
                                                                                         
        meminfo=`cat /proc/meminfo  |grep MemTotal`                 
        echo "$meminfo" >> /data/firstBootStat                      
                                                   
        emmcinfo=`busybox fdisk -l /dev/block/mmcblk1 |grep MB |busybox awk '{print $3}'`
        echo "MMCTotal:        $emmcinfo MB" >> /data/firstBootStat                      
                                                                                         
fi                                                                                       

fi

sysLED &

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