#! /bin/sh
# $Id: activate_license.sh,v 1.2 2001/11/07 18:06:42 rlawrence Exp $ 
# SCCSID(@(#)activate_license.sh	1.1) Modified 10:34:08 6/20/01
# A simple script that is to be called after the license is changed,
# to make the license changes active.

# Print out to the log file when ok to log, and to the user when trace is on.
Log()
{
	[ "$OK_TO_LOG" = "ok_to_log" ] && echo $EPT "$*" >> "$LOGFILE"
	[ "x$TRACE" = "xtrace" ]       && echo $EPT "$*"
}

# + + + MAIN --- start here --- + + + + + + + + + + + + + + + + + + + + + +  +
# (Everything above here must only be functions)

# Get the STATICMERGE, SYSTEMTYPE, DEFAULTMERGE and HOME setting.
. /etc/mrgssv.sh
[ "$SYSTEMTYPE" = "linux" ] && EPT="-e"
LOGFILE="$VARMERGE"/log/activate_license.log
OK_TO_LOG="ok_to_log"

# The script "set_nls.sh" uses STATICMERGE to set MFILE.
. $STATICMERGE/set_nls.sh
DM="LCC.MERGE.UNIX.ACT_LIC"

MY_UID=`"$STATICMERGE"/bin/print_uid`
if [ "$MY_UID" != "0" ]
then
	usrMsg ECHO MUST_BE_ROOT \
		"You must be the root user to use this command.\n"
	exit 2
fi

date > "$LOGFILE" 2>&1
Log "Log of activate_license"

Log "Running unloadem"
"$STATICMERGE"/drivers/tools/unloadem	>> "$LOGFILE" 2>&1
RETVAL=$?
Log "unloadem retval $RETVAL"

if [ $RETVAL -ne 0 ]
then
	usrMsg ECHO UNLOAD_FAILED \
"License not fully activated because unable to unload modules.\n\
This is probably because the product is currently in use.\n\
Inspect the log file $LOGFILE\n\
for details.\n" $LOGFILE
	exit 1
fi

Log "Running rlock_tune"
"$STATICMERGE"/adminbin/rlock_tune	>> "$LOGFILE" 2>&1
Log "rlock_tune retval $?"

Log "Running loadem"
"$STATICMERGE"/drivers/tools/loadem	>> "$LOGFILE" 2>&1
Log "loadem retval $?"

exit 0
