#!/bin/bash
#
# Script to install IntelMQ
#

if [ "x$(whoami)" != "xintelmq" ]; then
      echo "Exectuing as wrong user."
      exit -1
fi

if ! test -f /opt/intelmq/venv/bin/activate; then
        echo "Issues with venv."
        exit -1
else
        source /opt/intelmq/venv/bin/activate
fi

PY_INTELMQ='intelmq intelmq-api intelmqmail intelmq-manager gunicorn certstream'
PY_CERTBUND_CONTACT='intelmq-certbund-contact intelmq-fody-backend'


pip3 install $PY_INTELMQ
pip3 install $PY_CERTBUND_CONTACT
# Due to Certbund contact overwrite files for some reason, reinstall intelmq
pip3 install --force-reinstall intelmq

intelmq-manager-build -o /opt/intelmq/www/intelmq-manager

touch /opt/intelmq/.installed