#!/bin/bash
## Ordner anlegen
mkdir /root/REPORTS
cd /root/REPORTS

## APT UPDATE
apt update
apt install python3-pip git -y

## Add Crontab
if [ -f ".crontab" ]; then
  echo "Gibt es"
  next
else
  crontab -l | { cat; echo "30 0 * * * /root/REPORTS/setup-info.sh"; } | crontab -
  echo "Gibt es nicht"
  touch ".crontab"
fi

## Add GIT
git init
git remote add orgin https://gitlab.stines.de/sebastian.serfling/REPORTS.git
git fetch
git pull orgin main

## Install Python
python3 -m pip install virtualenv
python3 -m virtualenv venv
source venv/bin/activate
python3 -m pip install -r packages.txt
python3 -m pip uninstall mysql-connector -y ## Fix for Connection Issue
python3 -m pip install mysql-connector ## Fix for Connection Issue
python3 main.py
deactivate