master
sh 70 lines 2.09 KB
Raw
1 #!/bin/bash
2 set -e
3
4 # Get the directory where the script is located
5 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6 cd "$SCRIPT_DIR"
7
8 echo "Working directory: $SCRIPT_DIR"
9
10 # Check if Python is installed
11 if ! command -v python3 &> /dev/null; then
12 echo "Error: Python 3 is not installed or not in the PATH"
13 echo "Please install Python 3 from https://www.python.org/ or through your package manager"
14 exit 1
15 fi
16
17 echo "Python is installed: $(python3 --version)"
18
19 # Create virtual environment if it doesn't exist
20 if [ ! -d "venv" ]; then
21 echo "Creating virtual environment..."
22 python3 -m venv venv
23 echo "Virtual environment created at $SCRIPT_DIR/venv"
24 else
25 echo "Virtual environment already exists at $SCRIPT_DIR/venv"
26 fi
27
28 # Activate virtual environment
29 echo "Activating virtual environment..."
30 source venv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
31
32 # Check pip version
33 echo "pip version: $(pip --version)"
34
35 # Install requirements
36 echo "Installing dependencies..."
37 pip install websockets
38
39 # Create requirements.txt if it doesn't exist
40 if [ ! -f "requirements.txt" ]; then
41 echo "Creating requirements.txt..."
42 pip freeze > requirements.txt
43 echo "requirements.txt created"
44 else
45 echo "requirements.txt already exists"
46 echo "To update it, run: source $SCRIPT_DIR/venv/bin/activate && pip freeze > requirements.txt"
47 fi
48
49 # Get the full path to the script and venv
50 SCRIPT_PATH="$SCRIPT_DIR/nd-mcp.py"
51 VENV_PYTHON="$SCRIPT_DIR/venv/bin/python"
52 VENV_ACTIVATE="$SCRIPT_DIR/venv/bin/activate"
53
54 # Make sure the script is executable
55 chmod +x "$SCRIPT_PATH"
56
57 echo "Build complete!"
58 echo ""
59 echo "To use the bridge with the virtual environment:"
60 echo ""
61 echo "Option 1: Activate the environment and run the script"
62 echo "source $VENV_ACTIVATE"
63 echo "python $SCRIPT_PATH ws://ip:19999/mcp"
64 echo "deactivate # when finished"
65 echo ""
66 echo "Option 2: Run directly with the virtual environment's Python"
67 echo "$VENV_PYTHON $SCRIPT_PATH ws://ip:19999/mcp"
68 echo ""
69 echo "Option 3: Run the script directly (using the system's Python)"
70 echo "$SCRIPT_PATH ws://ip:19999/mcp"