#!/bin/sh
# This script is intended to be run by the administrator of a UNIX system
# who desires to start the FlexLM license server at system boot time.
# A detailed description of the actions performed by this script are
# contained in the sys5_idl_lmgrd script.
#
# Usage: This script must be run in the directory that contains 
# the 'sys5_idl_lmgrd' script (<IDL_DIR>/bin/). 
#

if [ ! -f ./sys5_idl_lmgrd ] ; then
    echo "Cannot find sys5_idl_lmgrd."
    echo "Please run this script from the bin subdirectory of your IDL distribution."
    exit 1
fi

UNAME=`uname`
case $UNAME in

    "Darwin")
	if [ ! -d /Library/StartupItems ]; then
	    mkdir /Library/StartupItems
	fi
	if [ ! -d /Library/StartupItems/IDL_LMGRD ]; then
	    mkdir /Library/StartupItems/IDL_LMGRD
	fi
	cp sys5_idl_lmgrd /Library/StartupItems/IDL_LMGRD/IDL_LMGRD
	echo "{
    Description    = \"IDL FlexLM License Manager\";
    Provides       = (\"IDL_License_Manager\");
    Requires       = (\"Network\", \"Resolver\");
    OrderPreference = \"Late\";
    Messages        = 
	{
	start = \"Starting the IDL FlexLM License Manager\";
	stop = \"Stopping the IDL FlexLM License Manager\";
	};
}
"> /Library/StartupItems/IDL_LMGRD/StartupParameters.plist
	;;

    "SunOS")				# Solaris
	cp sys5_idl_lmgrd /etc/init.d
	if [ -f /etc/rc3.d/S99sys5_idl_lmgrd ]; then
		rm -f /etc/rc3.d/S99sys5_idl_lmgrd
	fi
	if [ -f /etc/rc0.d/K01sys5_idl_lmgrd ]; then
		rm -f /etc/rc0.d/K01sys5_idl_lmgrd
	fi
        ln -s /etc/init.d/sys5_idl_lmgrd /etc/rc3.d/S99sys5_idl_lmgrd
	ln -s /etc/init.d/sys5_idl_lmgrd /etc/rc0.d/K01sys5_idl_lmgrd
	;;


    "Linux")
	# determine upper level boot dir
	if [ -d /etc/init.d ]
	then
		# Ubuntu, SuSE, Mandrake
		BOOT_DIR=/etc/init.d
	else
		if [ -d /etc/rc.d/init.d ]
		then
			# RedHat
			BOOT_DIR=/etc/rc.d/init.d
		else
			echo "$APPLICATION: Installer failed to find boot directory."
		fi
	fi

	# determine directory where the boot level directories live
	if [ -d /etc/rc2.d ]
	then
		# RedHat, Debian, Ubuntu
		BOOTLEVEL_DIR=/etc
	else
		if [ -d /etc/init.d/rc2.d ]
		then
			# SuSE
			BOOTLEVEL_DIR=/etc/init.d
		else
			echo "$APPLICATION: Installer failed to find boot level directory."
		fi
	fi

	cp sys5_idl_lmgrd $BOOT_DIR
	if [ -f $BOOTLEVEL_DIR/rc2.d/S99sys5_idl_lmgrd ]; then
		rm -f $BOOTLEVEL_DIR/rc2.d/S99sys5_idl_lmgrd
	fi
	if [ -f $BOOTLEVEL_DIR/rc3.d/S99sys5_idl_lmgrd ]; then
		rm -f $BOOTLEVEL_DIR/rc3.d/S99sys5_idl_lmgrd
	fi
	if [ -f $BOOTLEVEL_DIR/rc4.d/S99sys5_idl_lmgrd ]; then
		rm -f $BOOTLEVEL_DIR/rc4.d/S99sys5_idl_lmgrd
	fi
	if [ -f $BOOTLEVEL_DIR/rc0.d/S99sys5_idl_lmgrd ]; then
		rm -f $BOOTLEVEL_DIR/rc4.d/S99sys5_idl_lmgrd
	fi
	if [ -f $BOOTLEVEL_DIR/rc0.d/K01sys5_idl_lmgrd ]; then
		rm -f /etc/rc0.d/K01sys5_idl_lmgrd
	fi
	ln -s $BOOT_DIR/sys5_idl_lmgrd $BOOTLEVEL_DIR/rc2.d/S99sys5_idl_lmgrd
	ln -s $BOOT_DIR/sys5_idl_lmgrd $BOOTLEVEL_DIR/rc3.d/S99sys5_idl_lmgrd
	ln -s $BOOT_DIR/sys5_idl_lmgrd $BOOTLEVEL_DIR/rc4.d/S99sys5_idl_lmgrd
	ln -s $BOOT_DIR/sys5_idl_lmgrd $BOOTLEVEL_DIR/rc5.d/S99sys5_idl_lmgrd
	ln -s $BOOT_DIR/sys5_idl_lmgrd $BOOTLEVEL_DIR/rc0.d/K01sys5_idl_lmgrd
	;;
		
    *)
	echo "$APPLICATION: Unable to recognize system architecture."
	exit 1
	;;

esac

