Installation and test requirements
==================================

Here you can find out a standard way to install the software needed by SANET
to work properly. The procedures shown below are intended as general instruction for GNU/Linux systems and might not be the best and simplest way to go on your system.
In order to install these software please refer to your system documentation when possible.



.. _postgresql-req:

PostgreSQL
~~~~~~~~~~

SANET works much better using Postgres rather than MySQL.
Hence postgres is strongly reccomended.
Instructions on how to use MySQL are given anyway.

The only possible problem while building postgres is given by missing readline.
Compiling without readline is possible but deprecated.
Installing readline, even though optional, is reccommended (for slackware
distribution it can be downlaoded and installed using installpkg).

.. sourcecode:: python

    root@clarabella:~# wget http://ftp2.it.postgresql.org/mirrors/postgres//source/v8.3.1/postgresql-8.3.1.tar.bz2
    root@clarabella:~# tar xjvf postgresql-8.3.1.tar.bz2
    root@clarabella:~# cd postgresql-8.3.1
    root@clarabella:~/postgresql-8.3.1# ./configure --enable-thread-safety --prefix=/usr/local/pgsql-8.3.1 && make && make install
    ...
    root@clarabella:~/postgresql-8.3.1# groupadd postgres
    root@clarabella:~/postgresql-8.3.1# useradd -g postgres postgres

Postgres installation requires around 90MB of disk space and
obviously the directory used for compiling needs to be readable by the postgres user.
Before continuing with the installation it is reccomended to run some tests to check
that everything is working fine.

.. sourcecode:: python

    root@clarabella:~/postgresql-8.3.1# chown -R postgres.postgres .
    root@clarabella:~/postgresql-8.3.1# cd ..
    root@clarabella:~# mv postgresql-8.3.1 /var/tmp
    root@clarabella:~# cd /var/tmp/postgresql-8.3.1/
    root@clarabella:/var/tmp/postgresql-8.3.1# su postgres
    postgres@clarabella:/var/tmp/postgresql-8.3.1$ make check
    ...
    
    =======================
     All 114 tests passed.
    =======================
    
    make[2]: Leaving directory `/var/tmp/postgresql-8.3.1/src/test/regress'
    make[1]: Leaving directory `/var/tmp/postgresql-8.3.1/src/test'
    postgres@clarabella:/var/tmp/postgresql-8.3.1$
    postgres@clarabella:/var/tmp/postgresql-8.3.1$ exit
    root@clarabella:/var/tmp/postgresql-8.3.1# cd
    root@clarabella:~# rm -rf postgresql-8.3.1.tar.bz2 /var/tmp/postgresql-8.3.1


To continue the installation some links are needed:

.. sourcecode:: python

    root@clarabella:~# cd /usr/local
    root@clarabella:/usr/local# ln -s pgsql-8.3.1 pgsql
    root@clarabella:/usr/local# cd bin
    root@clarabella:/usr/local/bin# ln -s ../pgsql/bin/* .
    root@clarabella:/usr/local/bin# cd ..
    root@clarabella:/usr/local# cd include/
    root@clarabella:/usr/local/include# ln -s ../pgsql/include/* .
    root@clarabella:/usr/local/include# cd ..
    root@clarabella:/usr/local# cd lib
    root@clarabella:/usr/local/lib# ln -s ../pgsql/lib/* .
    root@clarabella:/usr/local/lib# cd ..
    root@clarabella:/usr/local# ldconfig
    root@clarabella:/usr/local# cd man/man1
    root@clarabella:/usr/local/man/man1# ln -s ../../pgsql/man/man1/* .
    root@clarabella:/usr/local/man/man1# cd ..
    root@clarabella:/usr/local/man# cd man7
    root@clarabella:/usr/local/man/man7# ln -s ../../pgsql/man/man7/* .
    root@clarabella:/usr/local/man/man7# cd ../../pgsql


Finally postgres can be set up:

.. sourcecode:: python

    root@clarabella:/usr/local/pgsql# mkdir data
    root@clarabella:/usr/local/pgsql# chown postgres.postgres data
    root@clarabella:/usr/local/pgsql# su - postgres
    ...
    postgres@clarabella:/$ initdb -D /usr/local/pgsql/data --locale=en_US.utf8
    ...
    WARNING: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the -A option the
    next time you run initdb.
    
    Success. You can now start the database server using:
    
        postgres -D /usr/local/pgsql/data
    or
        pg_ctl -D /usr/local/pgsql/data -l logfile start
    
    postgres@clarabella:/$ exit
    logout
    root@clarabella:/usr/local/pgsql# cat > /etc/rc.d/rc.postgres
    #!/bin/sh
    
    export base=/usr/local/pgsql
    export logfile=$base/data/$(hostname).log
    
    case "$1" in
    'start')
      su postgres -c "$base/bin/postgres -D $base/data >$logfile 2>&1 &"
      ;;
    'stop')
      killall postgres
      ;;
    'restart')
      $0 stop
      sleep 5
      $0 start
      ;;
    \*)
      echo "usage $0 start|stop|restart"
    esac
    
    (fate CTRL+D per terminare l'input)
    root@clarabella:/usr/local/pgsql# chmod +x /etc/rc.d/rc.postgres
    root@clarabella:/usr/local/pgsql# /etc/rc.d/rc.postgres start
    root@clarabella:/usr/local/pgsql# vi /etc/rc.d/rc.local


The command "/etc/rc.d/rc.postgres start" needs to be inserted in rc.local.
Obviously rc.pinger noods rc.postgres.


Python modules
~~~~~~~~~~~~~~

On the python side psycopg2 (Postgres drivers) and django are used.
Since django is highly variable even through the same version, and since
SANET is highly sensitive to variations in django, we decided to embed django
directly intio SANET, so there is no need to install it.
If django is already present in your system nothing bad will happen:
the system-wide installe django will continue working properly for everything
except SANET, while SANET will use its own embedded django instance.

If MySQL is preferred over Postgres, mysqldb (MySQL drivers) needs to be installed.


setuptools
``````````

Since we encountered some problems finding out the latest version of setuptools,
the following procedure is suggested.

.. sourcecode:: python

    root@helicopter:/usr/src# wget http://peak.telecommunity.com/dist/ez_setup.py
    root@helicopter:/usr/src# python ez_setup.py


.. _pyxmlmod-req:

PyXML
`````

.. sourcecode:: python

    root@helicopter:~# easy_install PyXML


It is possible that an error similar to the one below is raised during the installation:

.. sourcecode:: python

    ImportError: No module named xml.sax.saxutils


It can be fixed by:

.. sourcecode:: python

    cd /usr/lib/python2.X/site-packages/PyXML-0.8.4-py2.X-linux-i686.egg
    ln -s _xmlplus xml



.. _rrdtoolmod-req:

rrdtool
```````

If rrdtool >= 1.2.27 is already installed on your system you only need
to link the python module to it:

.. sourcecode:: python

    root@unimon:~# ln -s /usr/local/rrdtool/lib/python2.5/site-packages/rrdtoolmodule.so /usr/lib/python2.5/site-packages/


To check if it worked, do:

.. sourcecode:: python

    root@hubble:~# python
    Python 2.5.1 (r251:54863, May  4 2007, 16:52:23)
    [GCC 4.1.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import rrdtool
    >>>


Older versions might be imported only as "import rrdtoolmodule",
if that is the case the library needs to be updated to the last stable release available
(of the 1 series).

If rrdtool is not installed on your system you need to install it being
aware that some problems related to freetype might arise.
In that case here it is how to proceed:

For pinger (> 2.9.0) to work both rrd* executables and perl RRD module are needed.
To check if something is missing issue:

..sourcecode:: python

      perl -MRRDs -e ';'

If no message is given the system is ready, otherwise you need to install rrdtool.
rrdtool requires freetype: to check if freetype is present in the system check if
the command freetype-config is present, if it isn't you need to install it.  

Here it is an example of the freetype installation procedure: 

.. sourcecode:: python

        # wget http://heanet.dl.sourceforge.net/sourceforge/freetype/freetype-2.2.1.tar.bz2
        # tar xvjf freetype-2.2.1.tar.bz2
        # cd freetype-2.2.1
        # ./configure --prefix=/usr/local/freetype-2.2.1
        # make && make install
        # cd ..
        # rm -rf freetype-2.2.1*
        # cd /usr/local
        # ln -s freetype-2.2.1 freetype
        # cd bin
        # ln -s ../freetype/bin/freetype-config .
        # cd ..
        # cd include/
        # ln -s ../freetype/include/* .
        # ln -s freetype2/freetype/ freetype
        # cd ..
        # cd lib
        # ln -s ../freetype/lib/* .
        # cd ..
        # cd share
        # mkdir aclocal
        # cd aclocal
        # ln -s ../../freetype/share/aclocal/freetype2.m4 .
        # cd 


Example of rrdtool installation procedure (beware to modify the commands to fit your system architecture and software versions):

.. sourcecode:: python

        # wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.2.15.tar.gz
        # tar xzvf rrdtool-1.2.15.tar.gz
        # cd rrdtool-1.2.15
        # ./configure --prefix=/usr/local/rrdtool-1.2.15
        ...
        # make && make install
        # cd ..
        # rm -rf rrdtool-1.2.15*
        # cd /usr/local
        # ln -s rrdtool-1.2.15 rrdtool

        # cd bin
        # ln -s ../rrdtool/bin/* .
        # cd ..

        # cd include
        # ln -s ../rrdtool/include/* .
        # cd ..

        # cd lib
        # ln -s ../rrdtool/lib/lib* .
        # cd ..
        
        # cd man/man1
        # ln -s ../../rrdtool/man/man1/* .
        # cd ..

        # cd /usr/lib/perl5/site_perl/5.8.6/i486-linux/
        # ln -s /usr/local/rrdtool/lib/perl/5.8.6/i486-linux/RRDs.pm .
        # cd auto
        # ln -s /usr/local/rrdtool/lib/perl/5.8.6/i486-linux/auto/RRD* .
        # cd

Finally execute

.. sourcecode:: python

        # perl -MRRDs -e ''

If no error message is given in output the installation was completed succesfully!


.. _netsnmpmod-req:

net-snmp
````````

You can install Net-SNMP as usual. Download sources from
`net-snmp.org <http://www.net-snmp.org/download.html>`__. 

**NOTE**: You need at least version 5.5.pre2

Issue

.. sourcecode:: bash

      # ./configure --prefix=/usr/local/net-snmp-5.5.pre2 && make && make install

and refer to README and INSTALL files for any problem. 
Then you would like to symlink produced file to default system location like this:

.. sourcecode:: bash

	# cd /usr/local/
	# ln -s net-snmp-5.5.pre2 net-snmp
	# cd bin
	# ln -s ../net-snmp/bin/* .
	# cd ../lib/
	# ln -s ../net-snmp/lib/* .
	# cd ../sbin/
	# ln -s ../net-snmp/sbin/* .
	# cd ../include/
	# ln -s ../net-snmp/include/* .
	# cd ../share/man
	# for i in 1 3 5 8; do mkdir -p man$i; cd man$i; ln -s ../../../net-snmp/share/man/man$i/* .; cd -; done

Then execute ldconfig to update your dynamic linker configuration.

FINALLY you can proceed with netsnmp python module installation.
Come back to source directory and issue:

.. sourcecode:: bash

    # cd python
    # python setup.py build
    # python setup.py install

To test module installation exit from current directory (you can go in $SANET_HOME), and try:

.. sourcecode:: python

	# python
	Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
	[GCC 4.3.3] on linux2
	Type "help", "copyright", "credits" or "license" for more information.
	>>> import netsnmp
	>>> netsnmp.__file__
	'/usr/local/lib/python2.6/dist-packages/netsnmp_python-1.0a1-py2.6-linux-i686.egg/netsnmp/__init__.pyc'
	>>> CTRL+D

You must exit from building directory because there is a netsnmp directory in it.

If you get and error try to install with:

.. sourcecode:: bash

	# python setup.py install  --install-platlib /path/to/your/lib/python2.x/site-packages/


psycopg2
````````

If `EasyInstall
<http://peak.telecommunity.com/DevCenter/EasyInstall>`__ is installed
and you can access the Internet, you just need to launch:

.. sourcecode:: python

    root@helicopter:~# easy_install psycopg2


otherwise it can be installed the usula way:

.. sourcecode:: python

    root@clarabella:~# wget http://www.initd.org/pub/software/psycopg/psycopg2-2.0.7.tar.gz
    root@clarabella:~# tar xzvf psycopg2-2.0.7.tar.gz
    root@clarabella:~# cd psycopg2-2.0.7
    root@clarabella:~/psycopg2-2.0.7# python setup.py install
    root@clarabella:~# rm -rf psycopg2-2.0.7*


.. _pydotmod-req:

pydot
`````

If SANET is being installed on a slackware system, the following
libraries are needed:
libX11-1.1.4-i486-1.tgz libXau-1.0.3-i486-1.tgz
libXdmcp-1.0.2-i486-1.tgz libXpm-3.5.7-i486-1.tgz
libxcb-1.0-i486-2.tgz

Then the SANET_HOME variable, containing the path to the SANET directory, has to be
exported as an environment variable:

.. sourcecode:: bash

        export SANET_HOME=/usr/local/sanet

and added to /etc/profile

If setuptools have bbe installed as described above, and graphviz
is already installed on your system, you can install pydot by:

.. sourcecode:: python

    root@mason:~# easy_install pydot

Otherwise you need to install :ref:`graphviz-req`-

.. _graphviz-req:

Graphviz
````````

To install Graphviz the dev library .la libexpat is needed, if it is not present and you are using a slackware system
it can be installed as a slackware package, categoty "L".
The same holds for jpeg, fontconfig, and freetype).
Once the needed libraries and packages are installed, the graphviz installation procedure
is as follows:

.. sourcecode:: python

    
    root@melkor:~# wget http://www.graphviz.org/pub/graphviz/ARCHIVE/graphviz-2.20.2.tar.gz
    root@hubble:~# tar xzvf graphviz-2.20.2.tar.gz
    root@hubble:~# cd graphviz-2.20.2
    root@hubble:~/graphviz-2.20.2# ./configure --prefix=/usr/local/graphviz-2.20.2 && make && make install
    root@hubble:~/graphviz-2.20.2# cd /usr/local
    root@hubble:/usr/local# ln -s graphviz-2.20.2 graphviz
    root@hubble:/usr/local# cd bin
    root@hubble:/usr/local/bin# ln -s ../graphviz/bin/* .
    root@hubble:/usr/local/bin# cd ..
    root@hubble:/usr/local# cd lib
    root@hubble:/usr/local/lib# ln -s ../graphviz/lib/* .
    root@hubble:/usr/local/lib# cd ..
    root@hubble:/usr/local# cd include/
    root@hubble:/usr/local/include# ln -s ../graphviz/include/graphviz .
    root@hubble:/usr/local/include# cd ..
    root@hubble:/usr/local# cd man
    root@hubble:/usr/local/man# for i in 1 3 n
    > do
    > cd man$i
    > ln -s ../../graphviz/share/man/man$i/* .
    > cd ..
    > done
    root@hubble:/usr/local/man# cd
    root@hubble:~# rm  -rf graphviz-2.20.2*


Then pyparsing needs to be installed:

.. sourcecode:: python

    root@melkor:~# wget http://switch.dl.sourceforge.net/sourceforge/pyparsing/pyparsing-1.5.0.tar.gz
    root@hubble:~# tar xzf pyparsing-1.5.0.tar.gz
    root@hubble:~# cd pyparsing-1.5.0
    root@hubble:~/pyparsing-1.5.0# python setup.py install
    root@hubble:~/pyparsing-1.5.0# cd ..
    root@hubble:~# rm -rf pyparsing-1.5.0*


And finally pydot:

.. sourcecode:: python

    root@melkor:~# wget http://pydot.googlecode.com/files/pydot-1.0.2.tar.gz
    root@hubble:~# tar xzf pydot-1.0.2.tar.gz
    root@hubble:~# cd pydot-1.0.2
    root@hubble:~/pydot-1.0.2# python setup.py install
    root@hubble:~/pydot-1.0.2# cd ..
    root@hubble:~# rm -rf pydot-1.0.2*



antlr3
``````

Antlr3 is not available via easy install. The python runtime can be daownlaoded from
`http://www.antlr.org/download/Python/antlr_python_r
untime-3.1.2.tar.gz <http://www.antlr.org/download/Python/antlr_python
_runtime-3.1.2.tar.gz>`__
(python 2.4 o 2.5 or newer, `http://www.antlr.org/download/Python
<http://www.antlr.org/download/Python>`__)

.. sourcecode:: python

    # tar xzvf antlr_python_runtime-3.1.2.tar.gz
    # cd antlr_python_runtime-3.1.2
    # python setup.py install
    # cd ..
    # rm -rf antlr_python_runtime-3.1.2*

.. _reportlabmod-req:

ReportLab library
`````````````````

Download the ReportLab version 2.3 or newer from the `ReportLab download page <http://www.reportlab.org/downloads.html#reportlab>`__

Here it is a direct link to version 2.3:: `ReportLab_2_3 <http://www.reportlab.org/ftp/ReportLab_2_3.tar.gz>`__

Installation procedure:

.. sourcecode:: bash

	# wget http://www.reportlab.org/ftp/ReportLab_2_3.tar.gz
	# tar -xzvf ReportLab_2_3.tar.gz
	# cd ReportLab_2_3
	# python setup.py tests-preinstall  (dovrebbero esserci degli errori)
	# python setup.py install
	# python setup.py tests

Download the required fonts from `here <http://bioinf.scri.ac.uk/lp/downloads/programs/genomediagram/linfonts.zip>`__

Unzip the package and copy the files in the directory (create it if missing):

.. sourcecode:: bash

	/usr/lib/<python-2.*>/site-packages/reportlab/fonts/

For more info look at: `http://bioinf.scri.ac.uk/lp/downloads/programs/genomediagram/renderPM_help.txt <http://bioinf.scri.ac.uk/lp/downloads/programs/genomediagram/renderPM_help.txt>`__



.. _pilmod-req:

Pil library
```````````

Download the package from the `Pil homepage <http://www.pythonware.com/products/pil/index.htm>`__

It requires *libjpeg* library version *6a* or *6b*.
It should already be present in the default installation.

Here it is a direct link: `<http://effbot.org/downloads/Imaging-1.1.6.tar.gz>`__

Installation procedure:
		
.. sourcecode:: bash

	$ tar -xzvf Imaging-1.1.6.tar.gz
	$ cd Imaging-1.1.6
	$ python setup.py build
	$ python setup.py install


Html5lib library
````````````````

This library can be installed via Easy Install by issuing:

.. sourcecode:: bash

	# easy_install html5lib 


.. _pisamod-req:

Pisa library
````````````

Pisa can be installed via Easy Install by issuing:

.. sourcecode:: bash

	# easy_install pisa


PERL e RDTOOL modules
~~~~~~~~~~~~~~~~~~~~~

SANET comes with the latest pinger version. If an older pinger version is used
some modules might be missing.

To check if you are missing perl modules, issue:

.. sourcecode:: bash

        # pinger -h

If you get errors like `Can't locate somedir/somemodule.pm in @INC ...`
you need to download them from `<http://www.cpan.org>`__ or install them using cpan by issuing:

.. sourcecode:: bash

         "perl -MCPAN -e shell".


.. _rrdtool-req:

RRDTool
```````
Pinger versions > 2.9.0 needs rrd* executable files and the RRD Perl module to work.
If the command:

.. sourcecode:: bash
        
        # perl -MRRDs -e ';'

does not give any output everything is fine, otherwise it has to be installed.
To install RRDTool ``freetype`` is needed.
If the command:

.. sourcecode:: bash

        # freetype-config

everything is alright, otherwise it needs to be installed.

Here it is an example of freetype installation (please notice that:

.. sourcecode:: bash

        # wget http://heanet.dl.sourceforge.net/sourceforge/freetype/freetype-2.2.1.tar.bz2
        # tar xvjf freetype-2.2.1.tar.bz2
        # cd freetype-2.2.1
        # ./configure --prefix=/usr/local/freetype-2.2.1
        # make && make install
        # cd ..
        # rm -rf freetype-2.2.1*
        # cd /usr/local
        # ln -s freetype-2.2.1 freetype
        # cd bin
        # ln -s ../freetype/bin/freetype-config .
        # cd ..
        # cd include/
        # ln -s ../freetype/include/* .
        # ln -s freetype2/freetype/ freetype
        # cd ..
        # cd lib
        # ln -s ../freetype/lib/* .
        # cd ..
        # cd share
        # mkdir aclocal
        # cd aclocal
        # ln -s ../../freetype/share/aclocal/freetype2.m4 .
        # cd 

Here it is an example of rrdtool installation:

.. sourcecode:: bash

        # wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.2.15.tar.gz
        # tar xzvf rrdtool-1.2.15.tar.gz
        # cd rrdtool-1.2.15
        # ./configure --prefix=/usr/local/rrdtool-1.2.15
        ...
        # make && make install
        # cd ..
        # rm -rf rrdtool-1.2.15*
        # cd /usr/local
        # ln -s rrdtool-1.2.15 rrdtool

        # cd bin
        # ln -s ../rrdtool/bin/* .
        # cd ..

        # cd include
        # ln -s ../rrdtool/include/* .
        # cd ..

        # cd lib
        # ln -s ../rrdtool/lib/lib* .
        # cd ..

        # cd man/man1
        # ln -s ../../rrdtool/man/man1/* .
        # cd ..

        # cd /usr/lib/perl5/site_perl/5.8.6/i486-linux/ # Change it according to your system's architecture
        # ln -s /usr/local/rrdtool/lib/perl/5.8.6/i486-linux/RRDs.pm . # Change it according to your system's architecture
        # cd auto
        # ln -s /usr/local/rrdtool/lib/perl/5.8.6/i486-linux/auto/RRD* . # Change it according to your system's architecture
        # cd
        # perl -MRRDs -e ''

If the command:

.. sourcecode:: bash

        # perl -MRRDs -e ''

does not give any output, then RRDTool is installed correctly.




Apache 2.x
^^^^^^^^^^

Apache 2.x with mod_python is needed.
The basic Apache 2 installation usually works excpet mod_python
that usually is not included in the default installation.

Apache installation
```````````````````

.. sourcecode:: python

    root@unimon:~# wget http://www.eu.apache.org/dist/httpd/httpd-2.2.9.tar.bz2
    root@unimon:~# tar xjvf httpd-2.2.9.tar.bz2
    root@unimon:~# cd httpd-2.2.9
    root@unimon:~/httpd-2.2.9# ./configure --prefix=/usr/local/httpd-2.2.9/ --enable-mods-shared="all" --enable-ssl && make && make install
    

If something goes wrong try removing not needed modules (the only module
needed by SANET is mod_python).

.. sourcecode:: python

    root@unimon:~/httpd-2.2.9# cd ..
    root@unimon:~# rm -rf httpd-2.2.9*
    root@unimon:~# cd /usr/local


Note: on some machine it might be needed to install
db44-4.4.20-i486-2.tgz and expat-2.0.1-i486-1.tgz,
for slackware distribution they are available at
packages.slackware.it


mod_python installation
```````````````````````

Check that python 2.4 or newer is installed.

mod_python does not need `--prefix`, on the other hand if many apache instances are installed
it is fundamental to give the right `apxs` value to choose the apache instance to use.

.. sourcecode:: python

    root@unimon:~# wget http://www.eu.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz
    root@unimon:~# tar xzvf mod_python-3.3.1.tgz
    root@unimon:~# cd mod_python-3.3.1
    root@unimon:~/mod_python-3.3.1# ./configure --with-apxs=/usr/local/httpd-2.2.9/bin/apxs && make && make install
    root@unimon:~/mod_python-3.3.1# cd ..
    root@unimon:~# rm -rf mod_python-3.3.1*