#! /bin/sh

#	Copyright (c) 1988-1989 Frame Technology Corp.
# 
# fmorder
# Mike Takamoto

# Routine to get hostid
# $1=Primary1, Backup0
getid(){
#CHOST = Current Host
#FLSID = HostID of FLS machine
FLSID=""
CHOST=`/bin/hostname`
VALID=""
	if [ "$1" ]; then
		DEFAULT=$CHOST
		echo -n "
Please type in the name of the machine where the software
will be installed [$CHOST]: "
	else
		DEFAULT=""
		echo -n "
If you have a second machine on your network that you would
like to have as a backup in case the first machine goes down,
please type in the name of this machine [none]: "
		CHOST=""
	fi
	read ANSWER
	if [ "$ANSWER" = "" ]; then
		ANSWER=$DEFAULT
	fi

	if [ "$ANSWER" = "none" ]; then
		if [ "$1" ]; then
		echo "
You must designate at least one machine as the primary license
server to order Frame software. Please run this script again
and enter a valid hostname.
"
		exit
		else
		VALID="1"
		fi
	fi
	
	if [ "$ANSWER" = "" -a ! "$1" ]; then
		VALID="1"
	fi

	if [ "$ANSWER" ]; then
		FLS=$ANSWER
		if [ "$FLS" = "$CHOST" ]; then
		FLSID=`/bin/hostid`
		else
		FLSID=`/usr/ucb/rsh $FLS /bin/hostid 2> /dev/null`
		fi
		if [ "$FLSID" ]; then
		VALID=1
		else
		echo "
Unable to rsh to get hostid of $FLS. You have either typed the name
of the machine incorrectly, or are unable to log on to the machine 
you specified.
"
		fi
	fi

if [ "$1" ]; then
   PRIMEID=$FLSID
else
   BACKID=$FLSID
fi
}


echo -n "
fmorder 2.0

Running this script will provide you with the licensing
information you need to place an order with Frame Technology.

If you need more information about Frame's Floating License Server,
please see the Frame document, LicenseInfo.doc.

"

choice="Invalid"

echo -n "
Do you wish to:
	a. add licenses to your existing work group ?
OR	b. create a new work group ?

Note: If you are a member of a workgroup that already shares
Frame licenses, you would typically choose option a.
Otherwise, choose option b.

"

until [ "$choice" = "a" ] || [ "$choice" = "b" ];
do
echo -n "Type a or b: "
read choice
done


if [ "$choice" = "a" ]; then 

echo "

Please wait a moment, checking your environment.
"
fmserial > /tmp/serialData.$$
	if [ "$?" -ne 0 ]; then
		echo "
Could not find your frameusers file. Please check your Frame
installation, then run this script again.
		"
		exit
fi	
INFO=`cat /tmp/serialData.$$ |  tr -s '[< > \11-\12]' ' ' \
	| awk -e '{print $5, $12, $18 }'`
rm -f /tmp/serialData.$$


FILENM=`echo "$INFO" | awk -e '{print $1}'`
SERIAL=`echo "$INFO" | awk -e '{print $2}'`
SUPDAT=`echo "$INFO" | awk -e '{print $3}'`
EXPDT=`cat $FILENM | egrep FinalDay | tr -s '[< x >]' ' ' \
	| awk -e '{print $2}'`
HOSTP=`cat $FILENM | egrep Server1 | tr -s '[< x >]' ' ' \
	| awk -e '{print $4}'`
HOSTB=`cat $FILENM | egrep Server2 | tr -s '[< >]' ' ' \
	| awk -e '{print $3}'`
LICINFO=`cat $FILENM | egrep '(ProductName|MaxUsers)'\
	| tr -s '[< > \11-\12]' ' ' | awk -e '{print $5, $12, $19, $26}'`
IM=`echo $LICINFO | awk -e '{print $1}'`
FM=`echo $LICINFO | awk -e '{print $2}'`
FV=`echo $LICINFO | awk -e '{print $3}'`
FW=`echo $LICINFO | awk -e '{print $4}'`

echo "
Please provide the following information when you place your order:

	Your Primary License Server Host ID: $HOSTP"
if [ "$HOSTB" ]; then
	echo "	Your Backup License Server Host ID: $HOSTB"
fi
echo "	Your Frame Serial Number is: $SERIAL
	Your Frame SUP Expiration date is: $SUPDAT "
if [ "$HOSTB" ]; then
	echo "	Your Password Expiration date is: $EXPDT"
fi
echo "
Current license information:

	Number of FrameMaker Users: $FM
	Number of International FrameMaker Users: $IM
	Number of FrameWriter Users: $FW
	Number of FrameViewer Users: $FV

Please record the above information.
fmorder 2.0 Finished.
"


else

	echo "
You need to pick a machine where the license server software will
run. This is typically the same machine on which the Frame software
is installed.
"
	VALID=""
	until [ "$VALID" ];
	do
		getid "1"
		if [ ! "$VALID" ]; then
			YORN="maybe"
			until [ "$YORN" = "y" -o "$YORN" = "n" ];
			do
			echo -n "Try Again [y] ? "
			read CHECK
			if [ "$CHECK" = "" -o "$CHECK" = "y" ]; then
				VALID=""
				YORN="y"
			fi
			if [ "$CHECK" = "n" ]; then
				YORN="n"
				VALID="1"
			fi
			done
		fi
	done

	VALID=""
	until [ "$VALID" ];
	do
		getid ""
		if [ ! "$VALID" ]; then
			YORN="maybe"
			until [ "$YORN" = "y" -o "$YORN" = "n" ];
			do
			echo -n "Try Again [y] ? "
			read CHECK
			if [ "$CHECK" = "" -o "$CHECK" = "y" ]; then
				VALID=""
				YORN="y"
			fi
			if [ "$CHECK" = "n" ]; then
				YORN="n"
				VALID="1"
			fi
			done
		fi
	done

	echo "
Please provide the following information when you place your order:

	Hostid: $PRIMEID "
	if [ "$BACKID" ]; then
		echo "	Backup Hostid : $BACKID
		"
	fi
	echo "
Please record the above information.
fmorder 2.0 Finished.
"
fi


