#!/bin/sh
#
# Copyright (c) 1999-2005 Easysoft Ltd. All rights reserved.
#
# $Id: licshell 62 2005-08-09 10:57:59Z martin $
#
DIRNAME=`dirname $0`
if [ -x /bin/echo ];then
  ECHO="/bin/echo"
else
  if [ -x /usr/bin/echo ];then
    ECHO="/usr/bin/echo"
  else
    ECHO="echo"
  fi
fi
#
# echo interprets backslash chrs by default? POSIX says no.
#
test=`$ECHO "fred\c"`
if [ "$test" = "fred\c" ];then
  ECHO="$ECHO -e "
fi
#
# Overrides
#
if [ "$EASYSOFT_ROOT" != "" ];then
  ROOT="$EASYSOFT_ROOT"
else
  ROOT="/usr/local/easysoft"
fi
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOT/lib
export LD_LIBRARY_PATH
DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$ROOT/lib
export DYLD_LIBRARY_PATH
SHLIB_PATH=$SHLIB_PATH:$ROOT/lib
export SHLIB_PATH
LIBPATH=$LIBPATH:$ROOT/lib
export LIBPATH
#
# Warn user any generated licenses cannot be added to licenses file if the
# user does not have sufficient permission.
#
if [ ! -w . ]; then
  cat <<EOF

WARNING
You do not have write access to the current working directory so this program
will not be able to write out a license request file or any generated
licenses. If you generate a license request or a license these will be
displayed on screen instead.

Press the return key to continue.
EOF
read x
fi
if [ -r licenses.out ];then
  if [ ! -w licenses.out ]; then
  cat <<EOF

WARNING
The file licenses.out exists in the current working directory and you do
not have permission to remove/append/overwrite it. This program will be unable
to write out generated licenses so they will be display on screen instead.

Press the return key to continue.
EOF
  read x
  fi
fi
if [ -r license_request.txt ]; then
  if [ ! -w license_request.txt ]; then
  cat <<EOF

WARNING
The file license_request.txt exists in the current working directory and
you do not have permission to remove/append/overwrite it. This program will
be unable to write out a license request so it will be displayed on screen
instead.

Press the return key to continue.
EOF
  read x
  fi
fi
$DIRNAME/licclient $*
if [ -r licenses.out ];then
  $ECHO "It looks like licenses were obtained via the license application"
  $ECHO "These were placed in ./licenses.out."
  $ECHO "Would you like these added to the license database now (y/n) [y]: \c"
  addanswer="hoho"
  while [ "$addanswer" != "" -a "$addanswer" != "y" -a "$addanswer" != "n" ]
  do
    read addanswer
    if [ "$addanswer" = "" ];then
      addanswer="y"
    fi
    if [ "$addanswer" = "y" ];then
      cat licenses.out >> licenses
      if [ $? -ne 0 ];then
        $ECHO "WARNING: Failed to install licenses"
      else
        rm licenses.out
      fi
    fi
  done
fi
if [ -r license_request.txt ];then
  $ECHO "It looks like a license request file was created via the license application"
  $ECHO "Please mail the license_request.txt file to license@easysoft.com"
  $ECHO "to obtain your trial or full licenses."
fi
