#
# ident "@(#)preremove.src	1.18	05/06/01 SMI"
#
# Copyright 1999-2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin

if [ -z "$PKG_INSTALL_ROOT" ]; then PKG_INSTALL_ROOT=""; fi
if [ -z "$CLIENT_BASEDIR" ]; then CLIENT_BASEDIR="/"; fi
if [ -z "$BASEDIR" ]; then BASEDIR="$PKG_INSTALL_ROOT$CLIENT_BASEDIR"; fi

set -eu

#
# Clean up /var/opt/
#

PKGID=SUNWut
#
# VAROPTDIR, the /var/opt path without the prepended PKG_INSTALL_ROOT
# path. ROOT_VAROPTDIR includes the PKG_INSTALL_ROOT path.  This is
# needed mainly to support alternative root installation.
VAROPTDIR=/var/opt/$PKGID
ROOT_VAROPTDIR=$PKG_INSTALL_ROOT/var/opt/$PKGID

#
# no need to prepend the PKG_INSTALL_ROOT to UTLIBDIR because it's
# only used within the crontab.
UTLIBDIR=/opt/$PKGID/lib

#
# Remove symlinks
#
rm -rf $ROOT_VAROPTDIR/tokens $ROOT_VAROPTDIR/idle $ROOT_VAROPTDIR/displays
rm -rf $ROOT_VAROPTDIR/dispinfo
rm -rf $ROOT_VAROPTDIR/snmp 2> /dev/null

#
# Clean up directories
#
for dir in $ROOT_VAROPTDIR/log $ROOT_VAROPTDIR/cgitokens; do
  if [ -d "$dir" ]; then
    find $dir -type f -exec rm {} \;
  fi
done

#
# Clean up /etc/opt/
#

ETCOPTDIR=$PKG_INSTALL_ROOT/etc/opt/$PKGID

rm -f $ETCOPTDIR/utadmin.conf
rm -f $ETCOPTDIR/utadmin.pw
rm -f $ETCOPTDIR/gmSignature
rm -f $ETCOPTDIR/ut_disable_*
rm -f $ETCOPTDIR/jre
rm -f $ETCOPTDIR/guijre
[ -d $ETCOPTDIR/net ] && find $ETCOPTDIR/net -type f -exec rm -f {} \;

#
# Cleanup /etc/dt
#
# NOTE: these directoires do not exist on Linux
EDTDIR=$PKG_INSTALL_ROOT/etc/dt/config

for i in Xservers Xconfig; do
  #
  # Remove the symlink made by utacleanup
  #
  if [ -h $EDTDIR/$i ]; then
    rm -f $EDTDIR/$i
  fi

  #
  # If a saved "prototype" template file exists, move it into place as
  # the new site-customised config file.
  #
  proto=$EDTDIR/$i.$PKGID.prototype
  if [ -f $proto ]; then
    mv -f $proto $EDTDIR/$i
  fi
done

#
# cleanup the syslog entries.  Only do this on local system.
#
if [ -z "$PKG_INSTALL_ROOT" ] ; then
	$UTLIBDIR/utctl disable
fi
rm -f $ETCOPTDIR/utctl.conf
rm -f $ETCOPTDIR/utctl.run

OS=`uname -s`
#
# For Linux only.  We need to remove the links to init.d files using
# chkconfig.  This is something else we can't do in an altroot install,
# but luckily Linux doesn't support altroot installs anyway.
#
if [ $OS = "Linux" ]; then
    INITFILES="utsvc utacleanup utsyscfg"
    for F in $INITFILES
    do
	chkconfig --del $F > /dev/null
    done
    #
    # On SuSE/JDS, chkconfig (based on insserv) does not remove Kill links in
    # lower runlevels.  They must be removed manually.
    #
    if [ -f /etc/SuSE-release ]; then
	# we are installing on either SuSE or JDS
	ETCINIT=/etc/rc.d
    	for F in $INITFILES
    	do
	    rm -f $ETCINIT/rc4.d/K??$F
	    rm -f $ETCINIT/rc3.d/K??$F
	    rm -f $ETCINIT/rc2.d/K??$F
	    rm -f $ETCINIT/rc1.d/K??$F
    	done
    fi

    # cleanup the log directory on Linux
    ROOT_VAR_LOG=$PKG_INSTALL_ROOT/var/log/$PKGID
    rm -f $ROOT_VAR_LOG/*
fi
exit 0
