#!/bin/ksh
#----------------------------------------------------------------------------
#                                            COPYRIGHT DASSAULT SYSTEMES 2009
#----------------------------------------------------------------------------
# CREATED : 2009/07/06
#----------------------------------------------------------------------------

# Set variables
#set -x
export OSDS=linux_a64
[[ $(uname -m) = "aarch64" ]] && export OSDS="linux_m64"

CURPWD=`pwd` || exit 1
[[ $0 = /* ]] && STARTDIR=$0 || STARTDIR=`echo $CURPWD/$0 | sed 's%/\./%/%g'`
START=${STARTDIR##*/}
export STARTDIR=${STARTDIR%/*}
echo $STARTDIR

for i in $*
do
   if [[ $i = -h ]] 
    then 
      HELP=TRUE
   elif [[ $i == -aws ]]
    then
      export DSLAWSID=TRUE
  fi
done

if [[ $HELP = TRUE ]]
then
    # Help
    ${STARTDIR}/DSYLicServINSTB -h
 
else
  # Check root, and perform su if necessary
  #----------------------------------------
  if [[ `PATH=$PATH:/usr/ucb whoami` = root ]] ; then
    :
  else
     pbsu=$(eval echo \$$#)
     if [[ $pbsu = pbsu ]] ; then
      echo "Problem when trying to become super-user (root)"
      echo "Please try to become super-user by running following commands:"
      echo "       login root"
      echo "       cd /"
      echo "       $STARTDIR/$START $*"
      echo
      exit 1
     fi
     echo "Log on as super-user (root) before installing"
     echo
     su - root -c "$STARTDIR/$START $* pbsu"
     exit $?
  fi

  #Installation
  [[ -z $DISPLAY ]] && export DISPLAY=`uname -n`:0
  ${STARTDIR}/DSYLicServINSTB $*

fi


