#!/bin/sh
#****************************************************************
# *	Copyright (C) 2003, Wistron Inc.  All Rights Reserved.
# *	File Name:		asmcleanup
# *	Author:			Jerry Zhou
# *	Create Time: 	2003-12-19 16:27:31
# *	Last Update: 	2003-12-19 16:27:31
#****************************************************************
package_set="asm6agent-g310-rh9-6.0-1 asm6agent-g310-rh3-6.0-1 asm6agent-r310-6.0-1 asfd-3.0.3-01L hma-1.30-0 rc-agent-1.0.24-0 asm6p-1.11-0 armcagent-1.4-0 wconfig-2.10-0 wsma-1.18-0 wsmbdrv-1.5-0"

verifypkg()
{
	if [ ! -z $1 ] && [ $1 = 1 ] ; then
		headerstr="Removeing "
	else
		headerstr=""
	fi
	for i in $package_set
	do
		package_name=`rpm -qa | grep $i 2>/dev/null`
		if [ -z $package_name ] ; then
			tailstr=" does not exist!"
		else
			tailstr=" exists! ("$package_name")"
		fi
		if [ $1 = 1 ] ; then
			tailstr="! ("$package_name")"
		fi
		case $i in
			asm6agent*)
				echo $headerstr"Health Monitor Agent"$tailstr
				;;
			wsma*)
				echo $headerstr"System Monitor Agent"$tailstr
				;;
			hma*)
				echo $headerstr"Health Monitor Agent"$tailstr
				;;
			armc*)
				echo $headerstr"ARMC Agent"$tailstr
				;;
			rc*)
				echo $headerstr"Remote Console Agent"$tailstr
				;;
			asm6p*)
				echo $headerstr"ASM6P Agent"$tailstr
				;;
			wconfig*)
				echo $headerstr"Config Agent"$tailstr
				;;
			wsmbdrv*)
				echo $headerstr"Driver Agent"$tailstr
				;;
		esac
		if [ $1 = 1 ] ; then
			rpm -e $package_name --nodeps --nopreun
		fi
	done
	if [ $1 = 1 ] ; then
		tmppath=/usr/bin
		rm -f $tmppath/hmapkg $tmppath/wsmapkg $tmppath/armcpkg $tmppath/wsmbdrvpkg $tmppath/rcapkg $tmppath/wconfpkg $tmppath/asm6ppkg
		rm -f $tmppath/wprocdagent /etc/init.d/wprocd /etc/rc?.d/?99wprocd
	fi
}

case "$1" in
  -v)
	verifypkg 0
	;;
  -f)
	verifypkg 1
	echo "Removing result:"
	echo ""
	verifypkg 0
	;;
  *)
	echo "Usage: asmcleanup -v  show all asm6 agent package status"
	echo "                  -f  remove all asm6 agent package"
	exit 1
esac

exit 0
