#
# BBS Shutdown script, should be run as BBS owner.
# Note: this is only used on old Slackware and NetBSD systems.
#
# On FreeBSD it needs the psmisc package.
#
# $Id$
#

export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:$MBSE_ROOT/bin:"


if [ "$MBSE_ROOT" = "" ]; then
   export MBSE_ROOT=`cat /etc/passwd | grep mbse: | awk -F ':' '{ print $6}'`
fi


if [ -f $MBSE_ROOT/bin/mbtask ]; then
	echo -n "Shutdown MBSE BBS: "
	if [ -f $MBSE_ROOT/etc/config.data ]; then
		echo -n "closing the bbs "
		cd $MBSE_ROOT
		$MBSE_ROOT/bin/mbstat close wait -quiet
		echo -n "done, "
	fi
	# Now kill the daemons
	echo -n "kill "
	base=`basename mbtask`
	pid=`pidof $base`
	echo -n "mbtask "
	if ps h $pid >/dev/null 2>&1; then
		kill $pid
		RC=$?
		[ $RC -eq 0 ] && echo -n "ok " || echo -n "failed "
	fi
	echo ""
else
	echo "mbtask not available!"
fi
#
