#!/bin/sh
#
#	Archive - Build a tarfile of things we'd want to back up.
#		  Includes mush.config, the main conf file, a flatfile,
#		  the comsys and mail databases, and text files with a
#		  .txt extension that are not help, wizhelp, or mushman.txt
#		  Symbolic links are copied, not followed. 
#
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:.; export PATH
#
. mush.config
#
# You'll want to use gzip if you have it. If you want really good
# compression, try 'gzip --best'. If you don't have gzip, use 'compress'.
#
ZIP=gzip
#
DBDATE=`date +%m%d-%H%M`
FLATFILE=$GAMENAME.flat.$DBDATE
#
#	Make a flatfile.
#
if [ -r $DATA/$NEW_DB ]; then
    $BIN/dbconvert $DATA/$GDBM_DB x < $DATA/$NEW_DB > $FLATFILE
else
    if [ -r $DATA/$INPUT_DB ]; then
        echo "No recent checkpoint db. Using older db."
        $BIN/dbconvert $DATA/$GDBM_DB x < $DATA/$INPUT_DB > $FLATFILE
    else
        if [ -r $DATA/$SAVE_DB ]; then
            echo "No input db. Using backup db."
            $BIN/dbconvert $DATA/$GDBM_DB x < $DATA/$SAVE_DB > $FLATFILE
        else
            echo "No dbs. Backup attempt failed."
	    exit 1
        fi
    fi
fi
#
#	Gather and archive.
#
TXTFILES=`ls $TEXT/*.txt | egrep -v '(help|wizhelp|mushman).txt'`
ALLFILES="$FLATFILE $DATA/comsys.db $DATA/mail.db mush.config $GAMENAME.conf $TXTFILES"
#
echo "Archiving..."
tar -chvf - $ALLFILES | $ZIP -c > $GAMENAME-archive.$DBDATE.tar.gz
rm $FLATFILE
echo "Done."
