#!/bin/sh
# Script to install the Enterprise Server License Manager.   
test `uname -s` = Linux && echocmd="echo -e" || echocmd="echo"

if test ! -w /etc/passwd
then
	$echocmd "You must be running as root to execute this script"
	exit 1
fi

if test x.$COBDIR = x.
then
	$echocmd "You must have COBDIR set to execute this script"
        exit 1
fi


SCRIPTDIR=$COBDIR/bin
$echocmd "COBDIR=$COBDIR" > $SCRIPTDIR/mfeslmrcscript
$echocmd "export COBDIR" >> $SCRIPTDIR/mfeslmrcscript

cat >>$SCRIPTDIR/mfeslmrcscript <<END
LD_LIBRARY_PATH=\$COBDIR/lib:\$LD_LIBRARY_PATH:/lib
export LD_LIBRARY_PATH
END

$echocmd "cd $SCRIPTDIR" >> $SCRIPTDIR/mfeslmrcscript
$echocmd "./eslm" >> $SCRIPTDIR/mfeslmrcscript
chmod 755 $SCRIPTDIR/mfeslmrcscript

$echocmd "\nThe use of Enterprise Server requires the Enterprise Server License Manager\nto be running." 

$echocmd "\nDo you want the Enterprise Server License Manager to be automatically \nstarted at boot time? (y/n): \c"
read y
case "$y" in
y*|Y*)	
            cp $SCRIPTDIR/mfeslmrcscript /etc
            chmod 755 /etc/mfeslmrcscript
            cp /etc/inittab /etc/inittab.bak
            check=`grep mfeslmrcscript /etc/inittab`
	    if [ ! -z "$check" ]
	    then
                fgrep -v "mfeslmrcscript" /etc/inittab.bak > /etc/inittab
            fi
            $echocmd "mfes:2345:wait:sh /etc/mfeslmrcscript > /dev/null 2>&1" >> /etc/inittab
        ;;
*)  	    $echocmd "\nIf you later want to configure the Enterprise Server License Manager\nto be automatically started at boot time, enter the following command\nwhilst logged in as root :\n     cd $COBDIR; sh ./bin/eslminstall\n" 
        ;;
esac
