#!/bin/csh -f
#
# compose-tricky: a shell script for putting together events.txt
#
# This script calls index-events and maybe mkrumor
# 
# To use compose, make a subdirectory of your txt directory called
# Events, and split your events.txt into any number of files in the
# Events directory, each ending in .event
# 
# By Alan Schwartz (Javelin/Paul)


# This process can eat CPU, so we'll be nice.
/etc/renice +6 $$

# Where do you keep various files?
# If you don't want to use Rumor stuff, comment out the set RMRDIR...
set TXTDIR=/dunemush/mush/game/txt
set EVENTDIR=$TXTDIR/Events
set RMRDIR=$EVENTDIR/Rmr

# Go to the txt directory
cd $TXTDIR

# Backup old events
cp events.txt events.txt~

# Go to the events directory
cd $EVENTDIR

# Remove the old index
rm index.event

# Build up the rumors file
if ($?RMRDIR) then
	echo Building current rumors files...
	cd $RMRDIR
	mkrumor
	cp rumor.event ..
	cd $EVENTDIR
endif

# Build a new index, and tack it on.
echo Building index...
cat *.event | tee $TXTDIR/events.txt | $TXTDIR/index-events > index.event
cat index.event >> $TXTDIR/events.txt

# Back to TXTDIR
cd $TXTDIR

# Re-index the event files
echo Building hashed index...
mkindx events.txt events.indx

# Put the time of last events update into the first line of the motd.txt
echo Updating motd...
echo "Last Events Update: `/bin/date`"  > /tmp/compose.$$
/usr/ucb/tail +2 $TXTDIR/motd.txt >> /tmp/compose.$$
mv /tmp/compose.$$ $TXTDIR/motd.txt

# If you use the DuneSource code, uncomment the lines below and
# a HUP signal will be sent to the MUSH, causing it to re-read
# motd.txt and update it on the fly. The ps line may fail on SysV.
#
echo Sending the MUSH a HUP...
set mush = `/bin/ps ux | /bin/grep conf | /bin/grep netmush | awk '{print $2}'`
if ($mush > 1) then
	/bin/kill -HUP $mush
endif

# DuneMUSH had an ftp site where it kept copies of its
# events files and things. This part of the script copies the
# file to the ftp site.
#
#echo Updating ftp site...
#cp events.txt /usr/spool/ftp/pub/DuneMUSH/Events
#gzip -c events.txt > /usr/spool/ftp/pub/DuneMUSH/Events/events.txt.gz

echo Done.
