#! /bin/sh


#################################################################################
#                                                                               #
#    This file is part of GISMB.                                                #
#    GISMB Stands for 'GenEthic IRC Server Monitoring Bot'                      #
#                                                                               #
#    GISMB is free software; you can redistribute it and/or modify              #
#    it under the terms of the GNU General Public License as published by       #
#    the Free Software Foundation; either version 2 of the License.             #
#                                                                               #
#    GISMB is distributed in the hope that it will be useful,                   #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of             #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              #
#    GNU General Public License for more details.                               #
#                                                                               #
#    You should have received a copy of the GNU General Public License          #
#    along with GISMB; if not, write to the Free Software                       #
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  #
#                                                                               #
#################################################################################

echo GenEthic1.0 configuration process...


if [ "$1" = "" ]
then
	echo 'Syntax error'
	echo "$0 <absolute_path_where_to_install>"
	exit 1
else
	TEST=`echo $1 | sed "s/^\/.*/X/"`
	if [ "$TEST" != "X" ]
	then
		echo Error, $1 is not an absolute path
		exit 1
	fi
fi

if [ -d "$1" ]
then
	echo Looks good, using $1 as installation directory
else
	echo  Creating $1 directory
	mkdir $1
fi

echo 'Trying to find out where you are hiding your perl... \c'

PERL=`which perl`;

if [ -x "$PERL" ]
then
	PVER=`$PERL -v | grep version | sed "s/.*version //"`
	echo $PERL $PVER
else
	echo 
	echo Sorry, cant find it
	exit 1
fi

echo Creating needed directories...
mkdir $1/etc
mkdir $1/bin
mkdir $1/var
mkdir $1/log

echo Copying files...
cp README   $1/
cp COPYING   $1/
cp CHANGES  $1/
cd src
echo "#!$PERL"  >  $1/bin/genethic.pl
cat genethic.pl >> $1/bin/genethic.pl
chmod 755          $1/bin/genethic.pl
echo "#!/bin/sh" > $1/bin/runbot.sh
echo "BOTPATH=\"$1\"" >> $1/bin/runbot.sh
cat runbot.sh           >> $1/bin/runbot.sh
chmod 755          $1/bin/runbot.sh

cp sample.conf     $1/etc/
cp help.txt        $1/etc/
cp extra_data_sample.txt $1/etc/

echo done
echo Now do: cd $1
echo and read the README
