master
sh 60 lines 1.64 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 Node.js is installed
11 if ! command -v node &> /dev/null; then
12 echo "Error: Node.js is not installed or not in the PATH"
13 echo "Please install Node.js from https://nodejs.org/"
14 exit 1
15 fi
16
17 echo "Node.js is installed: $(node --version)"
18 echo "npm version: $(npm --version)"
19
20 # Check if package.json exists, if not create it
21 if [ ! -f "package.json" ]; then
22 echo "Creating package.json..."
23 npm init -y
24
25 # Update package description and add script
26 tmp=$(mktemp)
27 jq '.description = "Netdata MCP WebSocket bridge for Node.js" |
28 .scripts.start = "node nd-mcp.js" |
29 .private = true' package.json > "$tmp" && mv "$tmp" package.json
30
31 echo "Created package.json"
32 else
33 echo "package.json already exists"
34 fi
35
36 # Install dependencies if not already installed
37 if [ ! -d "node_modules" ]; then
38 echo "Installing dependencies..."
39 npm install ws --save
40 else
41 echo "Dependencies already installed"
42 echo "To reinstall dependencies, delete the node_modules directory and run this script again"
43 fi
44
45 # Get the full path to the script
46 SCRIPT_PATH="$SCRIPT_DIR/nd-mcp.js"
47
48 # Make sure the script is executable
49 chmod +x "$SCRIPT_PATH"
50
51 echo "Build complete!"
52 echo ""
53 echo "You can now run the bridge using the full path:"
54 echo "$SCRIPT_PATH ws://ip:19999/mcp"
55 echo ""
56 echo "Or using Node.js with the full path:"
57 echo "node $SCRIPT_PATH ws://ip:19999/mcp"
58 echo ""
59 echo "Or from this directory:"
60 echo "./nd-mcp.js ws://ip:19999/mcp"