#!/bin/sh
#
# This script file updates Japanese help files of
# HP BladeSystem Integrated Management Environment 1.1.

HPSIMNAME="HP Systems Insight Manager 4.2"

####################################
#
# file and directory locations
#
####################################
SIM_BIN="/opt/mx/bin"
MXVERSION="${SIM_BIN}/mxversion"
MXTOOL=${SIM_BIN}/mxtool
MXTOOLOPT="-l f -t BogusToolName"
TAR="/bin/tar -xzf"
TARFILE=montero11_ja_help.tgz

####################################
#
# version strings for matching
#
####################################
PATCH1_VERSION_42="C.04.02.00.01"
PATCH2_VERSION_42="C.04.02.00.02"

#############################################################
#
# Function: GetSIMStatus()
#
# Checks to see if HP SIM is running
#
# Returns 0 if HP SIM is running and 1 if it is not
#
#############################################################

GetSIMStatus()
{
    $MXTOOL $MXTOOLOPT > /dev/null 2>&1

    # if return value of 200, we know that HP SIM is not started
    if [ $? = 200 ]
    then
        return 1
    fi

    return 0
}

#############################################################
#
# Main: start of the main script execution
#
#############################################################

echo
echo
echo ====================================================
echo HP BladeSystem Integrated Management Environment 1.1
echo 
echo This script file updates Japanese help files
echo 
echo Enter "'y'" to continue this installation.
echo ====================================================

read x
if [ "$x" != 'y' -a "$x" != 'Y' ]; then
	echo "Installation was not chosen.  No changes made."
	exit 50
fi

echo 

# Check to see if the user is the root user
user=`whoami`
if [ "$user" != "root" ] 
then
    echo "This patch must be run by the root user.  No changes made."
    exit 100
fi

# Check if the "mxversion" utility can be found
if [ ! -e "${MXVERSION}" ]
then
    echo "${HPSIMNAME} not found.  No changes made."
    exit 200
fi

# execute "mxversion" and store the result
simVersion=`$MXVERSION`

# if "mxversion" failed to execute properly then exit
if [ $? -ne 0 ]
then
    echo "Failed to execute $MXVERSION .  No changes made."
    exit 300
fi

# extract the version string from the "mxversion" output
verString="$(echo $simVersion | sed 's/^.*- Linux \([^ ]*\).*$/\1/')"
verString="$(echo $verString | sed 's/^.*- HP-UX \([^ ]*\).*$/\1/')"
verString="$(echo $verString | sed 's/^Systems Insight Manager \([^ ]*\).*$/\1/')"
# this strips off the last 2 fields
# verString="$(echo $verString | sed 's/.[^.]*.[^.]*$//')"

# Check to see if we can recognize the version of SIM
if [ "$verString" != "$PATCH1_VERSION_42" -a "$verString" != "$PATCH2_VERSION_42" ]
then 
	echo "${HPSIMNAME}, SP1 or SP2 not found.  No changes made."
	exit 400
fi

echo
echo "${HPSIMNAME}, $verString found."

if [ ! -f $TARFILE ]; then
	echo Tar file, $TARFILE missing. No changes made.
	exit 500
fi

echo

# install new files
x=`pwd`
cd /
$TAR ${x}/$TARFILE > /dev/null 2>&1
if [ $? -ne 0 ]; then
        echo Unable to extract tar file. No changes made.
        rm -rf temp
        exit 1000 
fi

echo
echo Japanese help file installation completed.
echo

exit $x
