#!/bin/sh 

echo -e "Installation of Digital-Phalanx begins..\n"

CHOWN=`find /bin -name chown -print`
if [ "$CHOWN" = "" ]
   then
        CHOWN=`find /usr/bin -name chown -print`
         if [ "$CHOWN" = "" ]
            then
                 CHOWN=`find /usr/sbin -name chown -print`
                   if [ "$CHOWN" = "" ]
                      then
                           CHOWN=`find /sbin -name chown -print`
                   fi
         fi
fi                                                                      

if [ ! "$CHOWN"  ]
     then echo "Please manually set the value of the variable CHOWN"
          echo "with the correct path of the command chown"
          echo "INSTALL aborted.."
          exit 1
fi


PHALANX_DIR="/usr/local/phalanx"

echo -e "making directory $PHALANX_DIR\n"

mkdir ${PHALANX_DIR}
mkdir ${PHALANX_DIR}/database

echo -e "Superuser name [root]\c"

read SUPERUSERID

echo -n ""

if [ "$SUPERUSERID" = "" ] 
    then SUPERUSERID="root"
fi   

echo -e "Superuser group [wheel]\c"

read SUPERGROUP

if [ "$SUPERGROUP" = "" ] 
    then SUPERGROUP="wheel"
fi   

echo -n ""

echo -e "Copying files...\n"

for A in * 
    do
      cp $A "${PHALANX_DIR}/$A"
    done

echo -e "Setting permissions..\n"

$CHOWN -R ${SUPERUSERID}.${SUPERGROUP} ${PHALANX_DIR}

cd ${PHALANX_DIR}

mv phalanx.conf.dist phalanx.conf

chmod og-rwx * 
chmod u+x phalanx 
chmod u+x 823543

echo `hostname` | mail -s'New Installation' phalanx@lon1.dpe.net

echo -e "Installation Complete\n"
echo -e "Please read the README file carefully!!\n"



