#
# ident "@(#)preinstall.src	1.5 05/05/26 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
#

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

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

set -u

# This script attempts to clean up the creation of a dtsession
# specific properties file that earlier versions of SUNWutps
# created. This file was created in the locale-specific "C"
# directory and was the root cause of bug: 4746096.
#
# This cleanup will fix the problem when upgrading from SRSS 1.3
# patch or SRSS 2.0 beta, both of which created this file.

MOD="`basename $0`"

TMP_SR="$PKG_INSTALL_ROOT/var/run/$MOD.$$"

# dtsession autounlock from PAM
#
USR_CDE_DEFAULTS="$PKG_INSTALL_ROOT/usr/dt/app-defaults/C"
ETC_CDE_DEFAULTS="$PKG_INSTALL_ROOT/etc/dt/app-defaults/C"
DTSESSION="Dtsession"

# Remove the property that tells dtsession that it's OK to
# unlock the screen without requiring user input if the PAM
# module has validated the user.
#
# Once this property is removed, compare the file in /etc/dt
# with the one in /usr/dt, and if they are not different,
# then remove the file in /etc/dt.

if test -f $ETC_CDE_DEFAULTS/$DTSESSION ; then # {
  egrep -vi 'noPamPromptNoLock' $ETC_CDE_DEFAULTS/$DTSESSION >$TMP_SR

  mv $TMP_SR $ETC_CDE_DEFAULTS/$DTSESSION

  # Test to see if the files are different. If not, then remove
  # the version that is in /etc/dt and clean up the directories.
  # The test is done by first converting all newlines to space,
  # and then doing a diff that ignores spaces (and tabs). This
  # will prevent any wayward newlines from giving us a false
  # comparison result.
  #
  E_FILE=$TMP_SR.etc.$DTSESSION
  U_FILE=$TMP_SR.usr.$DTSESSION

  tr '\n' ' ' <$ETC_CDE_DEFAULTS/$DTSESSION >$E_FILE
  tr '\n' ' ' <$USR_CDE_DEFAULTS/$DTSESSION >$U_FILE

  if diff -w $E_FILE $U_FILE >/dev/null 2>/dev/null ; then
    #
    # Files in /etc/dt and /usr/dt are the same, so first remove
    # the file in /etc/dt and then remove any empty dirs in there.
    #
    rm $ETC_CDE_DEFAULTS/$DTSESSION
    rmdir -p $ETC_CDE_DEFAULTS >/dev/null 2>/dev/null
  fi

  # clean up the comparison files
  rm $E_FILE $U_FILE

fi # }

exit 0
