#! /bin/sh
#*+***********************************************************************
#*
#*  Module:
#*	mental ray SPM utilities
#*
#*  Copyright (c) 2001-2001 by Alias|Wavefront, Inc., and Alias|Wavefront,
#*  a division of Silicon Graphics Canada Ltd.  All rights reserved.
#*
#*  This script queries the spm_key utility for a request code
#*
#*-***********************************************************************

UserID=`id | awk 'BEGIN{ FS="[=(]" } { print $2}'`
PROG=`basename $0`

if test "$UserID" != "0" ; then
	echo "$PROG must be run with root priveleges";
	exit ;
fi

echo "Checking for existing licenses..."
/var/spm/spm_key -t -y -F1 > /tmp/eospmt.tmp 2> /tmp/eospme.tmp
ALIAS=`cat /tmp/eospme.tmp | grep "Alias"`
if test "$ALIAS" != ""; then
	# AW vendor string found
	/var/spm/spm_key -c -m 'Alias|Wavefront' -y -F1 > /tmp/eospmk.tmp 2> /tmp/eospme.tmp;
else
	/var/spm/spm_key -c -m Anybody -y -F1 > /tmp/eospmk.tmp 2> /tmp/eospme.tmp;
fi	
echo "Creating a license request code..."
		
KEYL=`cat /tmp/eospmk.tmp | grep "^*" | cut -d " " -f5`
KEYD=`cat /tmp/eospmk.tmp | grep "^>" | cut -d " " -f3`
KEYS=`cat /tmp/eospmk.tmp | grep "^>" | cut -d " " -f2`
echo     "-----------------------------------------------"
if test "$KEYD" != ""; then
 	echo "Your Request Code is $KEYD";
	echo "Your Host Name is $KEYS";
	echo "Your Key Level is $KEYL";
	echo "Please visit http://www.alias.com/spar";
	echo "and enter the above information to obtain a";
	echo "license.";
else
	echo "Could not generate a request code."; 
	echo "spm_key produced the following output:";
	cat /tmp/eospme.tmp;
fi
echo     "-----------------------------------------------"
  
rm /tmp/eospmk.tmp /tmp/eospme.tmp /tmp/eospmt.tmp
