#!/bin/bash

export ACUXE_BIN_INSTALLATION_DIR=/opt/compaq/cpqacuxe/bld/
export LD_LIBRARY_PATH=${ACUXE_BIN_INSTALLATION_DIR}
export ACUXE_LOCK_FILES_DIR=/var/opt/compaq/locks/
${ACUXE_BIN_INSTALLATION_DIR}/mklocks.sh cpqacuxe
${ACUXE_BIN_INSTALLATION_DIR}/updsmh.sh


ACUXE_PASS_FAILED=0
if [ "$1" == "" ] || [ "$1" == "-R" ] || [ "$1" == "-d" ]; then
   PROCESSES=`ps -e|grep hpsmhd`
   if [ "$PROCESSES" = "" ]; then
      ACUXE_PASS_FAILED=1
   fi
fi

PROCESSES=`ps -e|egrep ".acuxebin|.hpacuscripting|.hpacucli"`
if [ "$PROCESSES" == "" ]; then
   $ACUXE_BIN_INSTALLATION_DIR/.acuxebin -mopup
fi

if [ "$ACUXE_PASS_FAILED" = 0 ]; then
   chmod ug+s ${ACUXE_BIN_INSTALLATION_DIR}ipcelmclient 2>/dev/null
   if [ '/usr/bin/tty -s' -o "$HPLSPINSTALL" = "TRUE" ]; then
      ${ACUXE_BIN_INSTALLATION_DIR}.acuxebin $*
      if [ "$1" == "-stop" ]
      then
         /etc/init.d/hpsmhd restart>/dev/null 2>&1
      fi
   else
      /usr/bin/X11/xterm -T xterm -hold -e ${ACUXE_BIN_INSTALLATION_DIR}.acuxebin $* 
      if [ "$?" != 0 ]; then
         ${ACUXE_BIN_INSTALLATION_DIR}.acuxebin $* 2>/dev/null|cat > /dev/null
      fi
   fi
else
   echo Executing ACU with this option requires the HP System Management Homepage to be installed and running.
   echo Please install hpsmh if it is not installed. 
   echo Please try to use \"/etc/init.d/hpsmhd start\" to start it.
   exit 1
fi
