#!/bin/ksh -p
#
# ident "@(#)utpkg-utstrctl.ksh	1.4 10/02/02 SMI"
#
# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

set -u

function disable {

#
# kill storage service daemons if alive 
# This should only be done when installing on the local system
#
    
    if [ -x /etc/init.d/utstorage ]; then
	/etc/init.d/utstorage stop
    fi
    
#
# On Linux 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.
#

    typeset 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
	typeset 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

    return 0
        
}

function enable {

#
# On Linux, we need to create 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.
#
    typeset INITFILES="utstorage"
    for F in $INITFILES
	do
	chkconfig --add $F
    done
#
# On SuSE/JDS, chkconfig (based on insserv) does not create Kill links in
# lower runlevels.  They must be created manually.
#
    if [ -f /etc/SuSE-release ]; then
# we are installing on either SuSE or JDS
	typeset ETCINIT=/etc/rc.d
	typeset KILLFILES="K02utstorage"
	for F in $KILLFILES
	  do
	  INITF=`echo $F | sed -e "s/^K..//"`

	  rm -f $ETCINIT/rc4.d/$F
	  rm -f $ETCINIT/rc3.d/$F
	  rm -f $ETCINIT/rc2.d/$F
	  rm -f $ETCINIT/rc1.d/$F

	  ln -s ../$INITF $ETCINIT/rc4.d/$F
	  ln -s ../$INITF $ETCINIT/rc3.d/$F
	  ln -s ../$INITF $ETCINIT/rc2.d/$F
	  ln -s ../$INITF $ETCINIT/rc1.d/$F
	done
    fi
    
    return 0

}


########################################################################
# Local Variables
# They must defined here to resolve some of the parameter resolution
# problem
########################################################################
local_variables() {
    return
}


########################################################################
#
# Configurable parameter
#
########################################################################
# NONE


########################################################################
#
# Variables used in the shared script utctl-shlib
#
########################################################################
DESCR="Stops utstorage service. Removes utstorage (and kills symlinks) from rc. "


########################################################################
#
# Execution starts here
#
PROGPATH=`dirname $0`
. $PROGPATH/utctl-shlib
