#!/bin/sh
#
# Terminate WALE License Manager (waled2)
#

### Be sure the appropriate environment variables are set
###

if test x$SHARC_HOME = 'x'; then
    echo "\$SHARC_HOME is not defined!"
    exit 1
fi

if test x$SHARC_ARCH = 'x'; then
    ARCH=`$SHARC_HOME/bin/sharc_arch`
else
    ARCH=$SHARC_ARCH
fi


if test ! -x $SHARC_HOME/license/machines/$ARCH/waled2_stop; then
    echo "Cannot find or execute $SHARC_HOME/license/machines/$ARCH/waled2_stop!"
    exit 1
fi


### Set the home directory of the license manager
###

LICDIR=$SHARC_HOME/license

### Stop the daemon(s)
###

if [ $# -gt 0 ] ; then
$SHARC_HOME/license/machines/$ARCH/waled2_stop $SHARC_HOME/license/wale2.key "$@"
else
$SHARC_HOME/license/machines/$ARCH/waled2_stop $SHARC_HOME/license/wale2.key
fi

if [ "$?" -ne 0 ] ; then
echo ""
echo "NOTE: if you get an error and waled2 is currently running, you may"
echo "need to specify the waled2 host name as an argument to waled2_stop."
echo "The name must appear exactly as specified in waled2.key key file."
echo "This is because 'hostname' does not return the same name as encoded"
echo "in the key."
echo ""
fi
