#!/bin/csh -f 
#
# Change the NEONDIR to point towards the game/ directory of your old
# NeonMUCK. This should be the file with the restart script, muf dir, 
# logs dir, etc.
#
set HOME = $HOME
set NEONDIR = $HOME/neon/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 NeonMUCK 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 neon.db 
# or neon.new. If one or the other is missing, the upgrade will still
# run fine.
#


set MUFDIR = $NEONDIR/muf
set MCPDIR = $NEONDIR/mcp
set LOGSDIR = $NEONDIR/logs
set FILESDIR = $NEONDIR/files
set DBOLD = $NEONDIR/data/neon.db
set DBNEW = $NEONDIR/data/neon.new
set WELCOMET = $NEONDIR/data/welcome.txt
set WELCOMEH = $NEONDIR/data/welcome.html
set WELCOMED = $NEONDIR/data/welcome
set NEWST = $NEONDIR/data/news.txt
set NEWSD = $NEONDIR/data/news
set MOTD = $NEONDIR/data/motd.txt
set MPIHELPD = $NEONDIR/data/mpihelp
set MAND = $NEONDIR/data/man
set INFOD = $NEONDIR/data/info
set HELPD = $NEONDIR/data/help
set CONNECT = $NEONDIR/data/connect.txt
set PARMFILE = $NEONDIR/data/parmfile.cfg
################################################################
# 
# You should not have to change anything below here.
#
################################################################

echo "---------------------------------------------"
echo "  NeonMUCK    --->    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 $NEONDIR"
echo " "

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

#check for a neon.db or neon.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 neon.db or neon.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 neon.db and neon.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 $MCPDIR ) then
	echo "Copying any MCP code to $PROTODIR/mcp/" 
	cp -f -r $MCPDIR $PROTODIR/
endif

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

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

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

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

if ( -r $WELCOMED ) then
	echo "Copying welcome/ directory to $PROTODIR/data/welcome/"
	cp -f -r $WELCOMED $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 $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

if ( -r $CONNECT ) then
	echo "Copying connect.txt to $PROTODIR/data/ directory."
	cp -f $CONNECT $PROTODIR/data/
endif
echo " "
if ( -r $PROTODIR/data/proto.new ) then
	echo "**neon.new found, copying over proto.db**"
      cp -f $PROTODIR/data/proto.new $PROTODIR/data/proto.db
endif   

echo " "
echo "Converting Neon 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 NeonMUCK 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 NEONMUCK IS SHUT DOWN.**"
echo "Then change to $HOME/proto/ and type ./proto start"
echo "to start the MUCK."
