#
# ident "@(#)preremove.src	1.13 05/03/21 SMI"
#
# Copyright 2004, 2005 Sun Microsystems, Inc.  All rights reserved.
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin
SVCADM="/usr/sbin/svcadm"
SVCCFG="/usr/sbin/svccfg"
UTRCMD_FMRI="svc:/network/utrcmd/tcp"
UTRCMD_MANIFEST_PATH="/var/svc/manifest/network/utrcmd-tcp.xml"

if [ -z "$PKG_INSTALL_ROOT" ]; then PKG_INSTALL_ROOT=""; fi
if [ -z "$BASEDIR" ]; then BASEDIR="/opt"; fi

set -u

# Remove files created as side-effects of 
# scripts delivered by this package.
#

DIR="$PKG_INSTALL_ROOT/etc/opt/SUNWut"

FILES=""
FILES="$FILES $DIR/terminals"
FILES="$FILES $DIR/auth.props.bu"
FILES="$FILES $DIR/policy/utpolicy"
FILES="$FILES $DIR/policy/utpolicy.bu"

rm -f $FILES

# Run utrepair to remove modifications from all CDE / Solaris files 
# for use with Sun Ray
#
SUNWUTLIB="$BASEDIR/SUNWut/lib"
PROTODIR="$SUNWUTLIB/prototype"

# List of files to be updated by utrepair
#
MODFILES="/usr/dt/config/Xstartup /usr/dt/config/Xsetup /usr/dt/config/Xreset /usr/openwin/server/etc/OWconfig /etc/inet/services"
XINETD_DIR=/etc/xinetd.d
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"
  if [ -n "$PKG_INSTALL_ROOT" ] ; then

    # We assume that we can execute utrepair from its installed location on
    # this machine.	 In general this might not be true because we could
    # be about to uninstall, say, a SPARC binary package from an alternative
    # root while executing the packaging tools (and therefore this script)
    # on a a box with some other architecture.  However, we happen to know
    # that utrepair is a shell script so we can get away with running it now.
    #
    # Tell it that its prototypes and target files are in the alternative
    # root.

     ARGS="-R $PKG_INSTALL_ROOT -d $PROTODIR $ARGS"
  fi

  $SUNWUTLIB/utrepair $ARGS > /dev/null 2>&1
fi
if [ -f $SVCADM ]; then
	if [ -n "$PKG_INSTALL_ROOT" ]; then
		echo "***********************************************************************"
		echo "SRSS is being uninstalled from an alternate root filesystem"
		echo "Please run the following commands in the alternate root after uninstall"
		echo "svcadm disable -s $UTRCMD_FMRI"
		echo "svccfg delete $UTRCMD_FMRI"
		echo "rm -f $UTRCMD_MANIFEST_PATH"
		echo "***********************************************************************"
	else
		$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
fi

# Remove the xkb directory that we constructed (linux only)
rm -rf $SUNWUTLIB/xkb

# Always succeeds
exit 0
