#
# ident "@(#)postinstall.src	1.5 04/06/29 SMI"
#
# Copyright 2001,2002,2004 Sun Microsystems, Inc.  All rights reserved.
#

# postinstall script for SUNWutscr - Sun Ray smartcard APIs
#	Configure the Sun Ray PC/SC client driver into PC/SC.

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

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

set -u

BASEDIR="`pkginfo -R ${PKG_INSTALL_ROOT} -r SUNWutscr`"

PCSC_LIB="${PKG_INSTALL_ROOT}/usr/local/lib"
PCSC_CLNTDRV_CONFIG_FILE="$PCSC_LIB/pcsc_clndtdrv.cfg"
PCSCLITE_LIB="libpcsclite.so"
PCSCLITE_LIB_FP="$PCSC_LIB/$PCSCLITE_LIB"

SUNWUTLIB="${BASEDIR}/SUNWut/lib"
SRCOMPCSC_LIB_BASE="libsrcompcsc.so"
SRCOMPCSC_LIB_VERSION="1"
SRCOMPCSC_LIB="${SRCOMPCSC_LIB_BASE}.${SRCOMPCSC_LIB_VERSION}"
SRCOMPCSC_LIB_FP="$SUNWUTLIB/$SRCOMPCSC_LIB"

TMP=/var/run/SUNWutscr.$$

    #
    # make sure that PC/SC is installed - if not, then the admin will
    # have to install it and configure the Sun Ray drivers manually
    # This isn't really an error, just an inconvienience.
    #
    if test ! -f "$PCSCLITE_LIB_FP" ; then
	echo "PC/SC not installed, you must first install PC/SC and then"
	echo "manually configure the Sun Ray smartcard reader driver"
	echo "components for PC/SC."
	exit 0
    fi

    #
    # If the PC/SC client driver configuration file exists, remove any
    # entries for the Sun Ray SRCOM PC/SC client driver.
    #
    if test -f "$PCSC_CLNTDRV_CONFIG_FILE" ; then
	egrep -v "$SRCOMPCSC_LIB_BASE" "$PCSC_CLNTDRV_CONFIG_FILE" >$TMP
	mv $TMP "$PCSC_CLNTDRV_CONFIG_FILE"
    fi

    #
    # Add an entry for the Sun Ray SRCOM PC/SC client driver.
    # This will also create the PC/SC client driver configuration
    # file if it doesn't already exist.
    #
    echo "$SRCOMPCSC_LIB_FP" >>"$PCSC_CLNTDRV_CONFIG_FILE"

    echo "Sun Ray PC/SC client driver: $SRCOMPCSC_LIB added to PC/SC"

    exit 0
