#!/bin/sh

echo "test lcd"

rm /tmp/lib8653 -rf

app_disk=`cat /tmp/partitions | grep "app" | awk '{print $2}'`

if test $app_disk
then
	if echo $app_disk | grep "mmc" > /dev/null
	then
		echo "${app_disk}p1" | read app1
		echo "${app_disk}p2" | read app2
	else
		echo "${app_disk}1" | read app1
		echo "${app_disk}2" | read app2
	fi
	
	mount /dev/$app1 /root
  if ideinfo /root | grep "two"
  then
    mount /dev/$app2 /home
    if [ -d /home/dmb ]
    then
      if [ -f /tmp/terminal8653/default.xml ]
      then
        cp /tmp/terminal8653/default.xml /home/dmb/download/
      fi 
      if [ -d /tmp/terminal8653/terminal ]
      then
        cp /tmp/terminal8653/terminal /home/dmb/ -rf
      fi
    fi
  else
    if [ -d /root/dmb ]
    then
      if [ -f /tmp/terminal8653/default.xml ]
      then
        cp /tmp/terminal8653/default.xml /root/dmb/download/
      fi 
      if [ -d /tmp/terminal8653/terminal ]
      then
        cp /tmp/terminal8653/terminal /root/dmb/ -rf
      fi
    fi
  fi
  umount /root
  umount /home
fi

if [ -f /tmp/terminal8653/default.xml ]
then
  cp /tmp/terminal8653/default.xml /tmp/dmb/usrconfig/
fi

if [ -d /tmp/terminal8653/terminal ]
then
  cp /tmp/terminal8653/terminal /tmp/dmb/usrconfig/ -rf
fi

if [ -f /tmp/terminal8653/ftp.conf ]
then
  cp /tmp/terminal8653/ftp.conf /tmp/dmb/usrconfig/
fi

echo "L" > /tmp/dmb/usrconfig/outputMode.ini

if [ -f /tmp/terminal8653/test ]
then
	 cd /tmp/terminal8653
   umount /mnt	 
   
	 mknod /dev/mum0 c 126 0
   mknod /dev/em8xxx0 c 127 0

   export EM8XXX_SERVER=:0
   export LD_LIBRARY_PATH=/tmp/terminal8653/lib/
   export PATH=/tmp/terminal8653:$PATH

   insmod llad.ko
   video_tag=0xbbbbbbbb
   audio_tag=0xaaaaaaaa
   demux_tag=0xdddddddd
   ios_tag=0x00105105

   #stop audio video demux
   #audio
   ./xkc ukill a -1
   ./xkc ukill A -1
   ./xkc ukill @ -1
   #video
   ./xkc ukill v -1
   ./xkc ukill V -1
   #demux
   ./xkc ukill d -1
   ./xkc ukill D -1
	
   #unload video audio demux
   ./xkc xunload ${demux_tag}
   ./xkc xunload ${audio_tag}
   ./xkc xunload ${video_tag}
   
   DA=`rmmalloc 0 2340777`
   ./xkc xload ${video_tag} video_microcode_t3iptv_prod.xload $DA 0
   ./xkc xload ${audio_tag} audio_microcode_t3iptv_prod_nodts.xload $DA 0
   ./xkc xload ${demux_tag} demuxpsf_microcode_t3iptv_prod.xload $DA 0
   rmfree 0 $DA

   #start demux
   ./xkc ustart ${demux_tag} d
   ./xkc ustart ${demux_tag} D
   #start video
   ./xkc ustart ${video_tag} v
   ./xkc ustart ${video_tag} V
   #start audio
   ./xkc ustart ${audio_tag} a
   ./xkc ustart ${audio_tag} A
   ./xkc ustart ${audio_tag} @

   ./xkc xload ${ios_tag} ios.bin.gz_t3iptv_prod.xload

   insmod em8xxx.ko
   
   insmod usbserial.ko vendor=0x148F product=0x3070
   insmod rt3070sta.ko

   ./test
fi