#!/bin/ksh -p
#
# ident "@(#)utpkg-utsvt-ctl.ksh	1.5 09/09/17 SMI"
#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

set -u

function disable {
    
    typeset SERVICE=utsvtreg
	
    OS=`uname -s`
    if [ $OS = "SunOS" ]; then
	#
	# For Solaris use SMF
	#
	/usr/sbin/svcadm disable $SERVICE
	/usr/sbin/svccfg delete -f  $SERVICE
    fi
    if [ $OS = "Linux" ]; then 
	#
	# For Linux only.  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
    fi
    
    /etc/opt/SUNWutsvt/utsvtd remove            
    
    return 0


}

function enable {

    
    typeset SERVICE=utsvtreg
    

    typeset OS=`uname -s`
    if [ $OS = "SunOS" ]; then
	#
	# For Solaris use SMF
	#
	typeset SMFSVCDIR=/var/svc/manifest/application
	typeset MANIFEST_FILE=${SERVICE}.xml
	/usr/sbin/svccfg -v import $SMFSVCDIR/$MANIFEST_FILE
	/usr/sbin/svcadm  -v enable $SERVICE
    fi
    if [ $OS = "Linux" ]; then 
	#
	# For Linux only.  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
	
	
    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
