-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·210 lines (180 loc) · 5.71 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·210 lines (180 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bash
set -euo pipefail
# Forgemax installer — downloads pre-built binaries from GitHub releases.
# Usage: curl -fsSL https://raw.githubusercontent.com/postrv/forgemax/main/install.sh | bash
REPO="postrv/forgemax"
INSTALL_DIR="${FORGEMAX_INSTALL_DIR:-$HOME/.local/bin}"
BINARY_NAME="forgemax"
WORKER_NAME="forgemax-worker"
# Colors (only if terminal supports it)
if [ -t 1 ]; then
BOLD='\033[1m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
RESET='\033[0m'
else
BOLD='' GREEN='' YELLOW='' RED='' RESET=''
fi
info() { echo -e "${GREEN}${BOLD}info${RESET} $*"; }
warn() { echo -e "${YELLOW}${BOLD}warn${RESET} $*"; }
error() { echo -e "${RED}${BOLD}error${RESET} $*" >&2; }
detect_platform() {
local os arch
case "$(uname -s)" in
Linux*) os="linux" ;;
Darwin*) os="macos" ;;
*)
error "Unsupported OS: $(uname -s)"
error "Try: cargo install forgemax"
exit 1
;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*)
error "Unsupported architecture: $(uname -m)"
error "Try: cargo install forgemax"
exit 1
;;
esac
echo "${os}-${arch}"
}
get_latest_version() {
local url="https://api.github.com/repos/${REPO}/releases/latest"
if command -v curl &>/dev/null; then
curl -fsSL "$url" | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/'
elif command -v wget &>/dev/null; then
wget -qO- "$url" | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/'
else
error "Neither curl nor wget found"
exit 1
fi
}
download() {
local url="$1" dest="$2"
if command -v curl &>/dev/null; then
curl -fsSL "$url" -o "$dest"
elif command -v wget &>/dev/null; then
wget -q "$url" -O "$dest"
fi
}
# Detect available SHA256 command
detect_sha256_cmd() {
if command -v sha256sum &>/dev/null; then
echo "sha256sum"
elif command -v shasum &>/dev/null; then
echo "shasum -a 256"
else
echo ""
fi
}
# Verify SHA256 checksum of downloaded archive
verify_checksum() {
local archive_file="$1" version="$2" platform="$3"
local sha_cmd checksum_url checksum_file expected actual
sha_cmd="$(detect_sha256_cmd)"
if [ -z "$sha_cmd" ]; then
warn "No SHA256 tool found — skipping verification"
return 0
fi
checksum_url="https://github.com/${REPO}/releases/download/v${version}/SHA256SUMS.txt"
checksum_file="$(mktemp)"
if download "$checksum_url" "$checksum_file" 2>/dev/null; then
expected=$(grep "forgemax-v${version}-${platform}.tar.gz" "$checksum_file" | awk '{print $1}')
if [ -n "$expected" ]; then
actual=$($sha_cmd "$archive_file" | awk '{print $1}')
if [ "$expected" != "$actual" ]; then
error "SHA256 mismatch! Expected: ${expected}, got: ${actual}"
error "The downloaded binary may be corrupted or tampered with."
rm -f "$archive_file" "$checksum_file"
exit 1
fi
info "SHA256 verified"
else
warn "Checksum not found for platform — skipping verification"
fi
rm -f "$checksum_file"
else
warn "Could not download checksums — skipping verification"
rm -f "$checksum_file"
fi
}
main() {
local platform version archive_url archive_file
info "Detecting platform..."
platform="$(detect_platform)"
info "Platform: ${platform}"
if [ -n "${FORGEMAX_VERSION:-}" ]; then
version="$FORGEMAX_VERSION"
info "Using specified version: v${version}"
else
info "Fetching latest version..."
version="$(get_latest_version)"
if [ -z "$version" ]; then
error "Failed to determine latest version"
error "Try: cargo install forgemax"
exit 1
fi
info "Latest version: v${version}"
fi
archive_url="https://github.com/${REPO}/releases/download/v${version}/forgemax-v${version}-${platform}.tar.gz"
archive_file="$(mktemp)"
info "Downloading ${archive_url}..."
if ! download "$archive_url" "$archive_file"; then
rm -f "$archive_file"
error "Download failed"
error "Try: cargo install forgemax"
exit 1
fi
verify_checksum "$archive_file" "$version" "$platform"
info "Installing to ${INSTALL_DIR}..."
mkdir -p "$INSTALL_DIR"
tar xzf "$archive_file" -C "$INSTALL_DIR" "$BINARY_NAME" "$WORKER_NAME" 2>/dev/null || \
tar xzf "$archive_file" -C "$INSTALL_DIR"
rm -f "$archive_file"
chmod 755 "$INSTALL_DIR/$BINARY_NAME" "$INSTALL_DIR/$WORKER_NAME"
# Verify
if "$INSTALL_DIR/$BINARY_NAME" --version &>/dev/null; then
info "Installed: $("$INSTALL_DIR/$BINARY_NAME" --version)"
else
warn "Installed but version check failed"
fi
# Check PATH
if ! echo "$PATH" | tr ':' '\n' | grep -q "^${INSTALL_DIR}$"; then
warn "${INSTALL_DIR} is not in your PATH"
echo ""
info "Add to your shell profile:"
local shell_name
shell_name="$(basename "${SHELL:-/bin/bash}")"
case "$shell_name" in
zsh)
echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.zshrc"
echo " source ~/.zshrc"
;;
fish)
echo " fish_add_path ${INSTALL_DIR}"
;;
*)
echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.bashrc"
echo " source ~/.bashrc"
;;
esac
echo ""
fi
info "Quick start:"
echo ""
echo " 1. Create a config file:"
echo " curl -fsSL https://raw.githubusercontent.com/${REPO}/main/forge.toml.example > forge.toml"
echo ""
echo " 2. Configure your MCP client (Claude Desktop, Cursor, VS Code):"
echo ""
echo " Claude Desktop (~/.claude/claude_desktop_config.json):"
echo ' { "mcpServers": { "forgemax": { "command": "forgemax" } } }'
echo ""
echo " VS Code / Cursor (.mcp.json):"
echo ' { "servers": { "forgemax": { "command": "forgemax", "type": "stdio" } } }'
echo ""
}
main "$@"