#!/bin/sh
#
# chkconfig: 345 05 95
# description: This script is used to start and stop the IDL network \
#              license manager.
#
# To use it, you might have to customize it for your site.
# The shell variables ITT_DIR and IDL_DIR set set by the installer.
# These two variables, along with LM_LICENSE_FILE and LOG_FILE_NAME,
# are available for customization.
#
# The licence management software does not require root privileges
# to operate.  The license management daemons should be started
# by a non-privileged user with a restrictive umask setting, preventing
# the unneccessary use of the root account.  The license manager
# can be started by a non-privileged user by modifying the start
# command from below as follows:
#    "start") su username -c "umask 022;$IDL_DIR/bin/lmgrd > $LOG_FILE_NAME &"
# where "username" is the account name of an unprivileged user that has
# execute permission for the license management utilities, write
# permission to create the log file, and read permission for the license file.
#
# Once this file is properly customized, use the following commands to
# install it on your system. These commands assume that your current working
# directory is the one containing this script.  Make sure to use the
# appropriate commands for your system. Alternatively, you can use the
# "lmgrd_install" script, located in this directory.
#
# Sun Solaris, Linux and SGI IRIX
# -------------------------------
#	% cp sys5_idl_lmgrd /etc/init.d
#	% ln /etc/init.d/sys5_idl_lmgrd /etc/rc3.d/S99sys5_idl_lmgrd
#	% ln /etc/init.d/sys5_idl_lmgrd /etc/rc0.d/K01sys5_idl_lmgrd
#
# Darwin (Mac OS X)
# -----------------
#	Please consult the 'lmgrd_install" script for instructions.
# 
# After executing these commands, reboot the system.
#
# The following steps explain the commands above.
#
#	1) Copy this script to the standard System V location.
#	2) Link it into the run level 2 directory.
#          The leading 'S' means that our daemon should be started
#          at run level 2. The 99 causes this script
#	   to be executed after all other scripts in the rc directory.
#	3) Link it into the run level 0 directory. The leading 'K' means
#	   that our daemon should be killed when entering run level 0. 
#	   The 01 causes this script to be executed 
#	   before the other scripts in /etc/rc0.d.
#	4) Reboot the system, returning to multi-user mode. Entering this
#	   mode will cause the IDL license manager daemon to be started.
#
# TO LEARN MORE:
#	- Read about run levels in the System Administration guide for
#	  your system.
#	- Read the file /etc/init.d/README or /sbin/init.d/README or
#         read the manual pages for init, rc0, rc1, rc2, and rc3.

# NOTE: EDIT THESE DEFINITIONS FOR YOUR SITE
VERSION=70
ITT_DIR=/Applications/itt
IDL_DIR=$ITT_DIR/idl$VERSION
LM_LICENSE_FILE=$ITT_DIR/license/license.dat
LOG_FILE_NAME="/dev/console"
#PATH=/usr/sbin:/usr/bin:/sbin
#export PATH
# END OF END-USER DEFINITIONS

SCRIPT=$0
export ITT_DIR
export IDL_DIR
export LM_LICENSE_FILE
export PATH


# Make sure we really have the location of the daemon and the license file.
if [ ! -f $IDL_DIR/bin/lmgrd ]; then
  echo "$SCRIPT: Can't find the idl license manager daemon"
  exit 1
fi
if [ ! -f $LM_LICENSE_FILE ]; then
  echo "$SCRIPT: Can't find the idl license file: $LM_LICENSE_FILE"
  exit 1
fi

# Take the desired action
case $1 in
  "start_msg")
        echo "Start IDL license manager (lmgrd)"
        ;;
 
  "stop_msg")
        echo "Stop IDL license manager (lmgrd)"
        ;;
 
  "start") $IDL_DIR/bin/lmgrd > $LOG_FILE_NAME &
           sleep 5  ;;
  "stop")  $IDL_DIR/bin/lmdown -q ;;
  *) echo "$SCRIPT: Unknown option: $1"
     echo "Usage: $SCRIPT { start | stop }"
     exit 1;;
esac

