#!/bin/sh
#####################################################################
#history
#1. ver 03
#2.ver04 add break
#####################################################################
#ERROR CODE 
#  0   success
#  1   failed to unzip file
#  2   file dis-match with the device
#  3   can't found update file
#  4   no version file in update packet

#####################################################################
FTP=/var/ftp/pub
if [ -f $FTP/target.tgz ]; then
	echo "check version information:"
	if [ -f $FTP/target/version ]; then
		fn1=/home/root/version
		fn2=$FTP/target/version	
		cat $fn1 | while read BOARD_TYPE SCRIPT KERNEL APP FPGA WEB FPGA_COFDM EVENTLOG 
		do	
			echo "test Board Type:${BOARD_TYPE:11:6} "
			cat $fn2 | while read BOARD_TYPE1
			do
				################################################################################
				# check board type 
				################################################################################
				if [ ${BOARD_TYPE:11:6} != ${BOARD_TYPE1:11:6} ]
				then
					if [[ ${BOARD_TYPE:11:6} = "C01QAM" && ${BOARD_TYPE1:11:6} = "C01MOD" ]]; then
							if [ -n "$EVENTLOG" ]; then
								echo "Board Type:It's actually C01MOD"
								echo "upgrade software 1"
								exit 0						
							fi
					fi
					echo "upgrade file not for this device!"
					exit 2
				else
					echo "upgrade software"
					exit 0
				fi
			done
		break #	modify main ver	
		done
	else
		echo "The unit has not version file!"
		exit 4
	fi
else
		echo "Can not found the upgrade file."
		exit 3
fi
