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

set -u

function disable {
    
    typeset SERVICE=utsvtreg
	
    #
    # 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=$SERVICE
    for F in $INITFILES
    do
	chkconfig --del $F > /dev/null
    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="K97utsvtreg"
	for F in $KILLFILES
	do
	   rm -f $ETCINIT/rcS.d/$F
	   rm -f $ETCINIT/rc1.d/$F
	   rm -f $ETCINIT/rc0.d/$F
	done
    fi
    
    /etc/opt/SUNWutsvt/utsvtd remove
    rm -f /var/opt/SUNWutsvt/utsvtd.log
    
    return 0


}

function enable {

    
    typeset SERVICE=utsvtreg
    

    #
    # 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=$SERVICE
    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="K97utsvtreg"
	for F in $KILLFILES
	do
	    typeset INITF=`echo $F | sed -e "s/^K..//"`

	    rm -f $ETCINIT/rcS.d/$F
	    rm -f $ETCINIT/rc1.d/$F
	    rm -f $ETCINIT/rc0.d/$F

	    ln -s ../$INITF $ETCINIT/rcS.d/$F
	    ln -s ../$INITF $ETCINIT/rc1.d/$F
	    ln -s ../$INITF $ETCINIT/rc0.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="For SunOS: Enables/Disables service and imports/deletes SMF manifest; For Linux: installs/uninstalls RC scripts and invokes utsvtd remove"


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