#!/bin/sh
if [ "`echo -n`" = "-n" ]; then
   C='\c'
   N=
else
   N='-n'
   C=
fi
directory="/usr/local/cwlm"
con="Z"
while :
do
echo $N "Input the License Manager Directory (default = $directory:) $C"
read tmp
if [ -n "$tmp" ]; then
   directory=$tmp
fi

if [ -d $directory ] ; then
   if [ -f "$directory/lmgrd" ] ; then
      echo "WARNING - lmgrd CURRENTLY EXISTS IN SPECIFIED DIRECTORY"
      echo "          INSTALL WILL OVERWRITE lmgrd IF YOU CONTINUE"
   fi
fi

echo "The license server will be installed in directory: $directory"
   echo $N "Do you accept this directory y/n?  x exits $C"
   read con
   if [ -z "$con" ]
   then      
      con="Y"
   fi
   if [ $con = "Y" ] || [ $con = "y" ] || [ $con = "X" ] || [ $con = "x" ]
   then
      break
   fi
done
if [ $con = "Y" ] || [ $con = "y" ] ; then
      if [ ! -d $directory ] ; then
         mkdir $directory
         if [ $? != 0 ] ; then
            err=$?
            echo "install has failed"
            exit $err
         fi
      fi
      cp readme.txt $directory/readme.txt
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      cp lmgrd $directory/lmgrd
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      cp compuwar $directory/compuwar
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      cp lmutil $directory/lmutil
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      cp checkPort $directory/checkPort
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed on checkPort"
         exit $err
      fi
      echo "The License Manager has been installed"
      cp cl_merge $directory/cl_merge
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      cp cl_sort $directory/cl_sort
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      cp cl_valid $directory/cl_valid
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      cp flexlm.rul $directory/flexlm.rul
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      echo "The CW License Utilites has been installed"
      cp bps.stat $directory/bps.stat
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      cp bps.run $directory/bps.run
      if [ $? != 0 ] ; then
         err=$?
         echo "install has failed"
         exit $err
      fi
      echo "The Borrow Proxy Server files have been installed"
      cp aes $directory/aes
      if [ $? != 0 ] ; then
         err=$?
         echo "the aes script was not copied"
         exit $err
      fi
      echo "The ADMIN ENVIRON SCRIPT has been been installed"
fi
