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

set -u

function disable {
    
    typeset SVCADM="/usr/sbin/svcadm"
    typeset SVCCFG="/usr/sbin/svccfg"
    typeset UTRCMD_FMRI="svc:/network/utrcmd/tcp"
    typeset UTRCMD_MANIFEST_PATH="/var/svc/manifest/network/utrcmd-tcp.xml"
    
   
# Remove files created as side-effects of 
# scripts delivered by this package.
#
    
    typeset FILES=""
    FILES="$FILES /etc/opt/SUNWut/terminals"
    FILES="$FILES /etc/opt/SUNWut/auth.props.bu"
    FILES="$FILES /etc/opt/SUNWut/policy/utpolicy"
    FILES="$FILES /etc/opt/SUNWut/policy/utpolicy.bu"
    
    rm -f $FILES
    
# Run utrepair to remove modifications from all CDE / Solaris files 
# for use with Sun Ray
#
    typeset SUNWUTLIB="/opt/SUNWut/lib"
    typeset PROTODIR="$SUNWUTLIB/prototype"
    
# List of files to be updated by utrepair
#
    typeset MODFILES="@(MODFILES)"
    typeset XINETD_DIR=/etc/xinetd.d
    typeset INETD_CONF=/etc/inet/inetd.conf
    if [ -d $XINETD_DIR ]; then
	# for RH server
	MODFILES="$MODFILES $XINETD_DIR/sunray_utrcmdd"
    fi
    if [ -f $INETD_CONF ]; then
	# for Solaris and JDS servers
	MODFILES="$MODFILES $INETD_CONF"
    fi
    
    if [ -x $SUNWUTLIB/utrepair ]; then
  # Build the argument list for utrepair
  #
	ARGS="-r $MODFILES"
	
	$SUNWUTLIB/utrepair $ARGS > /dev/null 2>&1
    fi
    if [ -f $SVCADM ]; then
	$SVCADM disable -s $UTRCMD_FMRI 1>/dev/null 2>&1
	$SVCCFG delete $UTRCMD_FMRI 1>/dev/null 2>&1
	rm -f $UTRCMD_MANIFEST_PATH
    fi
        
# Always succeeds
    return 0
    
}

function enable {

    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=" Runs utrepair to remove modifications from all CDE / Solaris files for use with Sun Ray and deletes files created as side-effects of scripts delivered by the uto package"


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