|
3 | 3 | # Enable strict mode to exit on errors and unset variables |
4 | 4 | set -euo pipefail |
5 | 5 |
|
6 | | -# Set log file |
7 | | -LOG_FILE="/tmp/mcp.log" |
8 | | - |
9 | | -# Clear the log file at the start |
10 | | -> "$LOG_FILE" |
11 | | - |
12 | | -# Function for logging |
13 | | -log() { |
14 | | - local MESSAGE="$1" |
15 | | - echo "$(date +'%Y-%m-%d %H:%M:%S') - $MESSAGE" | tee -a "$LOG_FILE" >&2 |
16 | | -} |
17 | | - |
18 | | -# Trap errors and log them before exiting |
19 | | -trap 'log "An error occurred. Exiting with status $?."' ERR |
20 | | - |
21 | | -log "Starting npx setup script." |
22 | | - |
23 | | -# Ensure ~/.config/goose/mcp-hermit/bin exists |
24 | | -log "Creating directory ~/.config/goose/mcp-hermit/bin if it does not exist." |
25 | | -mkdir -p ~/.config/goose/mcp-hermit/bin |
26 | | - |
27 | | -# Change to the ~/.config/goose/mcp-hermit directory |
28 | | -log "Changing to directory ~/.config/goose/mcp-hermit." |
29 | | -cd ~/.config/goose/mcp-hermit |
30 | | - |
31 | | - |
32 | | -# Check if hermit binary exists and download if not |
33 | | -if [ ! -f ~/.config/goose/mcp-hermit/bin/hermit ]; then |
34 | | - log "Hermit binary not found. Downloading hermit binary." |
35 | | - curl -fsSL "https://github.com/cashapp/hermit/releases/download/stable/hermit-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/').gz" \ |
36 | | - | gzip -dc > ~/.config/goose/mcp-hermit/bin/hermit && chmod +x ~/.config/goose/mcp-hermit/bin/hermit |
37 | | - log "Hermit binary downloaded and made executable." |
38 | | -else |
39 | | - log "Hermit binary already exists. Skipping download." |
40 | | -fi |
41 | | - |
42 | | - |
43 | | -log "setting hermit cache to be local for MCP servers" |
44 | | -mkdir -p ~/.config/goose/mcp-hermit/cache |
45 | | -export HERMIT_STATE_DIR=~/.config/goose/mcp-hermit/cache |
46 | | - |
47 | | - |
48 | | -# Update PATH |
49 | | -export PATH=~/.config/goose/mcp-hermit/bin:$PATH |
50 | | -log "Updated PATH to include ~/.config/goose/mcp-hermit/bin." |
51 | | - |
52 | | - |
53 | | -# Verify hermit installation |
54 | | -log "Checking for hermit in PATH." |
55 | | -which hermit >> "$LOG_FILE" |
56 | | - |
57 | | -# Initialize hermit |
58 | | -log "Initializing hermit." |
59 | | -hermit init >> "$LOG_FILE" |
60 | | - |
61 | | -# Install Node.js using hermit |
62 | | -log "Installing Node.js with hermit." |
63 | | -hermit install node >> "$LOG_FILE" |
64 | | - |
65 | | -# Verify installations |
66 | | -log "Verifying installation locations:" |
67 | | -log "hermit: $(which hermit)" |
68 | | -log "node: $(which node)" |
69 | | -log "npx: $(which npx)" |
70 | | - |
71 | | - |
72 | | -log "Checking for GOOSE_NPM_REGISTRY and GOOSE_NPM_CERT environment variables for custom npm registry setup..." |
73 | | -# Check if GOOSE_NPM_REGISTRY is set and accessible |
74 | | -if [ -n "${GOOSE_NPM_REGISTRY:-}" ] && curl -s --head --fail "$GOOSE_NPM_REGISTRY" > /dev/null; then |
75 | | - log "Checking custom goose registry availability: $GOOSE_NPM_REGISTRY" |
76 | | - log "$GOOSE_NPM_REGISTRY is accessible. Using it for npm registry." |
77 | | - export NPM_CONFIG_REGISTRY="$GOOSE_NPM_REGISTRY" |
78 | | - |
79 | | - # Check if GOOSE_NPM_CERT is set and accessible |
80 | | - if [ -n "${GOOSE_NPM_CERT:-}" ] && curl -s --head --fail "$GOOSE_NPM_CERT" > /dev/null; then |
81 | | - log "Downloading certificate from: $GOOSE_NPM_CERT" |
82 | | - curl -sSL -o ~/.config/goose/mcp-hermit/cert.pem "$GOOSE_NPM_CERT" |
83 | | - if [ $? -eq 0 ]; then |
84 | | - log "Certificate downloaded successfully." |
85 | | - export NODE_EXTRA_CA_CERTS=~/.config/goose/mcp-hermit/cert.pem |
86 | | - else |
87 | | - log "Unable to download the certificate. Skipping certificate setup." |
88 | | - fi |
89 | | - else |
90 | | - log "GOOSE_NPM_CERT is either not set or not accessible. Skipping certificate setup." |
91 | | - fi |
92 | | - |
93 | | -else |
94 | | - log "GOOSE_NPM_REGISTRY is either not set or not accessible. Falling back to default npm registry." |
95 | | - export NPM_CONFIG_REGISTRY="https://registry.npmjs.org/" |
96 | | -fi |
97 | | - |
98 | | - |
| 6 | +# Get the directory where this script is located |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
99 | 8 |
|
| 9 | +# Source the common setup script |
| 10 | +source "$SCRIPT_DIR/node-setup-common.sh" |
100 | 11 |
|
101 | 12 | # Final step: Execute npx with passed arguments |
102 | 13 | log "Executing 'npx' command with arguments: $*" |
103 | 14 | npx "$@" || log "Failed to execute 'npx' with arguments: $*" |
104 | 15 |
|
105 | | -log "npx setup script completed successfully." |
| 16 | +log "npx script completed successfully." |
0 commit comments