#!/sbin/sh
########################################
#  Product: OpenSSL
#  Fileset: Latest
#  checkremove
#  (c) Copyright Hewlett-Packard Company
####################################
UTILS="/usr/lbin/sw/control_utils"
    if [[ ! -f $UTILS ]]
    then
        echo "ERROR: Cannot find $UTILS"
        exit 1
    fi
    . $UTILS
exitval=$SUCCESS
####################################
# Abort swremove operation if some process has either of 
# the openssl libraries loaded or openssl command line tool is running
####################################

ERROR=0

# Check the swremove operation.

ps -eax | grep swremove | grep OPENSSL-SRC 2> /dev/null 1> /dev/null

if [ $? -ne 0 ]
then

	# List the shared librariy names
	lib_list=`find /opt/openssl/0.9.7 -name "lib*" -type f`
	lib_list="$lib_list "`find /opt/openssl/0.9.7 -name "#lib*" -type f`
	lib_list="$lib_list "`find /opt/openssl/0.9.8 -name "lib*" -type f`
	lib_list="$lib_list "`find /opt/openssl/0.9.8 -name "#lib*" -type f`

	# List the Command line tool
	cmd_line_tool="/opt/openssl/0.9.7/bin/openssl /opt/openssl/0.9.8/bin/openssl "
	cmd_line_tool="${cmd_line_tool} /opt/openssl/0.9.7/bin/#openssl /opt/openssl/0.9.8/bin/#openssl "
	cmd_line_tool="ls ${cmd_line_tool} 2>/dev/null"

	for files in ${lib_list} ${cmd_line_tool}
	do
		process_ids=`fuser ${files} 2>/dev/null`
		if [ "$process_ids" != "" ]
		then
			ERROR=1
			echo "\nERROR:    ${files} cannot be removed"
			echo "          because the following processes have it loaded:"
			echo "          ${process_ids}"
		fi
	done
fi

if [ $ERROR -eq 1 ]
then
	exit 1
fi

####################################
exit $exitval
####################################

