#!/bin/sh
# Program:
#        Uninstall Supermicro Thin-agent

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
prog="Thin-Agent Service"
directory="/opt/supermicro"
TAS_BIN="/opt/supermicro/IPMITAS"
tas_dir="/etc/rc.d"

echo "TAS uninstall start..."

stop() {
  echo  "Stopping $prog"
  $TAS_BIN -agent stop-service  
  sleep 6

  test -f /var/run/watchtas.pid
  if [ $? -ne 0 ]; then
    watch=`ps -x | grep watchtas | grep -v grep | awk '{print $1}'`
    if [ $? -eq 0 ]; then
      for i in $watch
        do
          kill $i
        done
    fi
  else
    kill `cat /var/run/watchtas.pid`
  fi

  if pgrep -f IPMITAS > /dev/null ; then
    pkill -9 -x IPMITAS
  fi
}

stop
echo "Clear data..."
$TAS_BIN -agent clear
sleep 10

rm -rf $directory
rm -rf /opt
rm $tas_dir/tas
rm $tas_dir/watchtas

echo "TAS uninstall complete"
