#
#	preinstall script for explorer data collector
#
#  Determine if SUNWexplo is already installed.
# Get version of package
OldPkgVers=`pkginfo -l SUNWexplo.\*|grep VERSION: |nawk -F: '{ print $2 }'`
if [ ${?} = "0" ]
then			# Check for <explorer_install_dir>/etc directory
  EXP_INSTALL_DIR=`/usr/bin/pkginfo -r SUNWexplo.\*`
  if [ -d ${EXP_INSTALL_DIR}/etc ]
  then 		# Check for /etc/opt/SUNWexplo already existing
    if [ -d /etc/opt/SUNWexplo ]
    then 		# Verify /etc/opt/SUNWexplo is writeable by root
      if [ -w /etc/opt/SUNWexplo ]
      then  		# Check for individual files in /etc/opt/SUNWexplo
        for FILE in cmd.txt instinfo/install_info saninput.txt scinput.txt t3input.txt
        do
          if [ -f /etc/opt/SUNWexplo/${FILE} ]
          then 
            cd ${EXP_INSTALL_DIR}
            if [ -f ${FILE} ]
            then
	      mv /etc/opt/SUNWexplo/${FILE} /etc/opt/SUNWexplo/${FILE}.bkp.`date +%m%d%Y`
              echo "File /etc/opt/SUNWexplo/${FILE} was moved to /etc/opt/SUNWexplo/${FILE}.bkp.`date +%m%d%Y`"
            else
              echo "File ${FILE} is not in ${EXP_INSTALL_DIR}.  It does not need relocation."
            fi
          else
            echo "File /etc/opt/SUNWexplo/${FILE} does not exist."
          fi
        done
      else
        echo "Directory /etc/opt/SUNWexplo is not writable."
      fi
    else  
      echo "Directory /etc/opt/SUNWexplo does not exist.  It will be created."
      mkdir -p /etc/opt/SUNWexplo/default /etc/opt/SUNWexplo/instinfo
    fi
    echo "Copying ${EXP_INSTALL_DIR}/etc directory's contents to /etc/opt/SUNWexplo."
    cd ${EXP_INSTALL_DIR}
    for FILE in cmd.txt default/explorer instinfo/install_info saninput.txt scinput.txt t3input.txt
    do
      echo "EXP_INSTALL_DIR is ${EXP_INSTALL_DIR}"
      echo "FILE is ${FILE}"
      if [ -f etc/${FILE} ]
      then
        cp etc/${FILE} /etc/opt/SUNWexplo/${FILE}
        if [ ${?} = "0" ]
        then # Copy successful
          /usr/bin/rm etc/${FILE}
          echo "Copied ${FILE} to /etc/opt/SUNWexplo and removed"
          if [ ${FILE} = "instinfo/install_info" ]
          then
            /usr/bin/rmdir etc/instinfo
          fi
        else # Copy unsuccessfull
          echo "File ${EXP_INSTALL_DIR}/etc/${FILE} not copied and removed."
        fi
      else
        echo "File <explorer_install_dir>/etc/${FILE} does not exist."
      fi
    done
  fi
else # Package SUNWexplo not installed on this server.
#  echo "Directory ${EXP_INSTALL_DIR}/etc does not exist."
echo "Package SUNWexplo not yet installed."
fi
