-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·143 lines (127 loc) · 4.9 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·143 lines (127 loc) · 4.9 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
#!/bin/sh
# install.sh — installs the agentvfs prebuilt to ~/.local/bin (default).
# Usage: curl -fsSL https://raw.githubusercontent.com/thustorage/ContextFS/main/install.sh | sh
set -eu
REPO="thustorage/ContextFS"
URL_BASE="https://github.com/$REPO/releases/download"
VERSION="${AGENTVFS_INSTALL_VERSION:-}"
PREFIX="${AGENTVFS_INSTALL_PREFIX:-$HOME/.local/bin}"
usage() {
cat <<'EOF'
Usage: install.sh [--version <tag>] [--prefix <dir>] [--help]
Installs the agentvfs prebuilt binary, agentvfs-ctl, and agentvfs-quickstart
to PREFIX. Default PREFIX is ~/.local/bin (no sudo).
Environment:
AGENTVFS_INSTALL_VERSION pin a release tag (e.g. v0.1.0)
AGENTVFS_INSTALL_PREFIX override install destination
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--version) VERSION="$2"; shift 2 ;;
--version=*) VERSION="${1#--version=}"; shift ;;
--prefix) PREFIX="$2"; shift 2 ;;
--prefix=*) PREFIX="${1#--prefix=}"; shift ;;
--help|-h) usage; exit 0 ;;
*) echo "install.sh: unknown argument '$1'" >&2; usage >&2; exit 2 ;;
esac
done
# Detect host.
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$os" in
linux|darwin) : ;;
*) echo "install.sh: unsupported OS '$os' — build from source" >&2; exit 1 ;;
esac
case "$arch" in
x86_64|amd64) arch=x86_64 ;;
arm64|aarch64) [ "$os" = darwin ] && arch=arm64 || {
echo "install.sh: aarch64 Linux prebuilt not yet published — build from source" >&2
exit 1; } ;;
*) echo "install.sh: unsupported arch '$arch' — build from source" >&2; exit 1 ;;
esac
HOST_TUPLE="$os-$arch"
# Resolve version.
if [ -z "$VERSION" ]; then
api="https://api.github.com/repos/$REPO/releases/latest"
if command -v curl >/dev/null; then
VERSION="$(curl -fsSL "$api" | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)"
elif command -v wget >/dev/null; then
VERSION="$(wget -qO- "$api" | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)"
else
echo "install.sh: need curl or wget on PATH" >&2; exit 1
fi
[ -n "$VERSION" ] || { echo "install.sh: could not resolve latest release; pin with --version" >&2; exit 1; }
fi
ARCHIVE="agentvfs-$VERSION-$HOST_TUPLE.tar.gz"
CHECKSUMS="agentvfs-$VERSION-checksums.txt"
# Download and verify.
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT INT TERM
fetch() {
if command -v curl >/dev/null; then
curl -fsSL --retry 3 --retry-delay 2 -o "$2" "$1" \
|| { echo "install.sh: download failed: $1" >&2; exit 1; }
else
wget -q --tries=3 -O "$2" "$1" \
|| { echo "install.sh: download failed: $1" >&2; exit 1; }
fi
}
fetch "$URL_BASE/$VERSION/$ARCHIVE" "$WORK/$ARCHIVE"
fetch "$URL_BASE/$VERSION/$CHECKSUMS" "$WORK/$CHECKSUMS"
expected="$(awk -v f="$ARCHIVE" '{ sub(/^\*/, "", $2); if ($2 == f) print $1 }' "$WORK/$CHECKSUMS")"
[ -n "$expected" ] || { echo "install.sh: $ARCHIVE not in checksums file" >&2; exit 1; }
if command -v sha256sum >/dev/null; then
actual="$(sha256sum "$WORK/$ARCHIVE" | awk '{print $1}')"
else
actual="$(shasum -a 256 "$WORK/$ARCHIVE" | awk '{print $1}')"
fi
if [ "$expected" != "$actual" ]; then
echo "install.sh: checksum mismatch for $ARCHIVE" >&2
echo " expected: $expected" >&2
echo " actual: $actual" >&2
exit 1
fi
# Extract and install.
# Archive is expected to be flat (no nested dir); see release.yml packaging.
tar -xzf "$WORK/$ARCHIVE" -C "$WORK"
if [ ! -f "$WORK/agentvfs" ]; then
echo "install.sh: archive missing 'agentvfs' binary — please report at https://github.com/thustorage/ContextFS/issues" >&2
exit 1
fi
mkdir -p "$PREFIX"
for f in agentvfs agentvfs-ctl agentvfs-quickstart; do
[ -f "$WORK/$f" ] && install -m 0755 "$WORK/$f" "$PREFIX/$f"
done
# agentvfs-quickstart reads this file at runtime to write
# ~/.claude/skills/agentvfs-workspace/SKILL.md and ~/.codex/AGENTS.md.
[ -f "$WORK/agentvfs-workspace.md" ] && \
install -m 0644 "$WORK/agentvfs-workspace.md" "$PREFIX/agentvfs-workspace.md"
# Final message.
# Suggest the rc file for the most common login shell on this OS so the
# user knows where to persist the PATH addition.
if [ "$os" = darwin ]; then
default_rc="~/.zshrc"; alt_rc="~/.bashrc"
else
default_rc="~/.bashrc"; alt_rc="~/.zshrc"
fi
echo
echo "Installed agentvfs $VERSION to $PREFIX"
echo
case ":$PATH:" in
*":$PREFIX:"*)
echo "next: agentvfs-quickstart /path/to/project"
;;
*)
echo "Note: $PREFIX is not in your PATH."
echo
echo " # 1) Activate in the current shell (run this NOW):"
echo " export PATH=\"$PREFIX:\$PATH\""
echo
echo " # 2) Persist for future shells (run this ONCE):"
echo " echo 'export PATH=\"$PREFIX:\$PATH\"' >> $default_rc"
echo " # (use $alt_rc if that's your login shell)"
echo
echo "Then run: agentvfs-quickstart /path/to/project"
;;
esac