#!/bin/sh
#
# xfbb:        starts or stops xfbbd daemon server.
#
# Author:      Jose R. Marte A. <hi8gn@amsat.org>
# date:        Jun 15 2000.-
#
# chkconfig: 2345 97 95
# description: xfbb daemon server, F6FBB bbs server by Jean Paul ROUBELAT
# processname: xfbb
#
# Source function library.
. /etc/rc.d/init.d/functions

RETVAL=0

# See how I'm  calling the fbb.
case "$1" in
  start)
        [ xfbbd = "$(ps xc|grep -w xfbbd|awk '{print $5}')" ] && exit 0
        echo  "Starting xfbb daemon server. "
	touch /var/lock/subsys/xfbbd
	cd /usr/local/fbb
	daemon ./xfbb.sh -d -a > /dev/null 2>&1 &
  	RETVAL=$?
	;;
   xwin)
        [ xfbbd = "$(ps xc|grep -w xfbbd|awk '{print $5}')" ] && exit 0
	if  [ startx = "$(ps xc|grep -w 'startx'|awk '{print $5}')" ]; then
        echo  "Starting xfbb X Server. "
	cd /usr/local/fbb
	./xfbb.sh -f -a > /dev/null 2>&1
	else
	echo "WARNING!! you just can run the (fbb xwin) Under X-Windows"
	exit 0
	fi
   	RETVAL=$?
	;;
  stop)
       echo  "Stopping xfbb daemon server. "
	killproc xfbbd
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/xfbbd
	RETVAL=$?
	;;
  status)
	echo -n "Checking, the FBB daemon "
	if [ -f /var/lock/subsys/xfbbd ]; then
	echo 'is UP'
	else
	echo 'is DOWN'
	fi
	RETVAL=$?
	;;
       *)
	clear
        echo "Usage: fbb start, fbb xwin, fbb stop, fbb status"
	echo
	exit 1
esac
exit $RETVAL
