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

set -u

function disable {    
    
    # On Linux, we need to remove the links to init.d files using chkconfig.
    typeset 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
	typeset 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
    
#
# Cleaning all generated files.
#
    rm -f /var/opt/SUNWut/srds/log/*
    rm -f /var/opt/SUNWut/srds/replog/*
    rm -f /var/opt/SUNWut/srds/admin/*
    rm -rf /var/opt/SUNWut/srds/dbm.ut
    rm -rf /etc/opt/SUNWut/srds/current/*
    
    return 0
    
    
}

function enable {
#
# On Linux, this script is invoked after
# 'chroot' to the alternate install root.   
#
    typeset INITFILE="utds"
    chkconfig --add $INITFILE
    #
    # 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

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

	ln -s ../$INITFILE $ETCINIT/rc4.d/K30$INITFILE
	ln -s ../$INITFILE $ETCINIT/rc3.d/K30$INITFILE
	ln -s ../$INITFILE $ETCINIT/rc2.d/K30$INITFILE
	ln -s ../$INITFILE $ETCINIT/rc1.d/K30$INITFILE
    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="Uninstalls rc scripts. Removes generated files."


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