#!/bin/bash
if [ ! -f /usr/lib/prometheus/prometheus ]; then
    echo "Cannot find prometheus in /usr/lib/prometheus/. Please download"
    echo "and install Prometheus from https://prometheus.io/download/ and"
    echo "place the executable in /usr/lib/prometheus/."
    exit 1
fi

systemctl -a | grep -q grafana-server
if [ $? -ne 0 ]; then
    echo "Cannot find Grafana. Please download and install Grafana."
    echo 'After installation, run "systemctl enable --now grafana-server"'
    exit 1
fi

cp prometheus/prometheus.yml /usr/lib/prometheus/
cp prometheus/prometheus.service /lib/systemd/system/
systemctl enable prometheus
systemctl restart prometheus

cp prometheus-aip-exporter /opt/skyformai/sbin/
cp aip-exporter.service /lib/systemd/system/
systemctl enable aip-exporter
systemctl restart aip-exporter

cp grafana/grafana.ini /etc/grafana/grafana.ini
cp -r grafana/dashboards grafana/datasources /etc/grafana/provisioning
rm /etc/grafana/provisioning/datasources/sample.*
rm /etc/grafana/provisioning/dashboards/sample.*

systemctl enable grafana-server
systemctl restart grafana-server

echo Installation completed. Please goto http://$(hostname -I | awk '{print $1}'):3000 to view
echo dashboards.
