Skip to content

Commit 0a82acf

Browse files
authored
Add install script (#36)
1 parent cf59433 commit 0a82acf

File tree

2 files changed

+253
-2
lines changed

2 files changed

+253
-2
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@ An MCP (Model Context Protocol) server that provides tools for working with Subs
44

55
## Installation
66

7-
### Option 1: Install from GitHub
7+
### 1: Quick Install
8+
9+
```bash
10+
curl -sSfL https://raw.githubusercontent.com/Moonsong-Labs/substrate-mcp/main/install.sh | bash
11+
```
12+
13+
This will:
14+
- Download the appropriate binary for your platform
15+
- Install it to `~/.substrate-mcp/bin/substrate-mcp`
16+
- Add the binary to your PATH
17+
18+
### 2: Download from Releases
19+
20+
Download the binary for your platform from the [latest release](https://github.com/Moonsong-Labs/substrate-mcp/releases/latest).
21+
22+
### Option 3: Install from Source (Requires cargo)
823

924
```bash
1025
cargo install --locked --git https://github.com/Moonsong-Labs/substrate-mcp
1126
```
1227

13-
### Option 2: Build locally (Requires cargo)
28+
### Option 4: Build Locally (Requires cargo)
1429

1530
```bash
31+
git clone https://github.com/Moonsong-Labs/substrate-mcp.git
32+
cd substrate-mcp
1633
cargo build --release
1734
```
1835

install.sh

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Substrate MCP Server Installer
5+
#
6+
# Usage:
7+
# curl -sSfL https://raw.githubusercontent.com/Moonsong-Labs/substrate-mcp/main/install.sh | bash
8+
9+
REPO_URL="https://github.com/Moonsong-Labs/substrate-mcp"
10+
BIN_NAME="substrate-mcp"
11+
INSTALL_DIR="$HOME/.substrate-mcp/bin"
12+
13+
# Colors for output
14+
RED='\033[0;31m'
15+
GREEN='\033[0;32m'
16+
YELLOW='\033[1;33m'
17+
BLUE='\033[0;34m'
18+
NC='\033[0m' # No Color
19+
20+
info() {
21+
echo -e "${BLUE}[INFO]${NC} $1"
22+
}
23+
24+
warn() {
25+
echo -e "${YELLOW}[WARN]${NC} $1"
26+
}
27+
28+
error() {
29+
echo -e "${RED}[ERROR]${NC} $1"
30+
}
31+
32+
success() {
33+
echo -e "${GREEN}[SUCCESS]${NC} $1"
34+
}
35+
36+
detect_platform() {
37+
local arch=""
38+
local os=""
39+
40+
# Detect OS
41+
case "$(uname -s)" in
42+
Darwin)
43+
os="macos"
44+
;;
45+
Linux)
46+
os="linux"
47+
;;
48+
*)
49+
error "Unsupported operating system: $(uname -s)"
50+
error "Please use 'cargo install --git $REPO_URL' instead"
51+
exit 1
52+
;;
53+
esac
54+
55+
# Detect architecture
56+
case "$(uname -m)" in
57+
x86_64|amd64)
58+
arch="x86_64"
59+
;;
60+
aarch64|arm64)
61+
arch="aarch64"
62+
;;
63+
*)
64+
error "Unsupported architecture: $(uname -m)"
65+
error "Please use 'cargo install --git $REPO_URL' instead"
66+
exit 1
67+
;;
68+
esac
69+
70+
echo "${os}-${arch}"
71+
}
72+
73+
# Function to get the latest release version
74+
get_latest_version() {
75+
local version
76+
version=$(curl -s "https://api.github.com/repos/Moonsong-Labs/substrate-mcp/releases/latest" | \
77+
grep '"tag_name":' | \
78+
sed -E 's/.*"([^"]+)".*/\1/')
79+
80+
if [ -z "$version" ]; then
81+
error "Failed to get latest version from GitHub API"
82+
error "Please use 'cargo install --git $REPO_URL' instead"
83+
exit 1
84+
fi
85+
86+
echo "$version"
87+
}
88+
89+
90+
# Function to download and extract binary
91+
download_and_extract() {
92+
local platform="$1"
93+
local version="$2"
94+
local archive_name="${BIN_NAME}-${platform}.tar.gz"
95+
local download_url="${REPO_URL}/releases/download/${version}/${archive_name}"
96+
local temp_dir
97+
temp_dir=$(mktemp -d)
98+
99+
info "Downloading ${BIN_NAME} ${version} for ${platform}..."
100+
101+
if ! curl -L --progress-bar "$download_url" -o "$temp_dir/$archive_name"; then
102+
error "Failed to download binary from $download_url"
103+
error "Please check if the release exists or use 'cargo install --git $REPO_URL' instead"
104+
exit 1
105+
fi
106+
107+
108+
info "Extracting binary..."
109+
if ! tar -xzf "$temp_dir/$archive_name" -C "$temp_dir"; then
110+
error "Failed to extract archive"
111+
exit 1
112+
fi
113+
114+
# Create install directory if it doesn't exist
115+
mkdir -p "$INSTALL_DIR"
116+
117+
# Find the actual binary name in the extracted files
118+
local binary_path
119+
binary_path=$(find "$temp_dir" -name "${BIN_NAME}*" -type f | head -1)
120+
121+
if [ -z "$binary_path" ]; then
122+
error "Could not find binary in extracted archive"
123+
exit 1
124+
fi
125+
126+
# Move binary to install directory with the correct name
127+
if ! mv "$binary_path" "$INSTALL_DIR/$BIN_NAME"; then
128+
error "Failed to move binary to $INSTALL_DIR"
129+
exit 1
130+
fi
131+
132+
# Make binary executable
133+
chmod +x "$INSTALL_DIR/$BIN_NAME"
134+
135+
# Cleanup
136+
rm -rf "$temp_dir"
137+
138+
success "Binary installed to $INSTALL_DIR/$BIN_NAME"
139+
}
140+
141+
# Function to setup PATH
142+
setup_path() {
143+
local shell_profile=""
144+
local shell_name
145+
shell_name=$(basename "$SHELL")
146+
147+
# Check if already in PATH
148+
if echo "$PATH" | grep -q "$INSTALL_DIR"; then
149+
info "$INSTALL_DIR is already in your PATH"
150+
return 0
151+
fi
152+
153+
# Determine shell profile file
154+
case "$shell_name" in
155+
bash)
156+
if [ -f "$HOME/.bash_profile" ]; then
157+
shell_profile="$HOME/.bash_profile"
158+
elif [ -f "$HOME/.bashrc" ]; then
159+
shell_profile="$HOME/.bashrc"
160+
else
161+
shell_profile="$HOME/.bash_profile"
162+
fi
163+
;;
164+
zsh)
165+
shell_profile="$HOME/.zshrc"
166+
;;
167+
fish)
168+
# Fish has a different syntax
169+
if command -v fish >/dev/null 2>&1; then
170+
info "Adding $INSTALL_DIR to fish PATH..."
171+
fish -c "fish_add_path $INSTALL_DIR" 2>/dev/null || true
172+
success "Added $INSTALL_DIR to fish PATH"
173+
return 0
174+
fi
175+
;;
176+
*)
177+
warn "Unknown shell: $shell_name"
178+
warn "Please manually add $INSTALL_DIR to your PATH"
179+
return 1
180+
;;
181+
esac
182+
183+
# Add to PATH for bash/zsh
184+
if [ -n "$shell_profile" ]; then
185+
info "Adding $INSTALL_DIR to PATH in $shell_profile..."
186+
echo "" >> "$shell_profile"
187+
echo "# substrate-mcp" >> "$shell_profile"
188+
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$shell_profile"
189+
success "Added $INSTALL_DIR to PATH in $shell_profile"
190+
info "Please restart your shell or run: source $shell_profile"
191+
fi
192+
}
193+
194+
195+
# Main installation function
196+
main() {
197+
info "Starting substrate-mcp installation..."
198+
199+
# Check if curl is available
200+
if ! command -v curl >/dev/null 2>&1; then
201+
error "curl is required but not installed"
202+
error "Please install curl and try again"
203+
exit 1
204+
fi
205+
206+
# Check if tar is available
207+
if ! command -v tar >/dev/null 2>&1; then
208+
error "tar is required but not installed"
209+
error "Please install tar and try again"
210+
exit 1
211+
fi
212+
213+
local platform version
214+
215+
# Detect platform
216+
platform=$(detect_platform)
217+
info "Detected platform: $platform"
218+
219+
# Get latest version
220+
info "Fetching latest release information..."
221+
version=$(get_latest_version)
222+
info "Latest version: $version"
223+
224+
# Download and extract
225+
download_and_extract "$platform" "$version"
226+
227+
setup_path
228+
229+
echo ""
230+
success "substrate-mcp installation complete!"
231+
}
232+
233+
# Run main function
234+
main "$@"

0 commit comments

Comments
 (0)