
# This is a build and install script for pov under Linux

# convenience function
askplace()
{
   done=0
	while [ $done -ne 1 ]
	do
		echo -n "Where should I put the $stuff? [$defdir] "
		read destdir
		if [ -z "$destdir" ]; then
			destdir=$defdir
			done=1
		elif [ -d "$destdir" -a -w "$destdir" ]; then
			done=1
		else
			echo "  Either $destdir is not a directory...or you don't have"
			echo "  permission to write to it..."
			echo -n " Would you like for me to make it?"
			read ans
			case $ans in
			   [yY]|[Yy][Ee][sS]) mkdir -p $destdir; chmod 755 $destdir
			   	if [ -d $destdir -a -w $destdir ]; then
			   		echo "OK...$destdir created."
			   		done=1
					fi
					;;
			esac
		fi
	done
}

if [ ! -f source/povray ]
then
   echo "The ray tracer will now be built.."
   (cd source; make)
else
   echo "The ray tracer seems to already have been built..."
fi

# move povray
defdir=/usr/local/bin
stuff=executables
askplace
cp source/povray $destdir; chmod 555 $destdir/povray
echo "Povray outputs in a rather nasty (to Linux) format...(bummer dude). This "
echo "distribution includes a utility called qrttoppm that will convert"
echo "the .dis format output by povray into a .ppm format (which is viewable"
echo "by xv 3.0)"
echo -n "Would you like to install qrttoppm in $destdir? "
read ans
case $ans in
	[yY]|[Yy][Ee][sS]) 
		cp bin/qrttoppm $destdir
		;;
esac

# move the include files, and set up a defaults file.
defdir=/usr/local/pov/include
stuff="include files"
askplace
echo "Copying include files..."
cp doc/include/* $destdir; chmod 444 $destdir/*
echo "Creating defaults file in $HOME"
echo "+L$destdir" > $HOME/.povray.def

defdir=/usr/local/pov/scenes
stuff="demo scene files"
askplace
scenedir=$destdir
echo "Copying scene files..."
cp -r scenes/* $destdir

defdir=/usr/local/pov/doc
stuff="Documentation (ASCII format)"
askplace
echo "Copying docs..."
cp doc/docs/* $destdir

echo "All done!"
echo "You can try this thing out right now...start X windows, open an xterm"
echo "then:"
echo "$ cd $scenedir/level1"
echo "$ povray +W100 +H100 +d +Iblob.pov"
