#!/bin/sh
echo " "
basedir=`pwd`
echo "Please, inform the ROOT System version you want download, compile and install (ex. 5.20.00): "
echo " "
read version
cd /usr/local
	test -d root
	dir=$?
	if test $dir = 1
		then
		echo "Creating /usr/local/root"
		sudo mkdir root
	fi	
cd $basedir
#
#  comment and uncomment the relevant line, depending if you have or 
#  not a local copy of the root source code
#
##echo "Downloading ROOT v"$version" from root.cern.ch"
##wget -c "ftp://root.cern.ch/root/root_v"$version".source.tar.gz"
cp root_v"$version".source.tar.gz /usr/local/root/.
#
echo "ROOT System download concluded. Installing packages needed to compile the ROOT System in Ubuntu..."
sudo apt-get -y --force-yes install build-essential libx11-dev libxpm-dev libxft-dev libgl1-mesa-dev libglu1-mesa-dev libmysqlclient15-dev libsqlxx-dev libpng12-dev libgif-dev libungif4-dev python2*-dev libxml2-dev libgsl0-dev libgmp3-dev libjpeg62-dev libtiff4-dev libffi* cernlib   dpkg-dev make g++ gcc binutils libx11-dev libxpm-dev libxft-dev libxext-dev gfortran ncurses-dev libpcre3-dev xlibmesa-glu-dev libglew1.5-dev libftgl-dev libmysqlclient-dev libfftw3-dev cfitsio-dev graphviz-dev libavahi-compat-libdnssd-dev libldap2-dev python-dev libxml2-dev libssl-dev libkrb5-dev libgsl0-dev libafterimage-dev libglite* libGLU-dev ruby-dev
#sudo apt-get -y --force-yes install build-essential
#sudo apt-get -y --force-yes install libx11-dev
#sudo apt-get -y --force-yes install libxpm-dev
#sudo apt-get -y --force-yes install libxft-dev
#sudo apt-get -y --force-yes install libgl1-mesa-dev
#sudo apt-get -y --force-yes install libglu1-mesa-dev
#sudo apt-get -y --force-yes install libmysqlclient15-dev
#sudo apt-get -y --force-yes install libsqlxx-dev
#sudo apt-get -y --force-yes install libpng12-dev
#sudo apt-get -y --force-yes install libgif-dev
#sudo apt-get -y --force-yes install libungif4-dev
#sudo apt-get -y --force-yes install python2.5-dev
#sudo apt-get -y --force-yes install libxml2-dev
#sudo apt-get -y --force-yes install libgsl0-dev
#sudo apt-get -y --force-yes install libgmp3-dev
#sudo apt-get -y --force-yes install libjpeg62-dev
#sudo apt-get -y --force-yes install libtiff4-dev
#sudo apt-get -y --force-yes install libffi4-dev   
#sudo apt-get -y --force-yes install cernlib 
cd /usr/local/root
tar -zxvf "root_v"$version".source.tar.gz"
sudo mv root root_v$version
export ROOTSYS=`pwd`/root_v$version
export PATH=$PATH:$ROOTSYS/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
cd root_v$version 
pwd
## for Intel processor, uncomment this line
./configure linux --enable-roofit --enable-python --enable-asimage --enable-astiff --enable-exceptions --enable-explicitlink --enable-fftw3 --enable-fitsio --enable-gviz --enable-glite --enable-mathmore --enable-memstat --enable-minuit2 --enable-mysql --enable-reflex --enable-rpath --enable-ruby --enable-shared --enable-table --enable-tmva --enable-unuran --enable-x11 --enable-xml --enable-xft --disable-xrootd
make
make install
cd ../
rm -rf pro
ln -s root_v$version pro
sudo rm -rf root_v$version.source.tar.gz
echo "ROOT System is compiled and installed! Enjoy!"
echo "set the environment variables to:"
echo "ROOTSYS --> /usr/local/root/pro"
echo "PATH --> $ROOTSYS/bin"
echo "LD_LIBRARY_PATH --> $ROOTSYS/lib"

exit
