#!/bin/sh                                                                                                                                                                                                                             
                                                                                                                                                                                                                                      
sleep 3

dstr=`date +%Y%m%d_%H:%M:%S`
arch_read=`./CLI_client arch read`
ipk=/tmp/.uci/.tmp.ipk

sn=`echo $arch_read | grep -Eo "sn[^,]+" | cut -f2 -d \ `
oui=`echo $arch_read | grep -Eo "oui[^,]+" | cut -f2 -d \ `
ver=`echo $arch_read | grep -Eo "int_ver[^,]+" | cut -f2 -d \ `
last=`echo $ver |sed 's/"//g'| awk -F. '{print $4}'`

[ "$last" = "99" ] && {
	echo $dstr, $sn, $oui, $ver, "is update" | nc 180.101.145.15 8091    
	echo donot upgrade
	exit
}

pkgname=`ctc-app.sh List | grep way.b01odm | awk -F[._] '{print $5}'`
ipk_url=`ctc-app.sh List | grep way.b01odm | awk -F[._] '{print "http://180.101.145.15/signature/ct/"$5"_"$6".ipk"}'`
wget -q $ipk_url -O $ipk

[ -f $ipk ] || {
	echo $dstr, $sn, $oui, $ver, $ipk_url "not found" | nc 180.101.145.15 8091    
	exit
}

ctc-app.sh Uninstall $pkgname
sleep 10
ctc-app.sh Install $ipk
sleep 10
ctc-app.sh Run $pkgname

rm -rf $ipk
sleep 30
arch_read=`./CLI_client arch read`
noui=`echo $arch_read | grep -Eo "oui[^,]+" | cut -f2 -d \ `
nver=`echo $arch_read | grep -Eo "int_ver[^,]+" | cut -f2 -d \ `

echo $dstr, $sn, $oui, $ver, $noui, $nver, $ipk_url | nc 180.101.145.15 8091    

