#!/bin/sh

make

user=`id -un`

echo
echo "Where do you want to install the slocate binary?"
echo -n "[/usr/local/bin/]: "
read instdir

if [ "$instdir" = "" ] ; then
   instdir="/usr/local/bin"
fi

if [ ! -d "$instdir" ] ; then
   echo
	echo -n "Directory: $instdir does not exist. Create it? [Y]/N : "
	read yesno
	if [ "$yesno" = "" ] ; then
	   yesno="Y";
	elif [ "$yesno" = "y" ] ; then
	   yesno="Y"
	fi
	
	if [ "$yesno" = "Y" ] ; then
      mkdir -p $instdir
   else
	   echo
		echo "Install aborted."
		echo
		exit 1
	fi

fi

echo
echo "Copying slocate to $instdir"
cp slocate $instdir

if ! grep slocate /etc/group >/dev/null
then
   echo
   echo "The group \"slocate\" must be created in order secure the slocate"
   echo -n "database.  Is it okay to do this? [Y]/N/S : "
   read yesno
	
	if [ "$yesno" = "" ] ; then
      yesno="Y";
   elif [ "$yesno" = "y" ] ; then
      yesno="Y"
   fi

   if [ "$yesno" = "Y" ] ; then
	   echo
		echo "Adding group: slocate"
      groupadd slocate
   else
      echo
	   echo "Install aborted."
		echo
		exit 1
	fi

fi

CWD="`pwd`"

cd $instdir
echo
echo "Changing permisions on slocate"
chown $user.slocate slocate
chmod a-w ./slocate
chmod a+rx ./slocate
chmod g+s ./slocate
cd $CWD

echo
echo "Creating slocate database directory: /var/lib/slocate"
mkdir -p /var/lib/slocate

echo
echo "Install Complete!"
echo


