#!/sbin/sh
####################################
#  Product: OpenSSL
#  Fileset: Latest
#  preinstall
#  (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
####################################
# Kill the prngd daemon
####################################
#kill_named_procs prngd KILL 1>/dev/null 2>/dev/null

####################################
# Setup config files
####################################
#newconfig_prep /opt/openssl/0.9.8/openssl.cnf
#newconfig_prep /opt/openssl/0.9.7/openssl.cnf

#newconfig_prep /opt/openssl/fips/0.9.8/openssl.cnf
#newconfig_prep /opt/openssl/fips/0.9.7/openssl.cnf

if [ ! -d /opt/openssl/fips ]; then
    mkdir -p /opt/openssl/fips  > /dev/null 2>&1
    chmod 555 /opt/openssl/fips >/dev/null 2>&1
    chown bin:bin /opt/openssl/fips >/dev/null 2>&1
fi

if [ -d /opt/openssl/fips/0.9.8 ]; then
cd /opt/openssl/fips/0.9.8
if [ $? -eq 0 ]; then

rm -rf old >/dev/null 2>&1

if [ ! -a /opt/openssl/fips/0.9.8/old ]; then
  mkdir old  > /dev/null 2>&1
  chmod 555 old  > /dev/null 2>&1
  chown bin:bin old  > /dev/null 2>&1
fi

for dirs in `ls`; do
  if [ ${dirs} = "old" ]; then
     continue
  fi
  rm -rf ${dirs} > /dev/null 2>&1
  if [ -a /opt/openssl/fips/0.9.8/${dirs} ]; then
     mv ${dirs} old/${dirs}_$$ >/dev/null 2>&1
  fi
done

rm -rf old >/dev/null 2>&1

cd - >/dev/null 2>&1
fi  #### check if cd /opt/openssl/fips/0.9.8 is successful
fi  #### check if -d /opt/openssl/fips/0.9.8

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

