#!/bin/sh
#
# ident "@(#)preremove.src	1.4 04/09/13 SMI"
#
# Copyright 2001,2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

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

#
# This script is alternate install root clean.
# PKG_INSTALL_ROOT is only set on Solaris if the alternate install root
# is specified during uninstall.  On Linux, this script is invoked after
# 'chroot' to the alternate install root.
#
if [ -z "$PKG_INSTALL_ROOT" ]; then PKG_INSTALL_ROOT=""; fi

set -u

VAR_OPT_DIR="$PKG_INSTALL_ROOT/var/opt/SUNWut/srds"
ETC_OPT_DIR="$PKG_INSTALL_ROOT/etc/opt/SUNWut/srds"

#
# For Linux only.  We need to remove the links to init.d files using chkconfig.
#
OS=`uname -s`
if [ $OS = "Linux" ]; then
    INITFILE="utds"
    chkconfig --del $INITFILE > /dev/null
    #
    # 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
	rm -f $ETCINIT/rc4.d/K??$INITFILE
	rm -f $ETCINIT/rc3.d/K??$INITFILE
	rm -f $ETCINIT/rc2.d/K??$INITFILE
	rm -f $ETCINIT/rc1.d/K??$INITFILE
    fi
fi

#
# Cleaning all generated files.
#
rm -f $VAR_OPT_DIR/log/*
rm -f $VAR_OPT_DIR/replog/*
rm -f $VAR_OPT_DIR/admin/*
rm -rf $VAR_OPT_DIR/dbm.ut
rm -rf $ETC_OPT_DIR/current/*

exit 0
