#!/bin/bash
#
# Init file for sn
#
# chkconfig: 2345 95 05
# description: Small news server for small sites
#

SNROOT=/var/spool/sn

. /etc/rc.d/init.d/functions

[ -d $SNROOT ] || exit 0
RETVAL=0
SNERR=/tmp/snerr.$$ || [ -f $SNERR ] && rm -f $SNERR

case "$1" in

  start)
	echo -n $"Checking sn's news spool: "
	cd $SNROOT
	for a in .newsgroup .table .chain ; do
	   [ -f $a ] && rm -f $a
	done
	find . -type f -name "+*" -exec rm -f {} \;
	/usr/bin/snprimedb -i
	/usr/bin/snscan -n * 2> $SNERR | /usr/bin/snprimedb 2> /dev/null

	if [ -s $SNERR ]; then
	   echo_failure
	   cat $SNERR
	   rm -f $SNERR
	   RETVAL=1
	else
	   echo_success
	fi
	echo
	;;
  stop)
	# Nothing done
	RETVAL=0
	;;
  *)
	echo "Usage: sn {start}"
esac

exit $RETVAL
