#!/bin/sh
#****************************************************************
# *     Copyright (C) 2003, Wistron Inc.  All Rights Reserved.
# *     File Name:              wsmapkg
# *     Author:                 Jerry Zhou
# *     Create Time:    2003-06-03 14:09:26
# *     Last Update:    2003-06-25 14:59:16 by Jerry Zhou
#****************************************************************
pkg_key=wsma-1.18-0
pkg_mid="rhe3"
pkg_append=i386.rpm
pega_rpm=pegasus-2
drv_pkg_key=wsmbdrv-1.5-0
wconf_pkg_key=wconfig-2.10-0
wconf_path=/usr/local/share/asmagent/wconfig
wsma_path=/usr/local/share/asmagent/wsma
pkginfo_file=$wsma_path/createrpminfo

if uname -r|grep "2\.4\.18-14" 1>/dev/null 2>/dev/null ; then
        echo "Abort! Linux Redhat 8.0 is not supported now!"
        exit 1
fi
if uname -r|grep "2\.4\.18-3" 1>/dev/null 2>/dev/null ; then
        echo "Abort! Linux Redhat 7.3 is not supported now!"
        exit 1
fi

case $1 in
        install)
                tmp=`uname -r`
                if echo $tmp | grep "2\.4\.18-3" 1>/dev/null 2>/dev/null ; then
                        pkg_mid="rh73"
                fi
                if echo $tmp | grep "2\.4\.18-14" 1>/dev/null 2>/dev/null ; then
                        pkg_mid="rh80"
                fi
                if echo $tmp | grep "2\.4\.20-8" 1>/dev/null 2>/dev/null ; then
                        pkg_mid="rh90"
                fi
                if echo $tmp | grep "2\.4\.21-4" 1>/dev/null 2>/dev/null ; then
                        pkg_mid="rhe3"
                fi
                pkg_name=$pkg_key"."$pkg_mid"."$pkg_append
                if rpm -qa|grep $pega_rpm 1>/dev/null 2>/dev/null; then
                        echo ""
                else
                        echo "Abort: NO pegasus-2.* package is installed."
                        exit 1
                fi
                if rpm -qa|grep $drv_pkg_key 1>/dev/null 2>/dev/null; then
                        echo ""
                else
                        echo "Abort: NO wsmbdrv package is installed."
                        exit 1
                fi
                if rpm -qa|grep $wconf_pkg_key 1>/dev/null 2>/dev/null ; then
                        echo ""
                else
                        echo "Abort: No wconfig package is installed."
                        exit 1
                fi
                rpm -i --force --nodeps $pkg_name
                ln -s -f $wconf_path/evtconf $wsma_path/
                echo "Gathering installed package information ..."
                echo "It may take a few minutes. Please wait ..."
                $pkginfo_file
                ;;
        uninstall)
                if rpm -qa | grep $pkg_key 1>/dev/null 2>/dev/null ; then
                        installedpkgname=`rpm -qa | grep $pkg_key`
                        rpm -e $installedpkgname
                fi
                ;;
        *)
                echo "Usage: wsmapkg {install | uninstall}"
                exit 1
esac

exit 0
