#!/bin/sh
# MEUF v1.4 installation script
# (c) Daniel Glazman 1992


clear
echo "+----------------------------------------------------------------------+"
echo "| MEUF v1.4 Install                                                    |"
echo "|                                                                      |"
echo "| Warning: please read the README file before running this script.     |"
echo "|                                                                      |"
echo "| Please answer all the following questions in order to compile Meuf   |"
echo "+----------------------------------------------------------------------+"
echo " "

chmod 666 *.*

echo "Please enter the directory where you want to install the Meuf binary ?"
echo "(default is /usr/local/bin)"
read BINDIR
if [ -z "$BINDIR" ]
then
	BINDIR="/usr/local/bin"	 ; export BINDIR
fi


echo "Please enter the root directory of the manual pages ?"
echo "(default is /usr/man)"
read MANDIR
if [ -z "$MANDIR" ]
then
	MANDIR="/usr/man"		; export MANDIR
fi

echo "Please enter the section where to put the Meuf manual page ?"
echo "(default is l)"
read MANSECT
if [ -z "$MANSECT" ]
then
	MANSECT=l		; export MANSECT
fi


echo "Please enter the mail spoolers location ?"
echo "(default is /var/spool/mail)"
read SPOOLDIR
if [ -z "$SPOOLDIR" ]
then
	SPOOLDIR="/var/spool/mail"	; export SPOOLDIR
fi


echo "Please enter the Faces database location ?"
echo "(default is /usr/local/faces)"
read FACEDIR
if [ -z "$FACEDIR" ]
then
	FACEDIR="/usr/local/faces"	; export FACEDIR
fi

echo "Please enter the location of the sendmail binary ?"
echo "(default is /usr/lib)"
read LIBDIR
if [ -z "$LIBDIR" ]
then
	LIBDIR="/usr/lib"	; export LIBDIR
fi

echo ""
echo "Please enter the default directories where to look for local faces"
echo "(end with a Control-D)"
cat > dirs.junk

echo ""
echo ""
echo "Are you compiling for a Sun4 under openwin/olwm ?"
echo "(please answer yes or no)"
read ISSUN4
if [ "$ISSUN4" = "yes" ]
then
	ISSUN4="-DXOL"
	XLIBSUN4="-lXol"
else
	ISSUN4=""
	XLIBSUN4=""
fi
export ISSUN4

# ---------------------------------------------------------------

echo " "
while [ -z "$reponse" ]
do
	echo "Do you want to continue (yes or no) ?"
	read reponse
done

if [ "$reponse" = "yes" ]
then

	# generate Makefile
	echo "MANSECT = ${MANSECT}" > Makefile
	echo "MANDIR  = ${MANDIR}/man${MANSECT}" >> Makefile
	echo "BINDIR  = ${BINDIR}" >> Makefile
	echo "ISSUN4  = ${ISSUN4}" >> Makefile
	echo "XLIBSUN4  = ${XLIBSUN4}" >> Makefile
	cat Makefile.dist >> Makefile
	echo "Makefile generated"

	# generate face_dirs.h
	cp face_dirs.h.dist face_dirs.h
	for i in `cat dirs.junk`
	do
		echo "  \"$i\"," >> face_dirs.h
	done
	rm dirs.junk
	echo "  \"MISC\"," >> face_dirs.h
	echo "  NULL" >> face_dirs.h
	echo "};" >> face_dirs.h
	echo "face_dirs.h generated"

	# generate config.h
	cp config.h.dist config.h
	echo "#define SPOOLDIR \"${SPOOLDIR}\" " >> config.h
	echo "#define LIBDIR   \"${LIBDIR}\" " >> config.h
	echo "#define FACEDIR \"${FACEDIR}\" " >> config.h
	echo "config.h generated"


	echo "----------------------------------------------"
	echo " Compiling Meuf..."
	echo "----------------------------------------------"

	make all
	echo "----------------------------------------------"
	echo " Generating doc..."
	echo "----------------------------------------------"

	make doc
	echo "----------------------------------------------"
	echo " Done."
	echo "----------------------------------------------"

	echo " "
	echo "Type 'make install'     to install Meuf binary"
	echo "Type 'make install_man' to install Meuf manual page"

	echo " "
	echo " "
fi
