#!/usr/bin/env bash set -euo pipefail SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CONF_DIR="$SRC_DIR/conf/monitoring" MOD_DIR="$SRC_DIR/modules/grafana-central/conf" mkdir -p "$CONF_DIR" link_file() { if [ "$#" -lt 2 ]; then echo "[WARN] link_file: arguments insuffisants ($#)" >&2 return 0 fi local src="$1" local dst="$2" if [ ! -f "$src" ]; then echo "[WARN] Source introuvable: $src" >&2 return 0 fi if [ -L "$dst" ] || [ -f "$dst" ]; then if cmp -s "$src" "$dst" 2>/dev/null; then echo "[OK] Déjà aligné: $dst" return 0 fi echo "[INFO] Remplacement: $dst" rm -f "$dst" fi ln -s "$src" "$dst" echo "[OK] Lien créé: $dst -> $src" } link_file "$MOD_DIR/grafana.ini" "$CONF_DIR/grafana.ini" link_file "$MOD_DIR/datasources.yml" "$CONF_DIR/datasources.yml" link_file "$MOD_DIR/prometheus.yml" "$CONF_DIR/prometheus.yml" link_file "$MOD_DIR/promtail-config.yml" "$CONF_DIR/promtail-config.yml" link_file "$MOD_DIR/loki-config.yaml" "$CONF_DIR/loki-config.yaml" echo "[DONE] Liens symboliques de monitoring synchronisés."