forked from Dicklesworthstone/coding_agent_session_search
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
236 lines (211 loc) · 6.91 KB
/
install.sh
File metadata and controls
236 lines (211 loc) · 6.91 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
#!/usr/bin/env bash
set -euo pipefail
umask 022
shopt -s lastpipe 2>/dev/null || true
VERSION="${VERSION:-}"
OWNER="${OWNER:-Dicklesworthstone}"
REPO="${REPO:-coding_agent_session_search}"
DEST_DEFAULT="$HOME/.local/bin"
DEST="${DEST:-$DEST_DEFAULT}"
EASY=0
QUIET=0
VERIFY=0
QUICKSTART=0
FROM_SOURCE=0
CHECKSUM="${CHECKSUM:-}"
CHECKSUM_URL="${CHECKSUM_URL:-}"
ARTIFACT_URL="${ARTIFACT_URL:-}"
LOCK_FILE="/tmp/coding-agent-search-install.$$.lock"
SYSTEM=0
log() { [ "$QUIET" -eq 1 ] && return 0; echo -e "$@"; }
info() { log "\033[0;34m→\033[0m $*"; }
ok() { log "\033[0;32m✓\033[0m $*"; }
warn() { log "\033[1;33m⚠\033[0m $*"; }
err() { log "\033[0;31m✗\033[0m $*"; }
resolve_version() {
if [ -n "$VERSION" ]; then return 0; fi
info "Resolving latest version..."
local latest_url="https://api.github.com/repos/${OWNER}/${REPO}/releases/latest"
local tag
if ! tag=$(curl -fsSL -H "Accept: application/vnd.github.v3+json" "$latest_url" 2>/dev/null | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'); then
tag=""
fi
if [ -n "$tag" ]; then
VERSION="$tag"
info "Resolved latest version: $VERSION"
else
VERSION="v0.1.0"
warn "Could not resolve latest version from GitHub API; defaulting to $VERSION"
fi
}
maybe_add_path() {
case ":$PATH:" in
*:"$DEST":*) return 0;;
*)
if [ "$EASY" -eq 1 ]; then
UPDATED=0
for rc in "$HOME/.zshrc" "$HOME/.bashrc"; do
if [ -e "$rc" ] && [ -w "$rc" ]; then
if ! grep -F "$DEST" "$rc" >/dev/null 2>&1; then
echo "export PATH=\"$DEST:\$PATH\"" >> "$rc"
fi
UPDATED=1
fi
done
if [ "$UPDATED" -eq 1 ]; then
warn "PATH updated in ~/.zshrc/.bashrc; restart shell to use coding-agent-search"
else
warn "Add $DEST to PATH to use coding-agent-search"
fi
else
warn "Add $DEST to PATH to use coding-agent-search"
fi
;;
esac
}
ensure_rust() {
if [ "${RUSTUP_INIT_SKIP:-0}" != "0" ]; then
info "Skipping rustup install (RUSTUP_INIT_SKIP set)"
return 0
fi
if command -v cargo >/dev/null 2>&1 && rustc --version 2>/dev/null | grep -q nightly; then return 0; fi
if [ "$EASY" -ne 1 ]; then
if [ -t 0 ]; then
echo -n "Install Rust nightly via rustup? (y/N): "
read -r ans
case "$ans" in y|Y) :;; *) warn "Skipping rustup install"; return 0;; esac
fi
fi
info "Installing rustup (nightly)"
curl -fsSL https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly --profile minimal
export PATH="$HOME/.cargo/bin:$PATH"
rustup component add rustfmt clippy || true
}
usage() {
cat <<EOFU
Usage: install.sh [--version vX.Y.Z] [--dest DIR] [--system] [--easy-mode] [--verify] [--quickstart] \
[--artifact-url URL] [--checksum HEX] [--checksum-url URL] [--quiet]
EOFU
}
while [ $# -gt 0 ]; do
case "$1" in
--version) VERSION="$2"; shift 2;;
--dest) DEST="$2"; shift 2;;
--system) SYSTEM=1; DEST="/usr/local/bin"; shift;;
--easy-mode) EASY=1; shift;;
--verify) VERIFY=1; shift;;
--quickstart) QUICKSTART=1; shift;;
--artifact-url) ARTIFACT_URL="$2"; shift 2;;
--checksum) CHECKSUM="$2"; shift 2;;
--checksum-url) CHECKSUM_URL="$2"; shift 2;;
--from-source) FROM_SOURCE=1; shift;;
--quiet|-q) QUIET=1; shift;;
-h|--help) usage; exit 0;;
*) shift;;
esac
done
resolve_version
mkdir -p "$DEST"
OS=$(uname -s | tr 'A-Z' 'a-z')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="aarch64" ;;
*) warn "Unknown arch $ARCH, using as-is" ;;
esac
TARGET=""
case "${OS}-${ARCH}" in
linux-x86_64) TARGET="x86_64-unknown-linux-gnu" ;;
linux-aarch64) TARGET="aarch64-unknown-linux-gnu" ;;
darwin-x86_64) TARGET="x86_64-apple-darwin" ;;
darwin-aarch64) TARGET="aarch64-apple-darwin" ;;
*) :;;
esac
# Prefer prebuilt artifact when we know the target or the caller supplied a direct URL.
TAR=""
URL=""
if [ "$FROM_SOURCE" -eq 0 ]; then
if [ -n "$ARTIFACT_URL" ]; then
TAR=$(basename "$ARTIFACT_URL")
URL="$ARTIFACT_URL"
elif [ -n "$TARGET" ]; then
TAR="coding-agent-search-${TARGET}.tar.xz"
URL="https://github.com/${OWNER}/${REPO}/releases/download/${VERSION}/${TAR}"
else
warn "No prebuilt artifact for ${OS}/${ARCH}; falling back to build-from-source"
FROM_SOURCE=1
fi
fi
exec 9>"$LOCK_FILE" || true
LOCKED=0
if flock -n 9; then LOCKED=1; else err "Another installer is running (lock $LOCK_FILE)"; exit 1; fi
cleanup() {
rm -rf "$TMP"
if [ "$LOCKED" -eq 1 ]; then rm -f "$LOCK_FILE"; fi
}
TMP=$(mktemp -d)
trap cleanup EXIT
if [ "$FROM_SOURCE" -eq 0 ]; then
info "Downloading $URL"
if ! curl -fsSL "$URL" -o "$TMP/$TAR"; then
warn "Artifact download failed; falling back to build-from-source"
FROM_SOURCE=1
fi
fi
if [ "$FROM_SOURCE" -eq 1 ]; then
info "Building from source (requires git, rust nightly)"
ensure_rust
git clone --depth 1 "https://github.com/${OWNER}/${REPO}.git" "$TMP/src"
(cd "$TMP/src" && cargo build --release)
BIN="$TMP/src/target/release/cass"
[ -x "$BIN" ] || { err "Build failed"; exit 1; }
install -m 0755 "$BIN" "$DEST"
ok "Installed to $DEST/cass (source build)"
maybe_add_path
if [ "$VERIFY" -eq 1 ]; then "$DEST/cass" --version || true; ok "Self-test complete"; fi
if [ "$QUICKSTART" -eq 1 ]; then info "Running index --full (quickstart)"; "$DEST/cass" index --full || warn "index --full failed"; fi
ok "Done. Run: cass"
exit 0
fi
if [ -z "$CHECKSUM" ]; then
[ -z "$CHECKSUM_URL" ] && CHECKSUM_URL="${URL}.sha256"
info "Fetching checksum from ${CHECKSUM_URL}"
CHECKSUM_FILE="$TMP/checksum.sha256"
if ! curl -fsSL "$CHECKSUM_URL" -o "$CHECKSUM_FILE"; then
err "Checksum required and could not be fetched"; exit 1;
fi
# Extract just the hash (first field) from the file
CHECKSUM=$(awk '{print $1}' "$CHECKSUM_FILE")
if [ -z "$CHECKSUM" ]; then err "Empty checksum file"; exit 1; fi
fi
echo "$CHECKSUM $TMP/$TAR" | sha256sum -c - || { err "Checksum mismatch"; exit 1; }
ok "Checksum verified"
info "Extracting"
tar -xf "$TMP/$TAR" -C "$TMP"
BIN="$TMP/cass"
if [ ! -x "$BIN" ] && [ -n "$TARGET" ]; then
BIN="$TMP/coding-agent-search-${TARGET}/cass"
fi
if [ ! -x "$BIN" ]; then
BIN=$(find "$TMP" -maxdepth 3 -type f -name "cass" -perm -111 | head -n 1)
fi
# Fallback for older versions or if name mismatch?
if [ ! -x "$BIN" ]; then
BIN=$(find "$TMP" -maxdepth 3 -type f -name "coding-agent-search" -perm -111 | head -n 1)
if [ -x "$BIN" ]; then
warn "Found 'coding-agent-search' binary instead of 'cass'; installing as 'cass'"
fi
fi
[ -x "$BIN" ] || { err "Binary not found in tar"; exit 1; }
install -m 0755 "$BIN" "$DEST/cass"
ok "Installed to $DEST/cass"
maybe_add_path
if [ "$VERIFY" -eq 1 ]; then
"$DEST/cass" --version || true
ok "Self-test complete"
fi
if [ "$QUICKSTART" -eq 1 ]; then
info "Running index --full (quickstart)"
"$DEST/cass" index --full || warn "index --full failed"
fi
ok "Done. Run: cass"