-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·279 lines (245 loc) · 9.54 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·279 lines (245 loc) · 9.54 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/sh
# Copyright 2026 AlphaOne LLC
# SPDX-License-Identifier: Apache-2.0
set -e
REPO="alphaonedev/ai-memory-mcp"
BINARY="ai-memory"
VERSION="latest"
# ---------------------------------------------------------------------------
# Help
# ---------------------------------------------------------------------------
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<'USAGE'
Usage: install.sh [OPTIONS]
Install the ai-memory binary from GitHub releases.
Options:
-h, --help Show this help message
--dir DIR Override install directory (default: ~/.cargo/bin or ~/.local/bin)
--version VER Install a specific version tag (default: latest)
Environment variables:
AI_MEMORY_INSTALL_DIR Override install directory
Examples:
curl -fsSL https://raw.githubusercontent.com/alphaonedev/ai-memory-mcp/main/install.sh | sh
./install.sh --dir /usr/local/bin
AI_MEMORY_INSTALL_DIR=~/bin ./install.sh
USAGE
exit 0
fi
# ---------------------------------------------------------------------------
# Parse arguments
# ---------------------------------------------------------------------------
while [ $# -gt 0 ]; do
case "$1" in
--dir) shift; AI_MEMORY_INSTALL_DIR="$1" ;;
--version) shift; VERSION="$1" ;;
*) echo "Unknown option: $1 (try --help)" >&2; exit 1 ;;
esac
shift
done
# ---------------------------------------------------------------------------
# Windows / PowerShell detection
# ---------------------------------------------------------------------------
if [ -n "$PSModulePath" ] || [ -n "$POWERSHELL_DISTRIBUTION_CHANNEL" ]; then
echo "Error: It looks like you are running inside PowerShell." >&2
echo "Please use install.ps1 instead:" >&2
echo " irm https://raw.githubusercontent.com/$REPO/main/install.ps1 | iex" >&2
exit 1
fi
# ---------------------------------------------------------------------------
# Detect OS
# ---------------------------------------------------------------------------
OS="$(uname -s)"
case "$OS" in
Linux) os="unknown-linux-gnu" ;;
Darwin) os="apple-darwin" ;;
MINGW*|MSYS*|CYGWIN*) os="pc-windows-msvc" ;;
*)
echo "Error: Unsupported OS: $OS" >&2
echo "Fallback: cargo install ai-memory" >&2
exit 1
;;
esac
# ---------------------------------------------------------------------------
# Detect architecture
# ---------------------------------------------------------------------------
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*)
echo "Error: Unsupported architecture: $ARCH" >&2
echo "Fallback: cargo install ai-memory" >&2
exit 1
;;
esac
TARGET="${arch}-${os}"
# ---------------------------------------------------------------------------
# File extension
# ---------------------------------------------------------------------------
case "$os" in
*windows*) EXT="zip" ;;
*) EXT="tar.gz" ;;
esac
ASSET="ai-memory-${TARGET}.${EXT}"
# ---------------------------------------------------------------------------
# Install directory: prefer ~/.cargo/bin, fall back to ~/.local/bin
# ---------------------------------------------------------------------------
if [ -n "$AI_MEMORY_INSTALL_DIR" ]; then
INSTALL_DIR="$AI_MEMORY_INSTALL_DIR"
elif [ -d "$HOME/.cargo/bin" ]; then
INSTALL_DIR="$HOME/.cargo/bin"
else
INSTALL_DIR="$HOME/.local/bin"
fi
echo "Detected platform: ${TARGET}"
echo "Installing to: ${INSTALL_DIR}"
# ---------------------------------------------------------------------------
# Build download URLs
# ---------------------------------------------------------------------------
if [ "$VERSION" = "latest" ]; then
BASE_URL="https://github.com/${REPO}/releases/latest/download"
else
BASE_URL="https://github.com/${REPO}/releases/download/${VERSION}"
fi
RELEASE_URL="${BASE_URL}/${ASSET}"
CHECKSUM_URL="${BASE_URL}/${ASSET}.sha256"
# ---------------------------------------------------------------------------
# Create install directory
# ---------------------------------------------------------------------------
mkdir -p "$INSTALL_DIR"
# ---------------------------------------------------------------------------
# Temp directory with cleanup
# ---------------------------------------------------------------------------
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
# ---------------------------------------------------------------------------
# Download helper with exit-code checking
# ---------------------------------------------------------------------------
download() {
_url="$1"
_dest="$2"
_label="$3"
if command -v curl >/dev/null 2>&1; then
if ! curl -fsSL "$_url" -o "$_dest" 2>/dev/null; then
echo "Error: Failed to download ${_label} from:" >&2
echo " ${_url}" >&2
echo "" >&2
echo "If this is a 404, the release may not exist for your platform." >&2
echo "Fallback: cargo install ai-memory" >&2
return 1
fi
elif command -v wget >/dev/null 2>&1; then
if ! wget -q "$_url" -O "$_dest" 2>/dev/null; then
echo "Error: Failed to download ${_label} from:" >&2
echo " ${_url}" >&2
echo "" >&2
echo "If this is a 404, the release may not exist for your platform." >&2
echo "Fallback: cargo install ai-memory" >&2
return 1
fi
else
echo "Error: curl or wget is required to download files." >&2
exit 1
fi
}
# ---------------------------------------------------------------------------
# Download binary archive
# ---------------------------------------------------------------------------
echo "Downloading ${ASSET}..."
if ! download "$RELEASE_URL" "$TMPDIR/$ASSET" "$ASSET"; then
exit 1
fi
# Print binary archive size
FILESIZE=$(wc -c < "$TMPDIR/$ASSET" | tr -d ' ')
if [ "$FILESIZE" -gt 1048576 ] 2>/dev/null; then
SIZE_MB=$(echo "scale=1; $FILESIZE / 1048576" | bc 2>/dev/null || echo "$FILESIZE bytes")
echo "Downloaded: ${SIZE_MB} MB"
else
echo "Downloaded: ${FILESIZE} bytes"
fi
# ---------------------------------------------------------------------------
# Download and verify SHA256 checksum
# ---------------------------------------------------------------------------
echo "Verifying checksum..."
if download "$CHECKSUM_URL" "$TMPDIR/${ASSET}.sha256" "checksum" 2>/dev/null; then
EXPECTED_HASH=$(awk '{print $1}' "$TMPDIR/${ASSET}.sha256")
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL_HASH=$(sha256sum "$TMPDIR/$ASSET" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
ACTUAL_HASH=$(shasum -a 256 "$TMPDIR/$ASSET" | awk '{print $1}')
else
echo "Warning: No sha256sum or shasum found, skipping checksum verification." >&2
ACTUAL_HASH=""
EXPECTED_HASH=""
fi
if [ -n "$EXPECTED_HASH" ] && [ -n "$ACTUAL_HASH" ]; then
if [ "$EXPECTED_HASH" != "$ACTUAL_HASH" ]; then
echo "Error: Checksum mismatch!" >&2
echo " Expected: ${EXPECTED_HASH}" >&2
echo " Actual: ${ACTUAL_HASH}" >&2
echo "" >&2
echo "The downloaded file may be corrupted. Please try again." >&2
exit 1
fi
echo "Checksum OK: ${ACTUAL_HASH}"
fi
else
echo "Warning: Checksum file not available, skipping verification."
fi
# ---------------------------------------------------------------------------
# Extract
# ---------------------------------------------------------------------------
echo "Extracting..."
case "$EXT" in
tar.gz) tar xzf "$TMPDIR/$ASSET" -C "$TMPDIR" ;;
zip) unzip -qo "$TMPDIR/$ASSET" -d "$TMPDIR" ;;
esac
# ---------------------------------------------------------------------------
# Validate extracted binary
# ---------------------------------------------------------------------------
if [ ! -f "$TMPDIR/$BINARY" ]; then
echo "Error: Expected binary '$BINARY' not found after extraction." >&2
echo "Archive contents:" >&2
ls -la "$TMPDIR/" >&2
echo "" >&2
echo "Fallback: cargo install ai-memory" >&2
exit 1
fi
# ---------------------------------------------------------------------------
# Install binary
# ---------------------------------------------------------------------------
cp "$TMPDIR/$BINARY" "$INSTALL_DIR/$BINARY"
chmod +x "$INSTALL_DIR/$BINARY"
if [ ! -x "$INSTALL_DIR/$BINARY" ]; then
echo "Error: Installed binary is not executable at $INSTALL_DIR/$BINARY" >&2
exit 1
fi
# ---------------------------------------------------------------------------
# macOS: remove Gatekeeper quarantine attribute
# ---------------------------------------------------------------------------
if [ "$OS" = "Darwin" ]; then
xattr -d com.apple.quarantine "$INSTALL_DIR/$BINARY" 2>/dev/null || true
fi
# ---------------------------------------------------------------------------
# Done
# ---------------------------------------------------------------------------
echo ""
echo "Installed ${BINARY} to ${INSTALL_DIR}/${BINARY}"
# Verify installation by running the binary
if "$INSTALL_DIR/$BINARY" stats >/dev/null 2>&1; then
echo "Verification: binary runs successfully."
else
echo "Installed successfully (could not run 'ai-memory stats' -- database may not be configured yet)."
fi
# Check if install dir is in PATH
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "Note: ${INSTALL_DIR} is not in your PATH."
echo "Add it with:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
echo ""
echo "Run 'ai-memory --help' to get started."