-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·374 lines (340 loc) · 10.1 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·374 lines (340 loc) · 10.1 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/bin/sh
set -eu
REPO_URL=${TREE_RING_REPO:-"https://github.com/TerminallyLazy/Tree-Ring-Memory"}
GIT_REF=${TREE_RING_REF:-"main"}
INSTALL_SCOPE=${TREE_RING_INSTALL_SCOPE:-"global"}
INSTALL_DIR=${TREE_RING_INSTALL_DIR:-""}
SOURCE_DIR=${TREE_RING_SOURCE:-""}
ARCHIVE_URL=${TREE_RING_ARCHIVE_URL:-""}
ARCHIVE_SHA256=${TREE_RING_ARCHIVE_SHA256:-""}
MEMORY_ROOT=${TREE_RING_ROOT:-".tree-ring"}
RUN_INIT=${TREE_RING_INIT:-"0"}
RUN_ONBOARDING=${TREE_RING_ONBOARDING:-"1"}
ANIMATION=${TREE_RING_ANIMATION:-"auto"}
UPDATE_PATH=${TREE_RING_UPDATE_PATH:-"1"}
PATH_PROFILE_UPDATED=""
if [ ! -t 1 ] || [ "${NO_COLOR:-}" != "" ]; then
COLOR=0
else
COLOR=1
fi
case "$ANIMATION" in
auto|0|1) ;;
*) ANIMATION=auto ;;
esac
if [ "$ANIMATION" = "auto" ]; then
if [ -t 1 ] && [ "$COLOR" = "1" ] && [ "${TERM:-}" != "dumb" ]; then
ANIMATION=1
else
ANIMATION=0
fi
fi
die() {
printf '%s\n' "Tree Ring Memory install failed: $*" >&2
exit 1
}
usage() {
cat <<'EOF'
Tree Ring Memory installer
Usage:
curl -fsSL https://raw.githubusercontent.com/TerminallyLazy/Tree-Ring-Memory/main/install.sh | sh
curl -fsSL https://raw.githubusercontent.com/TerminallyLazy/Tree-Ring-Memory/main/install.sh | sh -s -- --project --init
Options:
--global Install to $HOME/.local/bin (default).
--project Install to .tree-ring/bin in the current project.
--init Run tree-ring welcome --init after install.
--no-init Do not initialize memory after install (default).
--animation Allow animated Rust terminal onboarding when stdout is a TTY.
--no-animation Use stable Rust terminal onboarding without animation.
--no-onboarding Skip tree-ring welcome after install.
--no-path-update Do not append the global install bin dir to a shell profile.
--install-dir DIR Override install prefix. Binary goes in DIR/bin.
--root DIR Memory root used by onboarding/init (default .tree-ring).
--repo URL Git repository used by cargo install.
--ref REF Git branch used by cargo install (default main).
--source DIR Install from a local checkout instead of git.
--archive-url URL Install from a release tarball containing tree-ring.
--archive-sha256 SUM Required SHA-256 for --archive-url.
-h, --help Show this help.
Environment:
TREE_RING_INSTALL_SCOPE=global|project
TREE_RING_INSTALL_DIR=/path/to/prefix
TREE_RING_ROOT=.tree-ring
TREE_RING_REPO=https://github.com/TerminallyLazy/Tree-Ring-Memory
TREE_RING_REF=main
TREE_RING_SOURCE=/path/to/checkout
TREE_RING_ARCHIVE_URL=https://example/tree-ring-memory.tar.gz
TREE_RING_ARCHIVE_SHA256=...
TREE_RING_INIT=1
TREE_RING_ANIMATION=auto|1|0
TREE_RING_ONBOARDING=0
TREE_RING_UPDATE_PATH=0
EOF
}
while [ "$#" -gt 0 ]; do
case "$1" in
--global)
INSTALL_SCOPE=global
;;
--project)
INSTALL_SCOPE=project
;;
--init)
RUN_INIT=1
;;
--no-init)
RUN_INIT=0
;;
--animation)
ANIMATION=1
;;
--no-animation)
ANIMATION=0
;;
--no-onboarding)
RUN_ONBOARDING=0
;;
--no-path-update)
UPDATE_PATH=0
;;
--install-dir)
shift
[ "$#" -gt 0 ] || die "--install-dir requires a value"
INSTALL_DIR=$1
;;
--root)
shift
[ "$#" -gt 0 ] || die "--root requires a value"
MEMORY_ROOT=$1
;;
--repo)
shift
[ "$#" -gt 0 ] || die "--repo requires a value"
REPO_URL=$1
;;
--ref)
shift
[ "$#" -gt 0 ] || die "--ref requires a value"
GIT_REF=$1
;;
--source)
shift
[ "$#" -gt 0 ] || die "--source requires a value"
SOURCE_DIR=$1
;;
--archive-url)
shift
[ "$#" -gt 0 ] || die "--archive-url requires a value"
ARCHIVE_URL=$1
;;
--archive-sha256)
shift
[ "$#" -gt 0 ] || die "--archive-sha256 requires a value"
ARCHIVE_SHA256=$1
;;
-h|--help)
usage
exit 0
;;
*)
die "unknown option: $1"
;;
esac
shift
done
if [ "$ARCHIVE_URL" != "" ] && [ "$ARCHIVE_SHA256" = "" ]; then
die "--archive-sha256 is required with --archive-url"
fi
paint() {
code=$1
text=$2
if [ "$COLOR" = "1" ]; then
printf '\033[%sm%s\033[0m' "$code" "$text"
else
printf '%s' "$text"
fi
}
line() {
printf '%s\n' "$*"
}
paint_line() {
paint "$1" "$2"
line ""
}
intro() {
if [ "$RUN_ONBOARDING" != "1" ]; then
paint_line "38;5;244" "Skipping terminal onboarding (--no-onboarding)."
fi
paint "1" "Tree Ring Memory"
line " installer"
line "Framework-agnostic local memory for AI agents."
line ""
}
require_cargo() {
if [ "$ARCHIVE_URL" != "" ]; then
return
fi
if ! command -v cargo >/dev/null 2>&1; then
die "cargo was not found. Install Rust from https://rustup.rs, then rerun this installer."
fi
}
download() {
url=$1
output=$2
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$output"
elif command -v wget >/dev/null 2>&1; then
wget -q "$url" -O "$output"
else
die "curl or wget is required for --archive-url"
fi
}
verify_sha256() {
file=$1
expected=$2
[ "$expected" != "" ] || return
if command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "$file" | awk '{print $1}')
elif command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$file" | awk '{print $1}')
else
die "SHA-256 verification requested, but shasum/sha256sum was not found"
fi
actual_lower=$(printf '%s' "$actual" | tr '[:upper:]' '[:lower:]')
expected_lower=$(printf '%s' "$expected" | tr '[:upper:]' '[:lower:]')
[ "$actual_lower" = "$expected_lower" ] || die "archive checksum mismatch"
}
install_prefix() {
if [ "$INSTALL_DIR" != "" ]; then
printf '%s' "$INSTALL_DIR"
return
fi
if [ "$INSTALL_SCOPE" = "project" ]; then
printf '%s' ".tree-ring"
else
[ "${HOME:-}" != "" ] || die "HOME is not set. Pass --install-dir or use --project."
printf '%s' "$HOME/.local"
fi
}
install_binary() {
prefix=$1
mkdir -p "$prefix"
line "Installing tree-ring into $prefix/bin"
if [ "$ARCHIVE_URL" != "" ]; then
tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/tree-ring-install.XXXXXX")
archive="$tmp_dir/tree-ring-memory.tar.gz"
download "$ARCHIVE_URL" "$archive"
verify_sha256 "$archive" "$ARCHIVE_SHA256"
tar -xzf "$archive" -C "$tmp_dir"
binary=$(find "$tmp_dir" -type f -name tree-ring | head -n 1)
[ "$binary" != "" ] || die "release archive did not contain tree-ring"
mkdir -p "$prefix/bin"
cp "$binary" "$prefix/bin/tree-ring"
chmod +x "$prefix/bin/tree-ring"
rm -rf "$tmp_dir"
elif [ "$SOURCE_DIR" != "" ]; then
line "Setting things up. This usually takes about 30 seconds after dependencies are cached."
cargo install --path "$SOURCE_DIR/crates/tree-ring-memory-cli" --root "$prefix" --locked --force
else
line "Setting things up. This usually takes about 30 seconds after dependencies are cached."
cargo install --git "$REPO_URL" --branch "$GIT_REF" tree-ring-memory-cli --root "$prefix" --locked --force
fi
}
path_contains() {
case ":$PATH:" in
*":$1:"*) return 0 ;;
*) return 1 ;;
esac
}
shell_quote() {
printf "'"
printf '%s' "$1" | sed "s/'/'\\\\''/g"
printf "'"
}
shell_profile_path() {
[ "${HOME:-}" != "" ] || return 1
shell_name=$(basename "${SHELL:-}")
case "$shell_name" in
zsh)
[ -f "$HOME/.zshrc" ] && { printf '%s' "$HOME/.zshrc"; return 0; }
[ -f "$HOME/.zprofile" ] && { printf '%s' "$HOME/.zprofile"; return 0; }
printf '%s' "$HOME/.zshrc"
;;
bash)
[ -f "$HOME/.bashrc" ] && { printf '%s' "$HOME/.bashrc"; return 0; }
[ -f "$HOME/.bash_profile" ] && { printf '%s' "$HOME/.bash_profile"; return 0; }
printf '%s' "$HOME/.bashrc"
;;
*)
[ -f "$HOME/.profile" ] && { printf '%s' "$HOME/.profile"; return 0; }
[ -f "$HOME/.zshrc" ] && { printf '%s' "$HOME/.zshrc"; return 0; }
[ -f "$HOME/.bashrc" ] && { printf '%s' "$HOME/.bashrc"; return 0; }
printf '%s' "$HOME/.profile"
;;
esac
}
update_shell_path() {
prefix_bin=$1
[ "$INSTALL_SCOPE" = "global" ] || return 0
[ "$UPDATE_PATH" = "1" ] || return 0
path_contains "$prefix_bin" && return 0
[ "${HOME:-}" != "" ] || return 0
[ -d "$HOME" ] || mkdir -p "$HOME" || return 0
profile=$(shell_profile_path) || return 0
marker="# >>> Tree Ring Memory PATH >>>"
if [ -f "$profile" ] && grep -F "$marker" "$profile" >/dev/null 2>&1; then
PATH_PROFILE_UPDATED=$profile
return 0
fi
quoted_prefix_bin=$(shell_quote "$prefix_bin")
if {
printf '\n%s\n' "$marker"
printf 'TREE_RING_BIN_DIR=%s\n' "$quoted_prefix_bin"
printf 'case ":$PATH:" in\n'
printf ' *":$TREE_RING_BIN_DIR:"*) ;;\n'
printf ' *) export PATH="$TREE_RING_BIN_DIR:$PATH" ;;\n'
printf 'esac\n'
printf '# <<< Tree Ring Memory PATH <<<\n'
} >> "$profile"
then
PATH_PROFILE_UPDATED=$profile
fi
}
intro
require_cargo
PREFIX=$(install_prefix)
BIN="$PREFIX/bin/tree-ring"
install_binary "$PREFIX"
update_shell_path "$PREFIX/bin"
[ -x "$BIN" ] || die "expected installed binary at $BIN"
"$BIN" --help >/dev/null || die "installed binary did not run"
line ""
paint "1" "Installed:"
line " $BIN"
if [ "$RUN_ONBOARDING" = "1" ]; then
WELCOME_FLAGS=""
if [ "$RUN_INIT" = "1" ]; then
WELCOME_FLAGS="$WELCOME_FLAGS --init"
fi
if [ "$ANIMATION" != "1" ]; then
WELCOME_FLAGS="$WELCOME_FLAGS --no-animation"
fi
# shellcheck disable=SC2086
"$BIN" --root "$MEMORY_ROOT" welcome $WELCOME_FLAGS
fi
line ""
if [ "$INSTALL_SCOPE" = "global" ] && ! path_contains "$PREFIX/bin"; then
if [ "$PATH_PROFILE_UPDATED" != "" ] && [ "$UPDATE_PATH" = "1" ]; then
line "Updated shell profile: $PATH_PROFILE_UPDATED"
line "Open a new terminal, or run this now:"
else
line "Add this to your shell profile if tree-ring is not found:"
fi
line " export PATH=\"$PREFIX/bin:\$PATH\""
fi
if [ "$INSTALL_SCOPE" = "project" ]; then
line "For project-local use:"
line " export PATH=\"$PWD/$PREFIX/bin:\$PATH\""
fi
line "Open the TUI:"
line " $BIN --root $MEMORY_ROOT tui"