#!/bin/sh

#
# weekly  -  shell script to be executed once per week to perform periodic
#            maintenance tasks on the Citadel/UX system.
#
# $Id: weekly.in,v 1.5 1999/07/17 18:46:41 ajc Exp $
# 

[ x$BBSDIR = x ] && BBSDIR=/usr/local/citadel
[ x$EXECDIR = x ] && EXECDIR=$BBSDIR

cd $BBSDIR || exit

echo `date` Weekly BBS processing started.

# Do some purging and expiry
$EXECDIR/sendcommand -h$BBSDIR "EXPI users"
$EXECDIR/sendcommand -h$BBSDIR "EXPI rooms"
$EXECDIR/sendcommand -h$BBSDIR "EXPI messages"
$EXECDIR/sendcommand -h$BBSDIR "EXPI visits"


# Create a file called "?" in the help directory, listing all of the other
# help files.  This is a bit kludgey, but it does allow a user to type
# .<H>elp ?  to get a list of all available help files.
#
ls $BBSDIR/help >$BBSDIR/help/\?

# Now we remove any zero-length files in all of the room directories.
# Presumably any empty files are failed uploads and are not needed.
#
echo The following files have been deleted:
find $BBSDIR/files -size 0 -print -exec rm -f {} \;

# Do some maintenance on the file descriptions.  We remove the lines 
# pertaining to files which no longer exist, and also make sure that there
# is only one line per file.
#
for x in $BBSDIR/files/*
do
	cd $x
	[ -s filedir ] && {
		cp /dev/null filedir2
		for y in *
		do
			cat filedir |grep -y $y >>filedir2
		done
		sort <filedir2 |uniq >filedir
		rm -f filedir2
	}
done

echo `date` Weekly BBS processing ended.
