#!/bin/bash

echo "Start...";

cd ~ && sudo rm -rf monterossa && \
sudo apt update && sudo apt-get update && curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - && sudo apt-get install -y nodejs && sudo npm i -g npm && node -v `v.8.11.3` && npm -v `6.1.0` && \
cd ~ && sudo mkdir monterossa && sudo npm -g config set user root && sudo npm -g install gulp && sudo npm install pm2 -g && \
cd ~/monterossa && sudo git clone http://gitlab.elinext.com/iArchive/iarchiv-client.git && cd ~/monterossa/iarchiv-client/ && sudo git checkout -b release origin/release && sudo chmod -R 777 /home/ubuntu/.npm && sudo chown -R $USER:$(id -gn $USER) /home/ubuntu/.config && npm -g config set user root && sudo npm install && \
cd ~/monterossa && sudo git clone http://gitlab.elinext.com/iArchive/iarchiv-server.git && cd ~/monterossa/iarchiv-server/  && sudo git checkout -b release origin/release && sudo mkdir -p logs && sudo apt install node-gyp -y && sudo npm install && \
cd ~/monterossa && sudo git clone http://gitlab.elinext.com/iArchive/iarchiv-pdf-worker.git && cd ~/monterossa/iarchiv-pdf-worker/ && sudo git checkout -b pdf-separate-worker origin/pdf-separate-worker && sudo apt install node-gyp -y && sudo npm install && sudo apt upgrade -y && sudo mkdir -p logs && sudo mkdir -p filestorage && sudo mkdir -p filestorage/input && sudo mkdir -p filestorage/output  && \
cd ~/monterossa && sudo git clone http://gitlab.elinext.com/iArchive/iarchiv-unified-storage.git && cd ~/monterossa/iarchiv-unified-storage/ && sudo git checkout -b release origin/release && sudo rm -rf build && sudo npm install  && sudo mkdir -p logs && \
cd ~ && sudo add-apt-repository ppa:libreoffice/ppa -y && sudo apt-get update -y && sudo apt install libreoffice -y && sudo apt-get install libreoffice-gnome && \
cd ~ && sudo apt install git default-jdk-headless ant libcommons-lang3-java libbcprov-java -y && sudo apt autoremove -y && sudo apt install default-jre-headless libcommons-lang3-java libbcprov-java && sudo apt install gdebi -y && sudo apt-get install gcc-6-base && sudo snap install pdftk-smoser && cd /usr/local/bin && sudo ln -s /snap/bin/pdftk-smoser.pdftk pdftk && \
cd ~ && sudo add-apt-repository ppa:dhor/myway -y && sudo apt-get update && sudo apt-get install graphicsmagick -y && \
cd ~ && sudo apt-get install poppler-utils && \
cd ~ && sudo apt-get update && sudo apt-get install mongodb -y && sudo apt-get update && \
cd ~/monterossa && sudo mkdir db && \
cd ~ && sudo wget http://download.redis.io/redis-stable.tar.gz && tar xvzf redis-stable.tar.gz && cd redis-stable && make && sudo make install && \
cd ~ && sudo add-apt-repository ppa:certbot/certbot -y && sudo apt-get update && sudo apt-get install certbot -y && sudo apt-get install letsencrypt && sudo certbot certonly --standalone -d digital-office.link -m fr@monterossa.ch && /

echo "Done...";
