#!/bin/sh

ps axu | fgrep portmap | grep -v grep >/dev/null
if [ $? != 0 ] ; then
	cat << EOF

You must have portmapper running to use FrameMaker.

Please start one by becoming root:

	athena% cd /
	athena% su
	Password: mrroot

and typing

	athena# /etc/portmap
	athena# exit
	athena% cd

EOF

exit 0
fi

TOPDIR=/afs/athena.mit.edu/software/frame
BINDIR=${TOPDIR}/bin
TMPDIR=/usr/tmp; export TMPDIR
frameLSName=framels
NUMSERVERS=2

FMHOME=${TOPDIR}

#
# Handle Xresources so we can use the preprocessor
#
MYSHELL=$$
planes=`xrdb -symbols | awk '{print $14}'`
if [ "${planes}" = "-DPLANES=1" ] ; then
	RESOURCES=${TOPDIR}/.fminit2.0/xresources/Maker.mono
else
	RESOURCES=${TOPDIR}/.fminit2.0/xresources/Maker.color
fi
cp ${RESOURCES} /tmp/maker.resources.${MYSHELL}

#
# Figure out a default printer
#
xrdb -q | /usr/bin/egrep "Maker[.]*printerName" 2>&1 > /dev/null
if [ $? != 0 ] ; then
   host=`/bin/hostname`
   clusterPrinter=`hesinfo $host cluster | \
	grep lpr | awk '{print $2}'`
   : ${PRINTER=$clusterPrinter}
   echo "Maker.printerName: $PRINTER" >> /tmp/maker.resources.${MYSHELL} 
fi

#
# Finally get the resources 
#
xrdb -edit /tmp/maker.resources.${MYSHELL}
XENVIRONMENT=/tmp/maker.resources.${MYSHELL}
export XENVIRONMENT


#
# Attempt to randomize the selection of license servers
#
serverNum=`echo $MYSHELL $NUMSERVERS | awk '{ print ($1 % $2) + 1 }'`
FRAMEUSERSD_HOST="$frameLSName$serverNum"
# FRAMEUSERSD_HOST=framels2

#
# set environment variables for bibframe
#
BIBFRAMEBIN=${TOPDIR}/decmipsbin

export FRAMEUSERSD_HOST FMHOME BIBFRAMEBIN 

prog=$0
progname=`basename $prog`

exec ${BINDIR}/$progname $*
