#!/bin/bash
###################################
###  PRE REMOVE SCRIPT          ###
###################################
if [ "$SIS_DEBUG_MODE" = "true" ]; then
  debug_logfile=/var/tmp/sdcss-kmod_preun$$.log;
  exec 1<&-       # Close STDOUT file descriptor
  exec 2<&-       # Close STDERR FD
  exec 1<>$debug_logfile # Open STDOUT as $LOG_FILE file for read and write.
  exec 2>&1       # Redirect STDERR to STDOUT
  set -x          # Turn on shell debugging
fi

BASEDIR=/usr/lib/symantec
AGENT_TYPE=5

INFUNLIB=${BASEDIR}/sdcssagent/lib/instfunlib-kmod
RCFUNCTION=/etc/symantec/sis/rc.functions
INSTATE=PREUN
if [ ! -f $INFUNLIB ] || [ ! -f $RCFUNCTION ] || \
   ( [ -d /etc/sisips ] && [ "`ls -1 /etc/sisips 2>/dev/null`" ] && [ "`ls -1 /etc/sisips/testforprevention 2>/dev/null`" = "" ] ); then
   printf "\nAborting uninstall as Agent does not seem to be installed correctly."
   printf "\nFile \"$INFUNLIB\" or \"$RCFUNCTION\" is inaccessible, or is missing."
   printf "\nIf protection is enabled, it must be disabled before uninstalling."
   printf "\nOtherwise, a manual uninstall must be performed to remove this software."
   printf "\nRefer to product documentation to perform a Manual Uninstall.\n\n"
   exit 1
else 
   . $INFUNLIB
   . $RCFUNCTION
fi

# For dpkg (ubuntu) and rpm upgrades,  this is run during package upgrade.
# We don't to run this script on upgrade as it does indiscriminate cleanup
if [ "$1" = "upgrade" ] || [ "$1" = "1" ]; then exit 0; fi

cd /var/tmp

logmsg "#--- Start kmod pre-remove <pid=$$> -------"
uninstallKernelModule
logmsg "#--- Stop kmod pre-remove <pid=$$> -------"



