binary=`which bash`


#! $binary



function getamigenepath {
		echo "Enter the new PATH : "
                read AMIGENE
                echo "Your choice : " $AMIGENE
} 

AMIGENE="/usr/local/share/amigene/"

echo "|------------------------------------------------------|"
echo "|                                                      |" 
echo "|             Amigene Package Installation             |"
echo "|                                                      |" 
echo "|------------------------------------------------------|"
echo
echo
echo "Current Amigene directory : " $AMIGENE
echo "Do you want to install Amigene package in this directory ? (yes|no) "
read answer
while [ $answer != "yes" -a $answer != "no" ]   
do
	echo "answer by yes or no" ; read answer
done

mv runAMIGA.sh runAMIGA.sh.tmp
mv amiga_run.sh amiga_run.sh.tmp


case $answer in
	yes) echo "Proceeding ...."
		cat amiga_run.sh.tmp | gawk -v bashpath=$binary '{if ( $0 ~ /#! / ) {print "#! "bashpath ; } else { print $0;} }' > amiga_run.sh
		cat runAMIGA.sh.tmp | gawk  -v bashpath=$binary '{if ($0 ~ /#! / ) {print "#! "bashpath ; } else { print $0;} }' > runAMIGA.sh
	;;
	no)	getamigenepath 
		echo "Are you sure ? (yes|no)"
		read answer2
		while [ $answer2 != "yes" -a $answer2 != "no" ]
		do
			echo "answer by yes or no" ; read answer2
		done
		if [ $answer2 = "no" ]
			then getamigenepath
		fi
		cat amiga_run.sh.tmp | gawk -v bashpath=$binary '{if ( $0 ~ /\#\! / ) {print "#! "bashpath ; } else { print $0;} }' > amiga_run.sh
		cat runAMIGA.sh.tmp | gawk -v amigenepath=$AMIGENE -v bashpath=$binary '{if ($0 ~ /AMIGAHOME="/) { print "AMIGAHOME=\""amigenepath"\""; } else { if ( $0 ~ /\#\! / ) {print "#! "bashpath ; } else { print $0;} } }' > runAMIGA.sh
		#mv runAMIGA.sh.tmp runAMIGA.sh
		#mv amiga_run.sh.tmp amiga_run.sh
	;;
esac

echo "Creating Amigene file : "$AMIGENE

#mkdir /usr/local/share/
mkdir $AMIGENE

echo "Copying Parameters files" 

cp *.seuils $AMIGENE

echo "Copying Amigene binairies"

cp amiga_filter_bis amiga_prk_score amiga_run.sh amiga_score1 prokov_curve prokov_learn prokov_orf pwg_translate spat runAMIGA.sh $AMIGENE

ln -s $AMIGENE/runAMIGA.sh /usr/local/bin/

if [ $? != "0" ] 
	then echo "Ask to root to put $AMIGENE/runAMIGA.sh in the PATH"
		echo "but you can work with  $AMIGENE/runAMIGA.sh" 
fi

echo "Change the rights"

chmod -R 777 $AMIGENE/*
