tinymush-3.1p2/game/backups/
tinymush-3.1p2/game/bin/
tinymush-3.1p2/game/data/
tinymush-3.1p2/game/modules/
tinymush-3.1p2/game/modules/old/
tinymush-3.1p2/src/modules/comsys/
tinymush-3.1p2/src/modules/hello/
tinymush-3.1p2/src/modules/mail/
tinymush-3.1p2/src/tools/
#!/bin/sh
#
# $Id: Restore,v 1.15 2004/11/14 03:05:39 tyrspace Exp $
#
#	Restore - Extract and install an archived set of backup
#		  database files.
#
#	Syntax: Restore [filename]
#
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:.; export PATH
LTDL_LIBRARY_PATH=./modules:./bin:.:../src:../src/modules:../src/.libs:./modules/.libs; export LTDL_LIBRARY_PATH
#
. mush.config
. check_paths
#
ARCHIVE="$1"
#
if [ ! "$ARCHIVE" ]; then
    echo "Syntax: $0 [backup archive]"
    exit 1
fi
#
if [ ! -r $ARCHIVE ]; then
    if [ ! -r "$BACKUP_DIR/$1" ]; then
	echo "Error: $ARCHIVE not found."
	exit 1
    fi
    ARCHIVE=$BACKUP_DIR/$1
fi
#
#
# Use the flatfile extension to figure out what type of file we have to
# deal with, and how we should deal with it.
#
case $ARCHIVE in
	*.gz) UNZIP="gzip -dc"
		ZEXT="gz"
		echo "Will use $UNZIP to uncompress gzipped archive." ;;
	*.Z) UNZIP="compress -dc"
		ZEXT="Z"
		echo "Will use $UNZIP to uncompress compressed archive." ;;
	*.bz2) UNZIP="bzip2 -dc"
		ZEXT="bz2"
		echo "Will use $UNZIP to uncompress bzip2 archive." ;; 
	*) UNZIP="cat"
		ZEXT=""
		echo "This archive appears to be uncompressed... okay." ;;
esac
#
# If we have other goop in the way, move it out of the way.
#
echo "Moving old files out of the way. Please ignore file-not-found warnings."
#
DBDATE=`date +%m%d-%H%M`
mkdir db-$DBDATE
mv -f $DATA/$GDBM_DB $DATA/$CRASH_DB $DATA/$BACKUP_DB $DATA/mod_*.db db-$DBDATE
#
# Reload the archive.
#
case $ARCHIVE in
    *-archive.*.tar.*) mv -f mush.config $GAMENAME.conf db-$DBDATE
	mkdir db-$DBDATE/$TEXT
	TXTFILES=`ls $TEXT/*.txt | egrep -v '^(help|wizhelp|qhelp|mushman).txt'`
	mv -f $TXTFILES db-$DBDATE/$TEXT
	echo "Restoring archive."
	$UNZIP $ARCHIVE | tar -xvf -
	INFILE=`basename $ARCHIVE | sed -e "s/\\.tar\\.$ZEXT\$//" | sed -e "s/\\-archive/\\.flat/"`
	. mush.config
	. check_paths
	echo "Restoring flatfile $INFILE ..."
	$BIN/dbconvert -c $GAMENAME.conf -d $DATA -D $GDBM_DB -X $DATA/$GDBM_DB < $INFILE
	rm $INFILE ;;
    *.tar.*) echo "Restoring module databases and flatfile."
	INFILE=`echo $ARCHIVE | sed -e "s/\\.tar\\.$ZEXT\$//"`
	$UNZIP $ARCHIVE | tar -xvf -
	$BIN/dbconvert -c $GAMENAME.conf -d $DATA -D $GDBM_DB -X $DATA/$GDBM_DB < $INFILE
	rm $INFILE ;;
    *) echo "Restoring flatfile."	
	$UNZIP $ARCHIVE | $BIN/dbconvert -c $GAMENAME.conf -d $DATA -D $GDBM_DB -X $DATA/$GDBM_DB ;;
esac