#!/bin/bash
# $Id: sm_execute_update,v 1.1 2013/10/16 15:19:08 sesam Exp $
read_ini()
{
   SM_INI=`grep -i '^sm_ini=' /etc/sesam2000.ini 2>/dev/null|cut -d"=" -f2`
   echo `grep -i "^$1=" "$SM_INI" 2>/dev/null|cut -d"=" -f2-`
}
echo "Starting update: $1"

[ "$2" = "-f" ] && force="--force"

gv_rw_work=`read_ini gv_rw_work`
if echo "$1" | grep -q 'deb$'
then
  dpkg -i "${gv_rw_work}/$1"
  iSts=$?
elif echo "$1" | grep -q 'rpm$'
then
  rpm -U -v ${force} "${gv_rw_work}/$1"
  iSts=$?
elif echo "$1" | grep -q 'sh$'
then
  "${gv_rw_work}/$1"
  iSts=$?
else
  echo "STATUS=ERROR MSG=Unkown package type"
  exit 2
fi  
if [ "$iSts" = "0" ]
then
  echo "STATUS=SUCCESS MSG=Updated"
else
  echo "STATUS=ERROR MSG=Not updated"
fi
exit $iSts
