#! /bin/bash

# This script is meant to be run on Rocks Linux 5.4 as an user (not as root).
# Run this script anywhere within /home/ to install dftb+ automatically in /home/user/dftb+.

#Prerequisite: 
#Intel ifort and mkl library 11.1.072 are already installed in /share/apps/intel


mkdir ~/dftb+
cd  ~/dftb+
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/dftbp_snapshot-081217_autotest.tar.gz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/dftbp_snapshot-081217_src.tar.gz
tar -xzvf dftbp_snapshot-081217_autotest.tar.gz 
tar -xzvf dftbp_snapshot-081217_src.tar.gz

wget http://www2.fizik.usm.my/configrepo/howto/dftb+/manual.pdf
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/band_struct.tar.gz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/first_calc.tar.gz
tar xvfz band_struct.tar.gz
tar xvfz first_calc.tar.gz

# Rename autotest folder and move all SK files into /autotest/slako. Unzip these SK files here. 

mv dftb+_snapshot-081217_autotest autotest
cd autotest/slako 
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/SKFiles/hyb-0-1.tar.gz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/SKFiles/mio-0-1.tar.gz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/SKFiles/pbc-0-1.tar.gz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/SKFiles/rare-0-1.tgz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/SKFiles/matsci-0-1.tar.gz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/SKFiles/trans3d-0-1.tar.gz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/SKFiles/pbc-0-2.tgz
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/SKFiles/znorg-0-1.tar.gz

rm index.*
tar xvfz hyb-0-1.tar.gz 
tar xvfz mio-0-1.tar.gz 
tar xvfz pbc-0-1.tar.gz 
tar xvfz rare-0-1.tgz 
tar xvfz matsci-0-1.tar.gz 
tar xvfz trans3d-0-1.tar.gz 
tar xvfz pbc-0-2.tgz 
tar xvfz znorg-0-1.tar.gz
rm *.tar.gz *tgz *.tar.gz.* *tgz.*

cd ~/dftb+/dftb+_snapshot-081217_src
wget http://www2.fizik.usm.my/configrepo/howto/dftb+/Makefile.user.sa
cp Makefile.user.sa Makefile.user

cd ~/dftb+/dftb+_snapshot-081217_src/prg_dftb
make distclean
make

mkdir ~/bin
cd ~/bin/
ln -s ~/dftb+/dftb+_snapshot-081217_src/prg_dftb/_obj_i686-linux-ifort/dftb+ .

cd ~/dftb+/dftb+_snapshot-081217_src/prg_dftb
make test
