#!/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/fips/0.9.8/lib -name "lib*" -type f`
	lib_list="$lib_list "`find /opt/openssl/fips/0.9.8/lib -name "#lib*" -type f`

	# List the Command line tool
	cmd_line_tool="/opt/openssl/fips/0.9.8/bin/openssl /opt/openssl/fips/0.9.8/bin/openssl.fipsonly "
	cmd_line_tool="${cmd_line_tool} /opt/openssl/fips/0.9.8/bin/#openssl /opt/openssl/fips/0.9.8/bin/#openssl.fipsonly "
	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 "\nNOTE:    ${files} cannot be deleted "
			echo "          because the following processes have it loaded:"
			echo "          ${process_ids}"
			echo "          ${files} will be moved to /opt/openssl/fips/0.9.8/old directory."
		fi
	done
fi

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

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

