#!/usr/bin/ksh
#=============================================================================
# Nom            : opcagt_util
# Projet         : HP-Openview IT/Operations
# Cree le        : 03/01/2000
# Cree par       : T.DELPLANQUE
# Objet          : Script verifiant la version de opcagt a utiliser.
# Appel(s)       : ?
# Environnements : HP-UX 9.05 10.20
#                : Solaris 5.3 5.4 5.5 5.5.1 5.6
#                : SunOs 4.1.3
#                : Aix 3.x 4.2 4.3
#                : Irix 5.3
#=============================================================================
# Modification(s)
#-----------------------------------------------------------------------------
# JJ/MM/AA - QUI
#       QUOI
#
#
# 08/02/2000 - T.DELPLANQUE
#	Ajout d un test dans le main qui verifi
#	que ITO est bien stoppe, avant de copier 
#	le bon opcagt.
#
#
# 04/04/2000 - T.DELPLANQUE
#       Ajout de l OS IRIX64.
#
# 11/04/2000 - T.DELPLANQUE
#	Changement du chemin au binaire ksh, pour pouvoir
#	fonctionner correctement sur IRIX. /usr/bin/ksh.
#
# 16/06/2000 - JPh BOCQUENET
#	Changement des mv en cp pour copier les opcagt dans /opt/OV/bin/OpC
#	En cas de plantage, le opcagt_OS n'est pas detruit et peut etre
#	rutilis.
#
# 18/09/2000 - T. DELPLANQUE
#	Modif du path pour les AIX usr a ete change en var, suite a une erreur
#
#=============================================================================
# Fonctions
#-----------------------------------------------------------------------------
#       DeterminationOS FonctionHPUX FonctionHPUX10 FonctionSunOS
#       FonctionSolaris FonctionAIX FonctionAIX42 FonctionIRIX
#=============================================================================
#
# Definition des variables globales locales script:
typeset OPCAGT				# Version de opcagt a utiliser
typeset TypeMachine                     # Recuperation de l'OS          
typeset ReferenceFonction               # Commande differente suivant l'OS

# Quel est le mot clef a rechercher dans les process ITO ?
OPC_PROC="opc"

#=============================================================================
# DeterminationOS
# Reconnaitre l'OS sur lequel le script se deroule
# Code retour : 0 => OK
#             : 2 => Erreur
#=============================================================================
function DeterminationOS
{
        TypeMachine=$(uname -s)           # Recuperation de l'OS        

        case ${TypeMachine} in
        HP-UX)
                OPCAGT=/var/opt/OV/bin/OpC/cmds/opcagt_hp
                ReferenceFonction=FonctionHPUX
                ;;
        SunOS)
                OPCAGT=/var/opt/OV/bin/OpC/cmds/opcagt_sun
		ReferenceFonction=FonctionSunOS
                ;;
        AIX)
		ReferenceFonction=FonctionAIX
                OPCAGT=/var/lpp/OV/OpC/cmds/opcagt_aix
                ;;
        IRIX64)
                OPCAGT=/var/opt/OV/bin/OpC/cmds/opcagt_irix
                ReferenceFonction=FonctionSunOS
                ;;
        *)      
		OPCAGT=/opt/OV/bin/OpC/cmds/opcagt
		ReferenceFonction=FonctionDefault
                ;;
        esac
        return $?
}

function FonctionHPUX
{
	mv /opt/OV/bin/OpC/opcagt /tmp/opcagt_old
	cp ${OPCAGT} /opt/OV/bin/OpC/opcagt
}

function FonctionSunOS
{
	mv /opt/OV/bin/OpC/opcagt /tmp/opcagt_old
	cp ${OPCAGT} /opt/OV/bin/OpC/opcagt
}

function FonctionAIX
{
	mv /var/lpp/OV/OpC/cmds/opcagt /tmp/opcagt_old
	cp ${OPCAGT} /var/lpp/OV/OpC/cmds/opcagt
}

function FonctionDefault
{
        mv /opt/OV/bin/OpC/opcagt /tmp/opcagt_old
        cp ${OPCAGT} /opt/OV/bin/OpC/opcagt
}

#=============================================================================
# Partie principale
#
DeterminationOS

if [ `ps -ef | grep ${OPC_PROC} | grep root | grep -v grep | awk 'END {print NR}'` -gt 2 ]
	then	echo "Merci de stopper ITO..."
		exit 0
	else	${ReferenceFonction}
		echo "Un appel a ito_util a ete ajoute dans opcagt."
fi

exit 0
#
# eof
#=============================================================================

