#!/bin/bash

echo "#####configuration#####"
qtdir="/usr/src"
target="/home/sascha/apps/theli"
curdir=`pwd`
theli="theli-1.6.1"
gui="gui-2.6.2"
qt="qt-x11-free-3.3.8b"
scamptarget="$target/theli/bin/Linux_64/scamp"


echo "#####install debian-packages as needed#####"
#on my system only the following were necessary
#sudo apt-get install libgsl0-dev libfftw3-dev libpng3

#from theli-site
#sudo apt-get install gfortran csh g++ libqt3-mt-dev gawk gettext wget
#sudo apt-get install tcl8.5-dev tk8.5-dev netpbm imagemagick libfftw3-dev
#sudo apt-get install xorg-dev pgplot5 libtiff4 libtiff4-dev libpng3
#sudo apt-get install binutils-dev build-essential libtie-ixhash-perl
#sudo apt-get install libncurses5-dev perl xterm gzip pdl emacs
#sudo apt-get install python python-dev python-numpy libxxf86vm-dev
#sudo apt-get install python-scipy python-matplotlib libgsl0ldbl libgsl0-dev

echo "#####qt3 installation#####"
if [ ! -d "$qtdir/$qt" ]
then
	mkdir -p $qtdir
	cd $qtdir
	#dl
	wget ftp://ftp.qt-project.org/qt/source/$qt.tar.gz
	#extract
	tar xfz $qt.tar.gz
	rm $qt.tar.gz
	cd $qt
	#configure
	./configure -fast
	#patch qvaluelist.h
	wget -O - http://www.parsecs.de/sites/www.parsecs.de/files/qvaluelist.patch | patch -p0
	#make
	make sub-src sub-tools
else
	echo "#####skipped#####"
fi

echo "#####now let's start with actual theli installation#####"
mkdir -p $target

echo "#####set qtdir for later qmake-call inside install.sh#####"
export QTDIR=$qtdir/$qt

echo "#####theli-pipeline#####"
cd $target
wget http://www.astro.uni-bonn.de/theli/gui/download/$theli.tgz
tar xfz $theli.tgz
rm $theli.tgz
cd $theli/pipesetup
./install.sh -m "ALL"

echo "#####theli-gui#####"
cd $target
wget http://www.astro.uni-bonn.de/theli/gui/download/$gui.tgz
tar xfz $gui.tgz
rm $gui.tgz
cd $gui
#patch install.sh
wget -O - http://www.parsecs.de/sites/www.parsecs.de/files/install.sh__0.patch | sed "s=THEQTBINDIR=$qtdir/$qt/bin/=g" | patch -p0
#all right
./install.sh

echo "#####scamp#####"
wget -O $scamptarget http://www.astro.uni-bonn.de/theli/gui/download/scamp-1.4.6.mp.x86_64/scamp
chmod a+x $scamptarget

cd $target/gui