#!/bin/bash



# 这是一个自动更新脚本

appfn=$1
applocal=$2
isbeta=$3
urlpattern="kpl-release/release"


if [ "appfn"x == ""x ]; then
   applocal=plg-app-linux-amd64.latest
fi

if [ "$applocal"x == ""x ]; then
   applocal=yplg-app
fi

if [ "$isbeta"x == ""x ]; then
   isbeta=1
fi

echo "p0:$0"
echo "applocal:$applocal"
echo "cmdaddr:$cmdaddr"
echo "configfile:$configfile"
echo "isbeta:$isbeta"

rm -rf $appfn

if [ "$isbeta"x == "1"x ]; then
  urlpattern="gnss/tools"
fi
echo "urlpattern:$urlpattern"

wget "http://119.96.169.117:3006/$urlpattern/$appfn"


# 比较MD5
rm -rf $appfn.md5
wget "http://119.96.169.117:3006/$urlpattern/$appfn.md5"

localMD5=`md5sum $appfn |awk 'NR==1'|awk '{print $1}'`
mustMD5=`cat $appfn.md5 |awk '{print $1}'`
echo " local: $localMD5"
echo "expect: $mustMD5"
if [ "$localMD5"x != "$mustMD5"x ]; then
  echo 'md5 verify fail!'
elif [ -f "$appfn" ];then
  echo 'md5 verify succ!'
  rm -rf $applocal
  cp $appfn $applocal
  chmod +x $applocal

  ps -ef|grep $applocal |grep -v 'grep' |grep -v 'sh' |grep -v 'rpxc-mipsle' |awk '{print $2}'|xargs kill -9
  echo "$applocal killed"
fi

