#!/bin/csh -f
#
# Change the FBDIR to point towards the game/ directory of your old
# FuzzBallMUCK. This should be the file with the restart script, muf dir,
# logs dir, etc.
#
set HOME = $HOME
set FBDIR = $HOME/fb5.66/game

#
# Make sure that this points to the game/ directory of your new copy
# of ProtoMUCK.
#

set PROTODIR = $HOME/proto/game
set PROTOSRC = $HOME/proto/src

#
# If your FuzzBall directories were not changed from the standard
# configuration, you should not need to change anything below. Note
# that only one copy of the data base is essential, either std-db.db
# or std-db.new. If one or the other is missing, the upgrade will still
# run fine.
#


set MUFDIR = $FBDIR/muf
set LOGSDIR = $FBDIR/logs
set DBOLD = $FBDIR/data/std-db.db
set DBNEW = $FBDIR/data/std-db.new
set WELCOMET = $FBDIR/data/welcome.txt
set NEWST = $FBDIR/data/news.txt
set NEWSD = $FBDIR/data/news
set MOTD = $FBDIR/data/motd.txt
set MPIHELPD = $FBDIR/data/mpihelp
set MAND = $FBDIR/data/man
set INFOD = $FBDIR/data/info
set HELPD = $FBDIR/data/help
set CONNECT = $FBDIR/data/connect.txt
set PARMFILE = $FBDIR/data/parmfile.cfg             
################################################################
#
# You should not have to change anything below here.
#
################################################################

echo "---------------------------------------------"
echo "FuzzBall5.xx    --->    ProtoMUCK AutoUpgrade  "
echo "---------------------------------------------"

#Check for the proto/src directory. If there, compile.
if ( -r $PROTOSRC ) then
        if ( -r $PROTODIR/protomuck ) then
                rm $PROTODIR/protomuck
        endif
        echo "Runing configuration script."
        cd $PROTOSRC
        ./configure
        cd $PROTODIR/..
        echo "Running make depend then make install"
        make depend -C $PROTOSRC
        make install -C $PROTOSRC
        if (! -r $PROTODIR/protomuck ) then
                echo "Error in compiling. Cancelling upgrade."
                exit 0
        endif
endif

echo " "
echo "Now copying over from $FBDIR"
echo " "

#Check for the neon/game game directory.
if (! -r $FBDIR ) then
        echo "No Neon directory found to upgrade."
        echo "Check FBDIR path."
        exit 0
endif

#check for a std-db.db or std-db.new to upgrade from
if (! -r $DBOLD & ! -r $DBNEW ) then
        echo "You need a data base to upgrade from."
        echo "Check the paths set above for std-db.db or std-db.new."
        exit 0                                                  
endif

#check for MUF dir. Wouldn't be a good upgrade without it.
if (! -r $MUFDIR ) then
        echo "MUF directory not found. Dangerous to upgrade with out."
        echo "Check the paths set above for the muf directory"
        exit 0
endif

#The rest of the files aren't essential to an upgrade, so are not
#checked for.

echo "Copying std-db.db and std-db.new and renaming to"
echo "proto.db and proto.new"

cp -f $DBOLD $PROTODIR/data/proto.db
cp -f $DBNEW $PROTODIR/data/proto.new

echo "Copying all MUF code to $PROTODIR/"
cp -f -R $MUFDIR $PROTODIR/

#Got the essentials done, now copy the rest.

echo " "
echo " "

if ( -r $PARMFILE ) then
        echo "Copying @tune parameters as parmfile.cfg to $PROTODIR/data/"
        cp -f $PARMFILE $PROTODIR/data/
endif

if ( -r $LOGSDIR ) then
        echo "Copying contents of log directory to $PROTODIR/log/"
        cp -f -r $LOGSDIR $PROTODIR/
endif

if ( -r $WELCOMET ) then
        echo "Copying welcome.txt to $PROTODIR/data/"
        cp -f $WELCOMET $PROTODIR/data/
endif

if ( -r $NEWST ) then
        echo "Copying news.txt to $PROTODIR/data/"
        cp -f $NEWST $PROTODIR/data/
endif

if ( -r $NEWSD ) then
        echo "Copying news directory to $PROTODIR/data/news/"
        cp -f -r $NEWSD $PROTODIR/data/
endif

if ( -r $MOTD ) then
        echo "Copying motd.txt to $PROTODIR/data/"
        cp -f $MOTD $PROTODIR/data/
endif

if ( -r $CONNECT ) then
        echo "Copying connect.txt to $PROTODIR/data/ directory."
        cp -f $CONNECT $PROTODIR/data/
endif   

if ( -r $MPIHELPD ) then
        echo "Copying mpihelp directory to $PROTODIR/data/mpihelp/"
        cp -f -r $MPIHELPD $PROTODIR/data/
endif

if ( -r $MAND ) then
        echo "Copying man directory to $PROTODIR/data/man/"
        cp -f -r $MAND $PROTODIR/data/
endif

if ( -r $INFOD ) then
        echo "Copying info directory to $PROTODIR/data/info/"
        cp -f -r $INFOD $PROTODIR/data/
endif

if ( -r $HELPD ) then
        echo "Copying help directory to $PROTODIR/data/help/"
        cp -f -r $HELPD $PROTODIR/data/
endif

echo " "
if ( -r $PROTODIR/data/proto.new ) then
        echo "**std-db.new found, copying over proto.db**"
      cp -f $PROTODIR/data/proto.new $PROTODIR/data/proto.db
endif

echo " "
echo "Converting FuzzBall data base to Proto."
cd $PROTODIR
./protomuck -convert data/proto.db data/proto.db
cd ..

touch game/logs/status
echo "`date` - `who am i` ran the Neon --> Proto upgrade script." >> game/logs/status

echo " "
echo " "
echo "--------------------------------------------------"
echo "             Welcome to ProtoMUCK"
echo "--------------------------------------------------"
echo " "
echo "If you are seeing this message, then your upgrade "
echo "from FB5.xx went smoothly. You should -NEVER-   "
echo "run this script again once starting up your copy  "
echo "of Proto. Doing so may result in the loss of your "
echo "database."
echo "Check the settings in the $PROTODIR/restart "
echo "script to make sure the locations are correct."
echo "**MAKE SURE THE OLD COPY OF FB5.xx IS SHUT DOWN.**"
echo "Then change to $HOME/proto/ and type ./proto start"
echo "to start the MUCK."                                      
