#!/bin/bash

##
## Edit the following three lines to change where HOH is installed to:
##

# programs
export BIN=/usr/local/bin

# data files
export DATA=/usr/local/share/games/HoH

# documentation
export DOCS=/usr/local/share/doc/HoH


##
## Now say what's going to happen
##

echo
echo Head-Over-Heels installer
echo -------------------------
echo
echo Head Over Heels will be installed in the following directories
echo \(You may need to be logged in as root for this to work.\):
echo
echo Program: $BIN/
echo Datafiles: $DATA/
echo Documenatation: $DOCS/
echo
echo ..if you want to change this, edit the 'install.sh' file.
echo
echo 
echo Press ENTER to continue, or Control-C to quit.
echo
read

echo ---------------------------
echo

##
## Now do the installation
##

echo
echo Installing..


mkdir -p $BIN
rm -f $BIN/hoh >& /dev/null
echo "#!/bin/bash" > $BIN/hoh
echo "export LD_LIBRARY_PATH=$DATA/runtime" >> $BIN/hoh
echo "cd $DATA" >> $BIN/hoh
echo "exec ./HoH \$@" >> $BIN/hoh

if ! test -f $BIN/hoh
then
	echo "Couldn't create file $BIN/hoh"
	echo
	echo "You may need to be root for this to work"
	exit 1
fi

chmod +x $BIN/hoh &> /dev/null
mkdir -p $DATA
mkdir -p $DOCS

if ! cp -af ./data/* $DATA/
then
	echo "Couldn't copy game data"
	echo
	echo "You may need to be root for this to work"
	exit
fi

if ! cp -af ./docs/* $DOCS/
then
	echo "Couldn't copy documentation"
	echo
	echo "You may need to be root for this to work"
	exit
fi

##
## Make an uninstaller
##

export GOAWAY=$BIN/hoh-uninstall

echo echo This will remove Head Over Heels > $GOAWAY
echo echo >> $GOAWAY
echo echo Press ENTER to continue, or Control-C to quit.>> $GOAWAY
echo echo >> $GOAWAY
echo read >> $GOAWAY
echo rm -f $BIN/hoh >> $GOAWAY
echo rm -rf $DATA >> $GOAWAY
echo rm -rf $DOCS >> $GOAWAY
echo rm -f $BIN/hoh-uninstall >> $GOAWAY
echo echo >> $GOAWAY
echo echo Done. >> $GOAWAY
chmod +x $GOAWAY

echo
echo
echo ---------------------------
echo
echo Done
echo
echo You can start the game by typing \'hoh\'
echo
echo You can remove the game by typing \'hoh-uninstall\'
echo

