:
#	@(#) fontserv   1.4  93/02/20
#
#	Copyright (C) 1990-1991 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#

# figure out which kernel we're running
if [ -x /bin/ps ] ; then
    /bin/su root -c "/bin/ps -e" > /tmp/ps.err$$ 2>&1
    if grep "not the booted" /tmp/ps.err$$ > /dev/null ; then
        PS="/bin/ps -n /unix.old"
    else
        PS="/bin/ps"
    fi
    rm -f /tmp/ps.err$$
else
    echo "$0: Can't find ps"
    exit 1
fi


case $1 in
'start')
	/bin/su root -c "$PS -e" | grep slink 1> /dev/null
	if [ "$?" != 0 ]
	then
		echo "TCP/IP must be running before starting the font server."
		exit 1
	fi
	pid=`/bin/su root -c "$PS -ef" | grep /usr/bin/X11/fs | sed -e '/grep/d' | awk '{print $2}'`
	if [ "${pid}" != "" ]
	then
		echo "The font server is currently running"
		exit 1
	else
	echo -n "Starting the Font Server: "
	[ -x /usr/bin/X11/fs ] && [ -r /usr/lib/X11/fs/config ]
	/usr/bin/X11/fs -cf /usr/lib/X11/fs/config &
	echo fs
	fi
	;;
'stop')
	echo "Stopping the Font Server. "
	pid=`/bin/su root -c "$PS -ef" | grep /usr/bin/X11/fs | sed -e '/grep/d' | awk '{print $2}'`
	if [ "${pid}" != "" ]
	then
		[ -x /bin/kill ] &&
		/bin/kill ${pid}
	fi
	;;
'enable')
	ln -s /etc/fontserv /etc/rc2.d/S91fontserv
	ln -s /etc/fontserv /etc/rc0.d/K80fontserv
	echo "The Font Server will now auto start when entering multi-user mode."
	;;
'disable')
	rm /etc/rc2.d/S91fontserv /etc/rc0.d/K80fontserv
	echo "The Font Server will no longer start when entering multi-user mode."
	;;
'query')
	pid=`/bin/su root -c "$PS -ef" | grep /usr/bin/X11/fs | sed -e '/grep/d' | awk '{print $2}'`
	if [ "${pid}" != "" ]
	then
		echo "The font server is currently running."
	else
		echo "The font server is not currently running."
	fi
	if ([ -f /etc/rc2.d/S91fontserv ] && [ -f /etc/rc0.d/K80fontserv ])
	then
		echo "The font server is currently enabled."
	else
		echo "The font server is currently disabled."
	fi
	;;
're-read')
	pid=`/bin/su root -c "$PS -ef" | grep /usr/bin/X11/fs | sed -e '/grep/d' | awk '{print $2}'`
	if [ "${pid}" != "" ]
	then
		echo "Telling font server to re-read its config file."
		[ -x /bin/kill ] &&
		/bin/kill -16 ${pid}
	fi
	;;
'flush')
	pid=`/bin/su root -c "$PS -ef" | grep /usr/bin/X11/fs | sed -e '/grep/d' | awk '{print $2}'`
	if [ "${pid}" != "" ]
	then
		echo "Telling font server to flush any cached information."
		[ -x /bin/kill ] &&
		/bin/kill -17 ${pid}
	fi
	;;
'reset')
	pid=`/bin/su root -c "$PS -e" | grep fs | sed -e 's/^  *//' -e 's/ .*//'`
	if [ "${pid}" != "" ]
	then
		echo "Resetting the font server."
		[ -x /bin/kill ] &&
		/bin/kill -1 ${pid}
	fi
	;;
*)
	echo "usage: $0  {start|stop|enable|disable|query|re-read|flush|reset}"
	echo
	echo "start     will start the font server."
	echo "stop      will stop the font server."
	echo "enable    will start the font server when going to multi-user mode."
	echo "disable   prevents the font server from starting when going multi-user."
	echo "query     tells you if the font server is running and enabled."
	echo "re-read   tells the font server to re-read it's configuration file."
	echo "flush     tells the font server to flush its buffers."
	echo "reset     does a soft reset of the font server"
	;;
esac

# End SCO_BASE
