#!/bin/sh
#
# Install the binaries from the distribution.
#
set -e

if echo '\c' | grep -s c >/dev/null 2>&1
then
   ECHO_N="echo -n"
   ECHO_C=""
else
   ECHO_N="echo"
   ECHO_C='\c'
fi

# Here is the default:
if [ "${bindir}" = "" ]; then bindir="/www/bin"; fi

# Get the name of a directory to install binaries in.
echo ""
echo "This script installs the Meta-HTML binaries for you, in the location"
echo "that you specify.  Once the binaries are installed, you may type"
echo ""
echo "        \`./install-site'"
echo ""
echo "to install the server or engine, release notes, applications, and"
echo "tagsets that came with your distribution."
echo ""
echo "We would like to install the binaries that came with your distribution"
echo "in a directory by themselves.  After installation is complete, you"
echo "should add this directory to the end of your PATH variable.  You"
echo "may install the binaries anywhere that you would like, but why not"
echo "install in a separate directory first, and then move them later?"
echo ""
echo "Where would you like the server, engine, and utility binaries to be"
echo "installed?"
${ECHO_N} "(Path, without trailing slash) default: [${bindir}] ${ECHO_C}"
read temp
if [ "$temp" = "" ]; then temp="${bindir}"; fi
bindir="$temp"

# Make the install directory if it does not already exist.
set `echo ${bindir} | sed -e 's@/@ @g'`
fullpath=/
for dir in $*; do
   if [ ! -d ${fullpath}${dir} ]; then
      echo "   mkdir ${fullpath}${dir}"
      mkdir ${fullpath}${dir}
   fi
   fullpath=${fullpath}${dir}/
done

# Okay, now install everything.
if [ -d Utilities ]; then
   echo "  Installing the utility programs into ${bindir}"
   doneone=
   ${ECHO_N} "    ${ECHO_C}"
   for file in Utilities/*; do
      pretty_file=`echo $file | sed -e 's@.*/@@'`
      if [ "$doneone" ]; then
	 ${ECHO_N} ", ${ECHO_C}"
      else
	 doneone=true
      fi
      ${ECHO_N} "$pretty_file ${ECHO_C}"
      if ! cp $file $bindir/; then
	 echo "   Unable to create the file \"$bindir/$file!\""
	 echo "The install was aborted."
	 echo ""
	 exit
      fi
   done
   echo "."
fi

# Install the Server if it is present.
if [ -d server ]; then
   echo "  Installing the Mhttpd Web Server into ${bindir}"
   cp server/mhttpd ${bindir}/
fi

# Install the Engine if it is present.
if [ -d engine ]; then
   echo "  Installing the Mhttpd CGI Engine into ${bindir}"
   cp engine/engine ${bindir}/
fi

# Install the Processor if it is present.
if [ -d mhc ]; then
   echo "  Installing the Standalone Processor (mhc) into ${bindir}"
   cp mhc/mhc ${bindir}/
fi

# Install the Debugger if it is present.
if [ -d mdb ]; then
   echo "  Installing the Debugger (mdb) into ${bindir}"
   cp mdb/mdb ${bindir}/
fi

echo ""
echo "Done installing the binaries that came with this package."
echo ""
exit 0
