#
# ident "@(#)preremove.src	1.4 05/09/29 SMI"
#
# Copyright 2004-2005 Sun Microsystems, Inc.  All Rights Reserved.
# Use is subject to licence terms.
#

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

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

set -u

#
# kill storage service daemons if alive 
# This should only be done when installing on the local system
#

if [ -z "$PKG_INSTALL_ROOT" ]; then
	if [ -x /etc/init.d/utstorage ]; then
		/etc/init.d/utstorage stop
	fi
fi

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="utstorage"
    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
fi

echo "### successfully ended Sun Ray storage services"

exit 0
