# Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved.
# @(#)preremove	1.4	10/24/03	SMI

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

set -u

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

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

/bin/rm -f $DIR/terminals \
	$DIR/auth.props.bu \
	$DIR/policy/utpolicy \
	$DIR/policy/utpolicy.bu

# 
# Run utrepair to remove modifications from all CDE / Solaris files 
# for use with Sun Ray
#

SUNWUTLIB="${PKG_INSTALL_ROOT}${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  /etc/inet/inetd.conf"

if [ -x ${SUNWUTLIB}/utrepair ]; then
	
	#
	# Build the argument list for utrepair
	#
	repairargs="-r ${MODFILES}"

	${SUNWUTLIB}/utrepair ${repairargs} 
fi

#
# Edit pam.conf to remove any configuration for utnsclogin
# and utgulogin
#

NSCLOGIN=utnsclogin
GULOGIN=utgulogin
SRTAG="SunRay Server Software"

#
# Edit pam.conf to remove any configuration for utnsclogin
#

ETCFILE="/etc/pam.conf"
TMPR="/etc/tmp.$$"

if [ -x ${SUNWUTLIB}/utpamcfg ]; then
	${SUNWUTLIB}/utpamcfg -u $NSCLOGIN -T "$SRTAG -- $NSCLOGIN"
	${SUNWUTLIB}/utpamcfg -u $GULOGIN -T "$SRTAG -- $GULOGIN"
else
	isconf=`sed -n  's/^.*utnsclogin//p' $ETCFILE`
	if [ "$isconf" ]; then
        	sed 's/^.*utnsclogin.*$//p' $ETCFILE > $TMPR
        	/usr/bin/cp $TMPR $ETCFILE
        	/usr/bin/rm $TMPR
	fi
fi

# Always succeeds
exit 0;
