#
# ident "@(#)preremove.src	1.9 04/10/21 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin

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

OS=`uname -s`
if [ $OS != "SunOS" ]; then
	# Only proceed to PAM section if uninstalling on Solaris
	exit 0
fi

# Edit pam.conf to remove any configuration for utnsclogin
# and utgulogin
#
NSCLOGIN=utnsclogin
GULOGIN=utgulogin
SRTAG="SunRay Server Software"
PAM_CONF="$PKG_INSTALL_ROOT/etc/pam.conf"

$SUNWUTLIB/utpamcfg -u $NSCLOGIN -T "$SRTAG -- $NSCLOGIN" -P "$PAM_CONF"
$SUNWUTLIB/utpamcfg -u $GULOGIN -T "$SRTAG -- $GULOGIN" -P "$PAM_CONF"

# Always succeeds
exit 0
