#!/bin/bash
#
# Copyright (C) 2010 Intel Corporation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Author:
#        Cao, Jenny <jenny.q.cao@intel.com>
#        Yue, jianhui <jianhuix.a.yue@intel.com>

if [ $# != 1 ];then
    echo "usage $0 + packagename"
fi

PACKAGENAME="/opt/usr/media/tct/opt/tct-ext02-wrt-tests/$1"
p_name=$1
APP_NAME=${p_name%.*}
PKG_ID=`wrt-launcher -l|grep -w $APP_NAME|awk '{print $(NF-1)}'`

if [ -n $PKG_ID ];then
  pkgcmd -u -q -t wgt -n $PKG_ID
  sleep 5
fi
pkgcmd -i -t wgt -q -p $PACKAGENAME
if [ $? -eq 0 ];then
  echo -e  " pkgcmd install widget successfully!"
  PKG_ID=`wrt-launcher -l|grep -w $APP_NAME|awk '{print $(NF-1)}'`
  pkgcmd -u -q -t wgt -n $PKG_ID
  exit 0
else
  echo -e  "pkgcmd install widget failed!"
  exit 1
fi
