-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·218 lines (191 loc) · 6.78 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·218 lines (191 loc) · 6.78 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
#!/usr/bin/env sh
#
# Memex (Flow) easy install — one command, no virtual env setup.
# Usage: curl -fsSL https://raw.githubusercontent.com/joenewbry/memex/main/install.sh | sh
#
# Installs to ~/.memex and adds a `memex` command. Add ~/.local/bin to your PATH
# if needed, then run: memex start
#
set -e
MEMEX_HOME="${MEMEX_HOME:-$HOME/.memex}"
BIN_DIR="${HOME}/.local/bin"
REPO_URL="${MEMEX_REPO_URL:-https://github.com/joenewbry/memex.git}"
BRANCH="${MEMEX_BRANCH:-main}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo "${BLUE}→${NC} $1"; }
log_ok() { echo "${GREEN}✓${NC} $1"; }
log_warn() { echo "${YELLOW}⚠${NC} $1"; }
log_err() { echo "${RED}✗${NC} $1"; }
# Find a Python 3.10+ executable (prefer 3.12, 3.11, 3.10 over default python3)
find_python() {
for cmd in python3.12 python3.11 python3.10 python3; do
if command -v "$cmd" >/dev/null 2>&1; then
if "$cmd" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; then
echo "$cmd"
return 0
fi
fi
done
return 1
}
# Detect if we're running from inside the repo (e.g. development)
in_repo() {
[ -d "refinery" ] && [ -d "mcp-server" ] && [ -d "cli" ] && [ -f "refinery/flow-requirements.txt" ] && [ -f "mcp-server/requirements.txt" ]
}
# Copy a source tree into the install dir without clobbering live data or caches.
sync_tree() {
src="$1"
dest="$2"
mkdir -p "$dest"
if command -v rsync >/dev/null 2>&1; then
rsync -a \
--exclude '.venv' \
--exclude '__pycache__' \
--exclude '.pytest_cache' \
--exclude 'data' \
--exclude 'logs' \
--exclude 'chroma' \
"$src"/ "$dest"/
else
tar -C "$src" \
--exclude '.venv' \
--exclude '__pycache__' \
--exclude '.pytest_cache' \
--exclude 'data' \
--exclude 'logs' \
--exclude 'chroma' \
-cf - . | tar -C "$dest" -xf -
fi
}
copy_runtime_files() {
src_root="$1"
mkdir -p "$MEMEX_HOME"
sync_tree "$src_root/cli" "$MEMEX_HOME/cli"
sync_tree "$src_root/mcp-server" "$MEMEX_HOME/mcp-server"
mkdir -p "$MEMEX_HOME/refinery"
sync_tree "$src_root/refinery/lib" "$MEMEX_HOME/refinery/lib"
cp "$src_root/refinery/run.py" "$MEMEX_HOME/refinery/run.py"
cp "$src_root/refinery/flow-requirements.txt" "$MEMEX_HOME/refinery/flow-requirements.txt"
[ -f "$src_root/refinery/load_ocr_data.py" ] && cp "$src_root/refinery/load_ocr_data.py" "$MEMEX_HOME/refinery/load_ocr_data.py" || true
[ -f "$src_root/setup.sh" ] && cp "$src_root/setup.sh" "$MEMEX_HOME/" || true
[ -f "$src_root/install.sh" ] && cp "$src_root/install.sh" "$MEMEX_HOME/" || true
mkdir -p \
"$MEMEX_HOME/refinery/data/ocr" \
"$MEMEX_HOME/refinery/data/images" \
"$MEMEX_HOME/refinery/data/audio" \
"$MEMEX_HOME/refinery/logs" \
"$MEMEX_HOME/refinery/chroma"
}
# Install from current directory
install_from_cwd() {
log_info "Installing from current directory into ${MEMEX_HOME}"
copy_runtime_files "$PWD"
}
# Install by cloning repo
install_from_repo() {
log_info "Downloading Memex (Flow) from ${REPO_URL}..."
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t memex)
trap 'rm -rf "$tmpdir"' EXIT
if command -v git >/dev/null 2>&1; then
git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$tmpdir/repo"
else
log_info "Git not found, downloading tarball..."
(cd "$tmpdir" && curl -sL "https://github.com/joenewbry/memex/tarball/${BRANCH}" -o flow.tar.gz && tar xzf flow.tar.gz)
# GitHub tarball extracts to owner-repo-commitHash/
repodir=$(find "$tmpdir" -maxdepth 1 -type d -name '*-flow-*' | head -1)
if [ -n "$repodir" ] && [ -d "$repodir/refinery" ]; then
mv "$repodir" "$tmpdir/repo"
else
log_err "Download or extract failed"
exit 1
fi
fi
log_info "Copying files to ${MEMEX_HOME}"
copy_runtime_files "$tmpdir/repo"
}
# Create single venv and install dependencies
setup_venv() {
log_info "Creating environment (one-time setup)..."
"${PYTHON:-python3}" -m venv "$MEMEX_HOME/.venv"
# shellcheck disable=SC1090
. "$MEMEX_HOME/.venv/bin/activate"
pip install -q --upgrade pip
pip install -q -r "$MEMEX_HOME/refinery/flow-requirements.txt"
pip install -q -r "$MEMEX_HOME/cli/requirements.txt"
if pip install -q -r "$MEMEX_HOME/mcp-server/requirements.txt" 2>/dev/null; then
log_ok "Dependencies installed (refinery + CLI + MCP server)"
else
log_warn "MCP server deps failed (optional). memex start/chat will work; for Claude add MCP deps later."
log_ok "Refinery + CLI dependencies installed"
fi
}
# Write the memex launcher script (invokes full Python CLI)
write_memex_script() {
mkdir -p "$MEMEX_HOME/bin" "$BIN_DIR"
cat > "$MEMEX_HOME/bin/memex" << MEMEX_SCRIPT
#!/usr/bin/env sh
# Memex launcher - full CLI (chat, start, status, doctor, etc.)
MEMEX_HOME="\${MEMEX_HOME:-\$HOME/.memex}"
cd "\$MEMEX_HOME" || exit 1
export PYTHONPATH="\$MEMEX_HOME:\${PYTHONPATH:-}"
exec "\$MEMEX_HOME/.venv/bin/python" -m cli.main "\$@"
MEMEX_SCRIPT
chmod +x "$MEMEX_HOME/bin/memex"
# Symlink or copy into ~/.local/bin so user can run `memex` after adding to PATH
if [ -w "$BIN_DIR" ] 2>/dev/null; then
ln -sf "$MEMEX_HOME/bin/memex" "$BIN_DIR/memex"
log_ok "memex command installed to $BIN_DIR"
else
log_warn "Could not write to $BIN_DIR (run: mkdir -p $BIN_DIR and ensure it is on your PATH)"
fi
}
# Main
main() {
echo ""
echo "Memex (Flow) — easy install"
echo ""
PYTHON=$(find_python) || true
if [ -z "$PYTHON" ]; then
log_err "Python 3.10+ required but not found."
echo ""
echo "Install a newer Python, then re-run this script. Examples:"
echo " macOS (Homebrew): brew install python@3.12"
echo " Then run: curl -fsSL https://raw.githubusercontent.com/joenewbry/memex/main/install.sh | sh"
exit 1
fi
log_info "Using $PYTHON"
if in_repo; then
install_from_cwd
else
install_from_repo
fi
if [ ! -d "$MEMEX_HOME/.venv" ]; then
setup_venv
else
log_info "Using existing environment at $MEMEX_HOME/.venv"
# Ensure deps are present (refinery=chromadb, cli, mcp-server)
# shellcheck disable=SC1090
. "$MEMEX_HOME/.venv/bin/activate"
pip install -q -r "$MEMEX_HOME/refinery/flow-requirements.txt" 2>/dev/null || true
pip install -q -r "$MEMEX_HOME/cli/requirements.txt" 2>/dev/null || true
pip install -q -r "$MEMEX_HOME/mcp-server/requirements.txt" 2>/dev/null || true
fi
write_memex_script
echo ""
log_ok "Installation complete."
echo ""
echo "Add memex to your shell (if not already on PATH):"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
echo "Then run:"
echo " memex start # Start capture (and optionally MCP server)"
echo " memex chat # Chat with Memex"
echo " memex help # See all commands"
echo ""
}
main "$@"