#!/bin/sh
#
# demo install

clear
echo "+----------------------------------------------------------------------+"
echo "| MEUF Demo version Installation script                                |"
echo "|                                                                      |"
echo "| Please answer all the following questions in order to install Meuf   |"
echo "+----------------------------------------------------------------------+"

echo 
echo
echo "In which directory do you wish to install the Meuf demo package ?"
echo "[default value=/usr/local/meuf-demo]"
read MEUFDIR
if [ -z "${MEUFDIR}" ]
then
	MEUFDIR="/usr/local/meuf-demo";	export MEUFDIR
fi

echo
echo "====> Creating directory"
mkdir -p ${MEUFDIR}

echo
echo "In which directory do you wish to install the script calling the"
echo "binary program ? [/usr/local/bin]"
read BINDIR
if [ -z "$BINDIR" ]
then
	BINDIR="/usr/local/bin"  ; export BINDIR
fi

echo
SCRIPT=${BINDIR}/meuf
echo "====> Building script"
echo "#!/bin/sh" > ${SCRIPT}
echo "#" >> ${SCRIPT}
echo >> ${SCRIPT}
echo "MEUFDIR=${MEUFDIR}" >> ${SCRIPT}
echo "export MEUFDIR" >> ${SCRIPT}
echo >> ${SCRIPT}
echo "\${MEUFDIR}/meuf -fn courier $""*" >> ${SCRIPT}
chmod 755 ${SCRIPT}

echo
echo "If you already have the Faces database on your system, please"
echo "enter its access path. [/usr/local/faces]"
read FACEDIR
if [ -z "${FACEDIR}" ]
then
	FACEDIR="/usr/local/faces"; export FACEDIR
fi

local_faces=no
if [ ! -d "${FACEDIR}" ]
then
	FACEDIR="${MEUFDIR}/faces"; export FACEDIR
	local_faces=yes
fi

echo
echo "Please enter the default site for faces retrieval. For instance,"
echo "if your site is asd.def.com, please enter com/def/asd."
read DEFORG

echo "====> Building default Meuf configuration"
CONFIG=${MEUFDIR}/meufrc
echo "set helpfile \"${MEUFDIR}/meuf.info\"" > ${CONFIG}
echo "defaultorg \"${DEFORG}\"" >> ${CONFIG}
echo "set mime on" >> ${CONFIG}
echo "set facedir \"${FACEDIR}\"" >> ${CONFIG}

echo
echo "Please enter the mpeg_play tool path. [/usr/local/bin/mpeg_play]"
read MPEGBIN
if [ -z "${MPEGBIN}" ]
then
	MPEGBIN="/usr/local/bin/mpeg_play"; export MPEGBIN
fi

echo
echo "Please enter the PostScript viewer path. [/usr/openwin/bin/pageview]"
read PSBIN
if [ -z "${PSBIN}" ]
then
	PSBIN="/usr/openwin/bin/pageview";	export PSBIN
fi

echo
echo "Please enter the audio tool path. [/usr/openwin/bin/audiotool]"
read AUDIOBIN
if [ -z "${AUDIOBIN}" ]
then
	AUDIOBIN="/usr/openwin/bin/audiotool"; export AUDIOBIN
fi

echo
echo "Please enter the image viewer path. [/usr/local/bin/xv]"
read XVBIN
if [ -z "${XVBIN}" ]
then
	XVBIN="/usr/local/bin/xv"; export XVBIN
fi

echo
echo "Please enter the text viewer path. [/usr/local/bin/xemacs]"
read TEXTBIN
if [ -z "${TEXTBIN}" ]
then
	TEXTBIN="/usr/local/bin/xemacs"; export TEXTBIN
fi

mpegbin=`echo $MPEGBIN | sed -e "s/\//~/g"`
psbin=`echo $PSBIN | sed -e "s/\//~/g"`
audiobin=`echo $AUDIOBIN | sed -e "s/\//~/g"`
xvbin=`echo $XVBIN | sed -e "s/\//~/g"`
textbin=`echo $TEXTBIN | sed -e "s/\//~/g"`
meufdir=`echo $MEUFDIR | sed -e "s/\//~/g"`
facedir=`echo $FACEDIR | sed -e "s/\//~/g"`

echo
echo "====> Building MIME configuration file"
sed -e "s/MPEGBIN/${mpegbin}/g" -e "s/PSBIN/${psbin}/g" -e "s/AUDIOBIN/${audiobin}/g" -e "s/XVBIN/${xvbin}/g" -e "s/TEXTBIN/${textbin}/g" -e "s/MEUFDIR/${meufdir}/g" -e "s/FACEDIR/${facedir}/g" meufcap > meufcap2

sed -e "s/~/\//g" meufcap2 > ${MEUFDIR}/meufcap
rm meufcap2

echo
echo "====> Copying files to ${MEUFDIR}"
cp meuf.Z ${MEUFDIR}
uncompress ${MEUFDIR}/meuf.Z
cp retext ${MEUFDIR}
cp -R meuf.info ${MEUFDIR}
cp xbmtoface.Z ${BINDIR}
uncompress ${BINDIR}/xbmtoface.Z

echo
echo "====> Retrieving Faces database"
if [ "${local_faces}" = "yes" ]
then
	PWD=`pwd`;	export PWD
	cd ${MEUFDIR}; uncompress -c ${PWD}/logos.tar.Z | tar xf -
else
	echo "      already in the system."
fi

echo
echo "============================================================"
echo "Installation complete. Don't forget the manual pages.
echo "You can remove the current directory."
echo
echo "Your demo version is valid until 15 March 1994."
echo
echo
