#!/bin/sh
#
# ident "@(#)preremove	1.3 01/10/26 SMI"
#
# Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
#
#
#	prepremove script for package: SUNWutds

# Exit codes for installation scripts 
e_ok=0      
e_fatal=1      # stop installation on this exit
e_warning=2    # Installation will go on. 
e_int=3        # Interrupted. Stop installation
e_reboot=10    # User must reboot after installation of all selected packages
e_rebootnow=20 # User must reboot right after installation of current package
               # To be added to one of the single-digit exit code above
# Trap interrupt
trap `exit $e_int` 15

AWK=/usr/bin/awk
ECHO=/usr/bin/echo
GREP=/usr/bin/grep
PS=/usr/bin/ps
WC=/usr/bin/wc
CRONTAB=/usr/bin/crontab

#
#	Stop running process(es)
#
if [ -f /etc/init.d/utdsd ]
then
	/etc/init.d/utdsd stop
fi
#
# kill the utpulld process
#
pid=`$PS -fe | $GREP lib/utpulld | $GREP -v grep | $AWK '{print $2}'`
if [ -n "$pid" ]
then
  kill -TERM $pid
fi
pid=`$PS -fe | $GREP lib/utpushd | $GREP -v grep | $AWK '{print $2}'`
if [ -n "$pid" ]
then
  kill -TERM $pid
fi

echo "\nPlease wait ...\c"
#
#
#      Cleaning all generated files, should be done by the pkgrm
#
rm -f /var/opt/SUNWut/srds/log/*
rm -f /var/opt/SUNWut/srds/replog/*
rm -f /var/opt/SUNWut/srds/admin/*
rm -fr /var/opt/SUNWut/srds/dbm.ut
# rm -rf /etc/opt/SUNWut/srds/previous
rm -rf /etc/opt/SUNWut/srds/current/*
#
# keep the database directory, if you want to remove it later just 
# uncomment the following line
rm -f /var/opt/SUNWut/srds/dbm.ut/*
#
echo ".\n"
#
# Remove any reference to utpushd and utpulld deamon in the crontab
#
TMPCRONTAB=/tmp/crontab.tmp
test -f "$TMPCRONTAB" && rm "$TMPCRONTAB"
$CRONTAB -l | grep -v "SUNWut/srds/lib/utpulld" > $TMPCRONTAB
$CRONTAB -l | grep -v "SUNWut/srds/lib/utpushd" > $TMPCRONTAB
$CRONTAB $TMPCRONTAB


exit $e_ok 

