#!/bin/sh

################定义变量##########################################
APP_UpgradePkg=$1
UpgradeDir="/tmp/wifiAppPkg_9802_STA"
UpgradeAppDir="$UpgradeDir/hlwh"
UpgradeBinDir="$UpgradeDir/bin"
UpgradeSbinDir="$UpgradeDir/sbin"
UpgradeEtcDir="$UpgradeDir/etc"
UpgradeLibDir="$UpgradeDir/lib"
UpgradeMntDir="$UpgradeDir/mnt"
UpgradeUsrDir="$UpgradeDir/usr"
UpgradeSuccessFile="/tmp/upgrade_success"

AppDir="/opt/hlwh"
BinDir="/bin"
SbinDir="/sbin"
EtcDir="/etc"
LibDir="/lib"
MntDir="/mnt"
UsrDir="/usr"

################解压升级文件#####################################
if [ -f "$APP_UpgradePkg" ]; then
    cd /tmp/
    tar -zxf $APP_UpgradePkg
    cd -
fi

################拷贝升级文件至目标文件中#########################
if [ -d "$UpgradeAppDir" ]; then
    cd $UpgradeAppDir
    cp -af * $AppDir
    cd -
fi

if [ -d "$UpgradeBinDir" ]; then
    cd $UpgradeBinDir
    cp -af * $BinDir
    cd -
fi

if [ -d "$UpgradeSbinDir" ]; then
    cd $UpgradeSbinDir
    cp -af * $SbinDir
    cd -
fi

if [ -d "$UpgradeEtcDir" ]; then
    cd $UpgradeEtcDir
    cp -af * $EtcDir
    cd -
fi

if [ -d "$UpgradeLibDir" ]; then
    cd $UpgradeLibDir
    cp -af * $LibDir
    cd -
fi

if [ -d "$UpgradeMntDir" ]; then
    cd $UpgradeMntDir
    cp -af * $MntDir
    cd -
fi

if [ -d "$UpgradeUsrDir" ]; then
    cd $UpgradeUsrDir
    cp -af * $UsrDir
    cd -
fi
sync
upgradecheck $UpgradeDir
sleep 1

if [ -f "$UpgradeSuccessFile" ]; then
	sync
	rm -rf $UpgradeDir
	
	cfg -a AP_STARTMODE=extsta
	cfg -c
	echo "Upgrade Success+++++++++"
fi

