#! /bin/sh
#
# Splus LICENSE modinstall
#
# Install new license key(s) for a module.
#

feature_name_file=Name
usage='Usage:
 
Splus LICENSE modinstall <module_name>
 
where "<module_name>" is the name of the module and corresponds to the name of
a sub-directory of $SHOME/module/.
'
 
[ $# -eq 0 ] && echo "$usage" >&2 && exit 1
 
module="$1"; shift
if [ $# -ne 0 ]
then
    echo "Too many arguments supplied." >&2
    echo "$usage" >&2
    exit 1
fi
 
S_MODHOME=${S_MODHOME-$SHOME/module/$module}
feature=`Slmhelper modfeature $module 2>/dev/null`
if [ X$feature = X ] || [ X$feature = X-1 ]
then
    echo "Could not locate licensing information for module $module" >&2
    echo "$usage" >&2
    exit 1
fi
 
if [ -r $S_MODHOME/$feature_name_file ]
then alias=`cat $S_MODHOME/$feature_name_file`
else alias=$module
fi
 
splus_server=`server host`
keyfile=`keydir`/$feature.lic

if samehost $splus_server
then hostinfo; install -M $feature=$alias
else
    cat <<EOCAT
You are not running this installation on the same computer that is serving as
the license server for your S-PLUS product. You will need to install a license
key on that system ($splus_server) by logging into it and running

    Splus LICENSE modinstall $module

EOCAT
exit 1
fi

if [ -r $keyfile ]
then echo; echo "License key for '$module' successfully installed."
else
    cat <<EOCAT
 
WARNING: License key not installed! The '$module' module will not be useable
         until the key is successfully installed.
 
EOCAT
fi
