#!/usr/bin/env bash set -euo pipefail # ------------------------------------------------------------ # OCS Inventory "quick test" on ZorinOS (Ubuntu-like) # - Server via Docker Compose (OCS + MariaDB) # - Agent installed only on this workstation, pointing to localhost # ------------------------------------------------------------ if [[ $EUID -ne 0 ]]; then echo "❌ Lance ce script en root (ex: sudo bash $0)" exit 1 fi OCS_DIR="/opt/ocs-test" HTTP_PORT="8080" DB_NAME="ocsweb" DB_USER="ocs" DB_ROOT_PASS="$(openssl rand -hex 16)" DB_PASS="$(openssl rand -hex 16)" OCS_IMAGE_TAG="latest" # stable "latest" according to OCS docs :contentReference[oaicite:1]{index=1} echo "==> 1) Dépendances (Docker, compose, outils)..." apt-get update -y apt-get install -y \ ca-certificates curl gnupg lsb-release \ docker.io docker-compose-plugin \ openssl sed grep coreutils \ ocsinventory-agent dmidecode echo "==> 2) Activation Docker..." systemctl enable --now docker echo "==> 3) Création du dossier: $OCS_DIR" mkdir -p "$OCS_DIR" cd "$OCS_DIR" echo "==> 4) Génération docker-compose.yml..." cat > docker-compose.yml < 5) Démarrage des conteneurs OCS..." docker compose up -d echo "==> 6) Attente (court) du service HTTP..." for i in {1..30}; do if curl -fsS "http://127.0.0.1:${HTTP_PORT}/" >/dev/null 2>&1; then echo "✅ OCS répond sur http://127.0.0.1:${HTTP_PORT}/" break fi sleep 2 done echo "==> 7) Configuration de l'agent (local uniquement)..." CFG="/etc/ocsinventory-agent/ocsinventory-agent.cfg" mkdir -p "$(dirname "$CFG")" touch "$CFG" # Commente d'éventuelles lignes existantes sed -i 's/^[[:space:]]*server[[:space:]]*=/# server =/I' "$CFG" || true sed -i 's/^[[:space:]]*local[[:space:]]*$/# local/I' "$CFG" || true # Ajoute notre config à la fin cat >> "$CFG" < 8) Envoi d’un inventaire tout de suite..." ocsinventory-agent --force --debug || true cat <