#!/bin/bash
+# ____ _ _
+# / ___| __ _ _ __ __ _ __ _ _ __ | |_ _____ _| |_
+# | | _ / _` | '__/ _` |/ _` | '_ \| __/ _ \ \/ / __|
+# | |_| | (_| | | | (_| | (_| | | | | || __/> <| |_
+# \____|\__,_|_| \__, |\__,_|_| |_|\__\___/_/\_\\__|
+# |___/
+
+# This receipe is for specific use (Open Stack && Debien)
+# Step by step installation process (advanced user mainly)
+# For others: a docker image is coming
+
+########################################################################
+# To be sure to have updated packages
sudo apt update
sudo apt upgrade
-sudo sed -i "s/stretch/buster/g" /etc/apt/sources.list
+# Tmux to avoid disconnections during the installation process
+# Htop for visual monitoring
+sudo apt install tmux htop
+########################################################################
+sudo sed -i "s/stretch/buster/g" /etc/apt/sources.list
sudo apt update
sudo apt dist-upgrade
+# sudo reboot #recommended
+########################################################################
-sudo adduser --disabled-password --gecos "" gargantua
+#sudo apt update
+sudo apt install liblzma-dev libpcre3-dev libblas-dev liblapack-dev pkg-config libgsl-dev libbz2-dev postgresql postgresql-server-dev-11 nginx libigraph0-dev libgfortran-9-dev
-if git --version;
-then
- echo "git installed, ok"
-else
- sudo apt update && sudo apt install git
-fi
+sudo apt install git
+#git config --global user.email "contact@gargantext.org"
+#git config --global user.name "Gargantua"
-sudo apt update
-sudo apt install liblzma-dev libpcre3-dev libblas-dev liblapack-dev pkg-config libgsl-dev libbz2-dev postgresql postgresql-server-dev-11 nginx libigraph0-dev
-#echo "Which user?"
+########################################################################
+echo "Which user?"
#read USER
-#sudo adduser --disabled-password --gecos "" $USER
-#sudo su $USER
+USER="gargantua"
+sudo adduser --disabled-password --gecos "" $USER
+
+########################################################################
+#cd /home
+#sudo mv -if /home/$USER /srv/
+#sudo ln -s /srv/$USER
curl -sSL https://get.haskellstack.org/ | sh
+
+sudo apt install curl
+sudo su $USER
stack update
stack upgrade
-git clone https://gitlab.iscpif.fr/gargantext/haskell-gargantext.git
+#git clone https://gitlab.iscpif.fr/gargantext/haskell-gargantext.git
+
+#cd haskell-gargantext
+##########
+
+if [[ ! -d "purescript-gargantext" ]]; then
+ ./devops/debian/install-purescript
+fi
+#########################################################################
-cd haskell-gargantext
-git clone https://gitlab.iscpif.fr/gargantext/purescript-gargantext
+# stack install should be enough but all process is the following steps
+stack setup && stack build && stack install
-##########
-curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
-echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
-sudo apt update
-sudo apt install yarn
+#########################################################################
+# build deps
-mkdir deps
-cd deps
-git clone https://gitlab.iscpif.fr/gargantext/clustering-louvain.git
-cd ..
-stack setup
-stack build
-stack install
+if [[ ! -d "deps" ]]; then
+ mkdir -v deps
+ cd deps
+ sudo apt install default-jdk
+ if [[ ! -f "coreNLP.tar.bz2" ]]; then
+ wget https://dl.gargantext.org/coreNLP.tar.bz2
+ fi
+ if [[ ! -d "home" ]]; then
+ tar xvjf coreNLP.tar.bz2
+ fi
+ # CoreNLP needs to be started
+ # ./startServer.sh
-# Specific to our servers
+ cd ..
+fi
-### Configure timezone and locale ###################################
-echo "########### LOCALES & TZ #################"
-echo "Europe/Paris" > /etc/timezone
-dpkg-reconfigure --frontend=noninteractive tzdata
-#ENV TZ "Europe/Paris"
-sed -i -e 's/# en_GB.UTF-8 UTF-8/en_GB.UTF-8 UTF-8/' /etc/locale.gen && \
-sed -i -e 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen && \
-locale-gen && \
-update-locale LANG=fr_FR.UTF-8 && \
-update-locale LANGUAGE=fr_FR.UTF-8 && \
-update-locale LC_ALL=fr_FR.UTF-8
-################################################################
+# Specific to our servers
+
+#### Configure timezone and locale ###################################
+# todo sync dates
+#echo "########### LOCALES & TZ #################"
+#echo "Europe/Paris" > /etc/timezone
+#dpkg-reconfigure --frontend=noninteractive tzdata
+##ENV TZ "Europe/Paris"
+#
+#sed -i -e 's/# en_GB.UTF-8 UTF-8/en_GB.UTF-8 UTF-8/' /etc/locale.gen && \
+#sed -i -e 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen && \
+#locale-gen && \
+#update-locale LANG=fr_FR.UTF-8 && \
+#update-locale LANGUAGE=fr_FR.UTF-8 && \
+#update-locale LC_ALL=fr_FR.UTF-8
+#################################################################
# Database configuration
# CREATE USER gargantua WITH PASSWORD $(grep DB_PASS gargantext.ini)
## POSTGRESQL DATA (as ROOT)
#######################################################################
-PGVersion = 11
-mkdir /srv/gargantua/gargandata
+./devops/debian/install-postgres
-sed -iP "s%^data_directory.*%data_directory = \'\/srv\/gargantua\/gargandata\'%" /etc/postgresql/$PGVersion/main/postgresql.conf
-#echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/$PGVersion/main/pg_hba.conf
-#echo "listen_addresses='*'" >> /etc/postgresql/$PGVersion/main/postgresql.conf
+# configure the database with script in devops/postgres
+# edit gargantext.ini