#!/bin/bash # Agentic Pentest MCP - Setup Script # Creates a Python virtual environment and installs dependencies. set -e # Detect if running as root (common in containers) if [ "$(id -u)" = "0" ]; then SUDO="" else SUDO="sudo" fi SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" VENV_DIR="$SCRIPT_DIR/.venv" echo "=== Agentic Pentest MCP Setup ===" echo "" # Check for Python 3 if ! command -v python3 &> /dev/null; then echo "Error: python3 not found. Please install Python 3 first." exit 1 fi PYTHON_VERSION=$(python3 --version | cut -d' ' -f2) echo "Found Python $PYTHON_VERSION" # Validate or create virtual environment if [ ! -d "$VENV_DIR" ] || [ ! -f "$VENV_DIR/bin/activate" ]; then # Remove broken/incomplete venv if it exists if [ -d "$VENV_DIR" ]; then echo "Removing incomplete virtual environment..." rm -rf "$VENV_DIR" fi echo "" echo "Creating virtual environment at .venv/" # Try to create venv, install python3-venv package if needed (Debian/Ubuntu) if ! python3 -m venv "$VENV_DIR" 2>/dev/null; then echo "Trying to install python3-venv package..." if command -v apt-get &> /dev/null; then $SUDO apt-get update && $SUDO apt-get install -y python3-venv elif command -v dnf &> /dev/null; then $SUDO dnf install -y python3-venv fi python3 -m venv "$VENV_DIR" fi else echo "Virtual environment already exists at .venv/" fi # Install dependencies using venv's pip directly echo "" echo "Installing dependencies..." "$VENV_DIR/bin/pip" install --upgrade pip > /dev/null 2>&1 "$VENV_DIR/bin/pip" install -r "$SCRIPT_DIR/requirements.txt" echo "" echo "=== Setup Complete ===" echo "" echo "To start the server:" echo " source .venv/bin/activate" echo " export IMPLANT_API_KEY='your-secret-key'" echo " python3 server.py --http 8000" echo "" echo "Or run everything in one command:" echo " source .venv/bin/activate && export IMPLANT_API_KEY='your-secret-key' && python3 server.py --http 8000"