# ================================================ #
*  Install - McStas and the (optional) Webserver   *
*  ---------------------------------------------   *
*        Debian 7.1 iso 64bit (DL+install)         *
*         use ifconfig to find ip address          *
# ================================================ #

System Setup
------------

1) Check out the McCode SVN repos:
     mkdir <whatever_build_dir_structure_you_want>
     cd <whatever_build_dir_structure_you_want>
     svn co https://svn.mccode.org/svn/McCode/trunk

2) Build all dependencies in this list:
     sudo apt-get (build-dep) install  cmake
     	  	  	      	       texlive-* (all except the langs and docs, you just need lang-danish)
				       latex2html
				       latexmk
				       gcc
				       flex
				       bison
				       libc6-dev
     	  	  	      	       xbase-clients 
                                       build-essential 
				       emacs 
				       subversion
				       nginx-full 
				       python-dev
				       libopenmpi-dev (if you need MPI. (Yes, you need it.))
				       python-pip            (the python package manager)
   and:
     sudo pip install python-django==1.7

*** I am here on my vm ***

3) Enable non-free repos:
      sudo apt-add-repository 'deb http://ftp.debian.org/debian/ wheezy main contrib non-free'
      cd /etc/apt/sources.list.d
      sudo wget http://packages.mccode.org/debian/mccode.list
   change your shell to bash:
      dpkg-reconfigure dash (and tell it 'No')
   now look at all the goodies you have directed your machine to find:
      sudo apt-get update ; apt-get upgrade

4) In the trunk dir there are a bunch of scripts which build .debs or .rpms for your particular
   OS. Run the correct one.
      cd /trunk/dist
      dpkg -i <whichever_you_wish_to_install> (I would just install them all)
   If this fails for some reason run:
      sudo apt-get -f install   
   The -f flag tells the unmet dependencies to be forced to install. Then run:
      dpkg -i <whichever_you_wish_to_install>
   again. This should install McStas, you can install McXtrace in exactly the same way using the correct
   build_... script. 


Setting up Django Webserver
---------------------------

5) Create the server dir and copy the server files into it, you are playing in the root dir now so you have to 
   sudo everything or run as root, change the permissions at the end if you don't like running round your 
   system as su:
     sudo mkdir /srv/mcstas-django
     sudo cp -rp /root/trunk/tools/Python/www/www-django/mcwww/ /srv/mcstas-django

6) Move to your shiny new working directory (the one you just made). Run:
     sudo bin/get-dependencies.sh

7) Make a <Group_Dir> in sim/ and populate sim/<Group_Dir> with at least one instr - 
     sudo cp /usr/local/lib/mcstas-2.0/examples/<choose_one_or_more>.instr sim/<Group_Dir>

sidenote_1: You will need to login to <IP ADDRESS>:<PORT>/admin (after creating your users) and put users 
	    in groups so they can run simulations. Groups correspond to <Group_Dir> names.

sidenote_2: Ensure your keyboard is set to a locale that the python scripts are happy with:
     	    	   export LC_ALL="en_US.UTF-8"  

8) ### THERE SHOULD BE FLAGS FOR THE VARIOUS MODES OF INSTALLATION ###
   REMEMBER THE NEW LDAP PASSWORD, IT IS REQUESTED AGAIN!
   Run:
     ./bin/init-db.sh
   set up the LDAP authentication DB, the sqlite simulation DBs, and, the file uploading DB (upon completion).
   you will be prompted for some information to set up the LDAP DB, this is important to keep hold of.                    

9) Follow the prompts, you should set up a superuser to start with, step (10)a) shows how to create new users:

   Username (leave blank to use 'root'): 
   E-mail address:
   Password: 
   Password (again): 
   Superuser created successfully.

10) Run the following commands (put the runworker in the background with '&' or open a new terminal):
   a)  ./manage.py createuser <USERNAME> <PASSWORD>
   c)  sudo ./manage.py runworker &
   d)  sudo ./manage.py runserver <IP ADDRESS>:<PORT> (80 is a good listening port)

sidenote_3: When you have compiled the instruments (step (10)b) ) you should copy the .html files into the <GROUP>
	    folder. This keeps everything tidy, although the server will find them in any of the referenced subfolders
	    from where you run step (10)c & d).

Adding a Simulation to the DB
-----------------------------

- If you wisdh to create a new group of simulations follow step (7) and then (10)b). Remember to put your 
  user in groups that you wish them to be able to select simulations from.
- Otherwise put your .instr file(s) in an existing group and perform step (10)b).
- Upon reopening the configuration page the new simulations should be available to the users in the correct 
  groups.
