#!/usr/bin/env bash # +-------------------------------------------------------------------------+ # | Copyright (C) 2004-2026 The Cacti Group | # | | # | This program is free software; you can redistribute it and/or | # | modify it under the terms of the GNU General Public License | # | as published by the Free Software Foundation; either version 2 | # | of the License, or (at your option) any later version. | # +-------------------------------------------------------------------------+ # | Cacti: The Complete RRDtool-based Graphing Solution | # +-------------------------------------------------------------------------+ set -euo pipefail COMPOSE_PROJECT="cacti_graph_e2e_$$" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" ENV_FILE="$REPO_DIR/.env.graph-e2e" WEB_PORT=18081 DB_PORT=13307 CONFIG_EXISTED=0 CONFIG_BACKUP="" if [ -f "$REPO_DIR/include/config.php" ]; then CONFIG_EXISTED=1 CONFIG_BACKUP="$(mktemp "${TMPDIR:-/tmp}/cacti-config.XXXXXX")" cp "$REPO_DIR/include/config.php" "$CONFIG_BACKUP" rm -f "$REPO_DIR/include/config.php" fi cleanup() { cd "$REPO_DIR" docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" down -v --remove-orphans 2>/dev/null || true rm -f "$ENV_FILE" if [ "$CONFIG_EXISTED" -eq 1 ] && [ -n "$CONFIG_BACKUP" ] && [ -f "$CONFIG_BACKUP" ]; then # The entrypoint may have created a container-owned config.php that cp # cannot open for writing; the host user can still unlink it. rm -f "$REPO_DIR/include/config.php" cp "$CONFIG_BACKUP" "$REPO_DIR/include/config.php" rm -f "$CONFIG_BACKUP" elif [ "$CONFIG_EXISTED" -eq 0 ]; then rm -f "$REPO_DIR/include/config.php" fi } trap cleanup EXIT cd "$REPO_DIR" cat > "$ENV_FILE" </dev/null | grep -o '"Health":"[^"]*"' | head -1 | cut -d'"' -f4 || true) WEB_HEALTH=$(docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" ps --format json 2>/dev/null | grep -o '"Health":"[^"]*"' | tail -1 | cut -d'"' -f4 || true) if [ "$DB_HEALTH" = "healthy" ] && [ "$WEB_HEALTH" = "healthy" ]; then break fi sleep 5 TRIES=$((TRIES + 1)) done if [ "${DB_HEALTH:-}" != "healthy" ] || [ "${WEB_HEALTH:-}" != "healthy" ]; then docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" ps exit 1 fi WEB_CONTAINER=$(docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" ps -q web) docker exec "$WEB_CONTAINER" php -l /var/www/html/cacti/graph_image.php docker exec "$WEB_CONTAINER" php -l /var/www/html/cacti/graph_realtime.php docker exec "$WEB_CONTAINER" php -l /var/www/html/cacti/lib/functions.php docker exec "$WEB_CONTAINER" php -l /var/www/html/cacti/lib/rrd.php docker exec "$WEB_CONTAINER" php -l /var/www/html/cacti/tests/e2e/graph_subsystem_probe.php PROBE_OUTPUT=$(docker exec "$WEB_CONTAINER" php /var/www/html/cacti/tests/e2e/graph_subsystem_probe.php) echo "$PROBE_OUTPUT" grep -q 'PASS graph subsystem docker probe' <<<"$PROBE_OUTPUT"