#!/bin/sh
####################################
#
# makeinstall 3.01
#
# installs $* to INSTALLDIR
# CHMOD gives the mode for the files
#
####################################
#set -x

echo "MakeInstall 3.01"
echo

##### First determine if there is a directory
##### to install to

if [ "$INSTALLDIR" = "" ]; then
  echo "No installation directory specified, not installing."
  exit
fi
if [ "$CHMOD" = "" ]; then
  echo "Variable CHMOD is not set, error, can't install!"
  exit
fi

##### Now just begin installing

echo "Installing to $INSTALLDIR"


##### Make the installdir if it doesn't exist

if [ ! -x $INSTALLDIR ]
then
  mkdir $INSTALLDIR
  if [ $? != 0 ]; then
    echo "Couldn't make install directory '$INSTALLDIR'"
    exit 2
  fi
fi

##### Install the things to install

for i in $*
do
  if [ -r $INSTALLDIR/$i ]; then
    chmod -R 755 $INSTALLDIR/$i
    rm -rf $INSTALLDIR/$i
  fi

  echo "  installing $i"

  tar cf /tmp/makeinstall.$$ $i
  (cd $INSTALLDIR; tar xf /tmp/makeinstall.$$)

  if [ -d $INSTALLDIR/$i ]; then
    find $INSTALLDIR/$i -type d -exec chmod 555 {} \;
    find $INSTALLDIR/$i -type f -exec chmod $CHMOD {} \;
  else 
    chmod $CHMOD $INSTALLDIR/$i
  fi
done
rm -f /tmp/makeinstall.$$

##### If we've got another script to execute
##### with this installation, execute it.

if [ "$INSTALLEXE" ]
then
  echo "executing INSTALLEXE=$INSTALLEXE"
  $INSTALLEXE $*
fi

##### We're ready

echo "done."
echo


