#!/bin/sh
##
# $Id: preremove,v 1.3 1999/02/18 15:51:59 georgeg Exp $
#
# clean /etc/services
#

init_dir=/etc/init.d
SERVICES=/etc/services
HPCROOT=${BASEDIR}

echo ""
echo "#"
echo "# Executing Sun LSF pre-remove script."
echo "#"

if [ ! -f /tmp/HPC_LSF_MOUNTED ]
then
    if [ -d $BASEDIR/SUNWlsf/conf/lsbatch/* ]
    then
        rm -r $BASEDIR/SUNWlsf/conf/lsbatch/*
    fi

    if [ -d $BASEDIR/SUNWlsf/conf/* ]
    then
        rm -r $BASEDIR/SUNWlsf/conf/*
    fi

    if [ -d $BASEDIR/SUNWlsf/work/* ]
    then
        rm -r $BASEDIR/SUNWlsf/work/*
    fi

    if [ -d $BASEDIR/SUNWlsf/logs/* ]
    then
        rm -r $BASEDIR/SUNWlsf/logs/*
    fi

    if [ -f $BASEDIR/SUNWlsf/bin/sparc7/Install.log ]
    then
        rm $BASEDIR/SUNWlsf/bin/sparc7/Install.log
    fi

    if [ -f $BASEDIR/SUNWlsf/etc/Install.log ]
    then
        rm $BASEDIR/SUNWlsf/etc/Install.log
    fi
fi

#
# Output message stating that the LSF_SHARED_LOC directory will NOT be remove
#

/usr/bin/echo "THE LSF_SHARED_LOC directory, $LSF_SHARED_LOC will NOT be deleted.\n"
/usr/bin/echo "If you wish to remove this directory please delete it manually.\n"


#
# If LSF_SKIP_POSTINSTALL exits, exit immediately
#
if [ -f "/tmp/LSF_SKIP_POSTINSTALL" ]; then
  exit 0
fi

#
# Make sure the root directory exists...
#

if [ ! -d $HPCROOT ]; then
        echo "ERROR: LSF was not properly installed, aborting..."
        exit 1
fi

#
# Stop the daemons
#
if [ -x $init_dir/lsf ]; then
        echo " * Stopping LSF daemons"
        $init_dir/lsf stop
fi

found=`grep "lim             [0-9]*\/udp        # LSF load information manager" $SERVICES`
if [ -n "$found" ]
then
  sed -e '/lim             [0-9]*\/udp        # LSF load information manager/d' \
   < $SERVICES > /tmp/tmp_lsf.$$
  mv /tmp/tmp_lsf.$$  $SERVICES
fi

found=`grep "res             [0-9]*\/tcp        # LSF remote execution server" $SERVICES`
if [ -n "$found" ]
then
  sed -e '/res             [0-9]*\/tcp        # LSF remote execution server/d' \
   < $SERVICES > /tmp/tmp_lsf.$$
  mv /tmp/tmp_lsf.$$  $SERVICES
fi

found=`grep "mbatchd         [0-9]*\/tcp        # LSF master lsbatch daemon" $SERVICES`
if [ -n "$found" ]
then
  sed -e '/mbatchd         [0-9]*\/tcp        # LSF master lsbatch daemon/d' \
   < $SERVICES > /tmp/tmp_lsf.$$
  mv /tmp/tmp_lsf.$$  $SERVICES
fi

found=`grep "sbatchd         [0-9]*\/tcp        # LSF slave lsbatch daemon" $SERVICES`
if [ -n "$found" ]
then
  sed -e '/sbatchd         [0-9]*\/tcp        # LSF slave lsbatch daemon/d' \
   < $SERVICES > /tmp/tmp_lsf.$$
  mv /tmp/tmp_lsf.$$  $SERVICES
fi

found=`grep "ident           [0-9]*\/tcp         auth tap        # identd authentication (LSF)" $SERVICES`
if [ -n "$found" ]
then
  sed -e '/ident           [0-9]*\/tcp         auth tap        # identd authentication (LSF)/d' \
   < $SERVICES > /tmp/tmp_lsf.$$
  mv /tmp/tmp_lsf.$$  $SERVICES
fi


if [ ! -f /tmp/HPC_LSF_MOUNTED ]
then
    if [ -d $BASEDIR/SUNWlsf/conf/lsbatch/* ]
    then
        rm -r $BASEDIR/SUNWlsf/conf/lsbatch/*
    fi

    if [ -d $BASEDIR/SUNWlsf/conf/* ]
    then
        rm -r $BASEDIR/SUNWlsf/conf/*
    fi

    if [ -d $BASEDIR/SUNWlsf/work/* ]
    then
        rm -r $BASEDIR/SUNWlsf/work/*
    fi

    if [ -d $BASEDIR/SUNWlsf/logs/* ]
    then
        rm -r $BASEDIR/SUNWlsf/logs/*
    fi

    if [ -f $BASEDIR/SUNWlsf/bin/sparc7/Install.log ]
    then
        rm $BASEDIR/SUNWlsf/bin/sparc7/Install.log
    fi

    if [ -f $BASEDIR/SUNWlsf/etc/Install.log ]
    then
        rm $BASEDIR/SUNWlsf/etc/Install.log
    fi
fi


/usr/bin/rm -f /etc/lsf.conf 
/usr/bin/rm -f /etc/rc3.d/S95lsf
/usr/bin/rm -f /etc/rc2.d/K05lsf
/usr/bin/rm -f $init_dir/lsf

