#
# ident "@(#)postinstall.src	1.5 04/10/22 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 "$CLIENT_BASEDIR" ]; then CLIENT_BASEDIR="/opt"; fi
if [ -z "$BASEDIR" ]; then BASEDIR="$PKG_INSTALL_ROOT$CLIENT_BASEDIR"; fi

set -u

set -e

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

#
# Edit pam.conf to add lines for utnsclogin and utgulogin.
#

PAM_CONF="$PKG_INSTALL_ROOT/etc/pam.conf"

SUNWUTLIB="$BASEDIR/SUNWut/lib"
SRLIB_GU="$CLIENT_BASEDIR/SUNWut/lib/sunray_get_user.so.1"

NSCLOGIN=utnsclogin
GULOGIN=utgulogin

SRTAG="SunRay Server Software"

OS_REL=`uname -r`
NEW_STACK=true

if [ "$OS_REL" = "5.8" ]; then
  NEW_STACK=false
fi

# Set the utnsclogin entries to have get_user on the top of the stack,
# followed by the authentication entries as defined in dtlogin (or other)
#
# We assume that we can execute utpamcfg from the installed location on
# this machine.  In general this might not be true because we could have
# just installed, say, a SPARC binary package into 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
# utpamcfg is a shell script so we can get away with running it now.
# "Bourne Shell -- Write Once, Run Anywhere".

$SUNWUTLIB/utpamcfg -c $NSCLOGIN -t dtlogin -n $NEW_STACK -T "$SRTAG -- $NSCLOGIN" -P "$PAM_CONF"
$SUNWUTLIB/utpamcfg -a $NSCLOGIN -m $SRLIB_GU -M property=username -f requisite -T "$SRTAG -- $NSCLOGIN" -P "$PAM_CONF"

isguconf=`sed -n  's/^.*utgulogin//p' $PAM_CONF`

if [ -z "$isguconf" ]; then
  echo "#added to $GULOGIN by $SRTAG -- $GULOGIN" >>$PAM_CONF
  echo "$GULOGIN  auth requisite $SRLIB_GU property=username" >>$PAM_CONF
  echo "$GULOGIN  auth requisite $SRLIB_GU token=auth,JavaBadge " >>$PAM_CONF
  echo "$GULOGIN  auth required $SRLIB_GU prompt" >>$PAM_CONF
fi

exit 0
