#!/bin/ksh

###############################################
# Sourcing macros
DIRNAME=/usr/bin/dirname
. `$DIRNAME $0`/../lib/psmacros
###############################################

BELL_CHAR='\a'

PS_STATE_FILE="$PS_CONFIG_DIR/PSConfig.properties"
JCIFS_PKGINFO_FILE="/var/sadm/pkg/SUNWjcifs/pkginfo"

###############################################
# Get configuration from file
###############################################
GrabConfig() {
  GRABCONFIG_FILE=$1
  GRABCONFIG_KEY=$2
  GRABCONFIG_SEPARATOR=$3

  ANSWER=`$GREP "^$GRABCONFIG_KEY$GRABCONFIG_SEPARATOR" $GRABCONFIG_FILE | $UNIQ | $SED -e "s/$GRABCONFIG_KEY$GRABCONFIG_SEPARATOR//"`
}

###############################################
# Main
###############################################

if [ `$ID | $AWK '{print $1}'` != "uid=0(root)" ]; then
  $ECHO "You must be root user. $BELL_CHAR"
  exit 1
fi

if [ ! -f $PS_STATE_FILE ]; then
  $ECHO "Error: $PS_STATE_FILE does not exist. $BELL_CHAR"
  exit 1
fi

GrabConfig $PS_STATE_FILE "BASEDIR" "="
if [ "$ANSWER" != "" ]; then
  PS_BASEDIR=$ANSWER
else
  $ECHO "Error: Cannot determine BASEDIR. $BELL_CHAR"
  exit 1
fi

if [ -f $JCIFS_PKGINFO_FILE ]; then
  GrabConfig $JCIFS_PKGINFO_FILE "BASEDIR" "="
  $LN -s $ANSWER/jcifs/lib/jcifs-0.7.3.jar $PS_BASEDIR/$PS_PRODUCT_DIR/web-src/WEB-INF/lib/jcifs-0.7.3.jar
  if [ "$OSTYPE" = "SunOS" ]; then
    $INSTALLF "SUNWpsnf" $PS_BASEDIR/$PS_PRODUCT_DIR/web-src/WEB-INF/lib/jcifs-0.7.3.jar
    $INSTALLF -f "SUNWpsnf"
  fi
fi

exit 0
