-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·353 lines (284 loc) · 9.56 KB
/
install.sh
File metadata and controls
executable file
·353 lines (284 loc) · 9.56 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
#!/bin/sh
# install.sh - Install csa (cli-sub-agent) and weave
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/RyderFreeman4Logos/cli-sub-agent/main/install.sh | sh
# curl -fsSL .../install.sh | sh -s -- --from-source
# curl -fsSL .../install.sh | sh -s -- --help
#
# Environment variables:
# CSA_INSTALL_DIR Override install directory (default: ~/.local/bin)
set -e
REPO_OWNER="RyderFreeman4Logos"
REPO_NAME="cli-sub-agent"
GITHUB_REPO="${REPO_OWNER}/${REPO_NAME}"
GITHUB_API="https://api.github.com/repos/${GITHUB_REPO}/releases/latest"
GITHUB_GIT="https://github.com/${GITHUB_REPO}.git"
INSTALL_DIR="${CSA_INSTALL_DIR:-${HOME}/.local/bin}"
TMPDIR_BASE="${TMPDIR:-/tmp}"
CLEANUP_DIR=""
# --- Output helpers ---
info() {
printf ' \033[1;34m==>\033[0m %s\n' "$1"
}
success() {
printf ' \033[1;32m==>\033[0m %s\n' "$1"
}
warn() {
printf ' \033[1;33mWARN:\033[0m %s\n' "$1" >&2
}
error() {
printf ' \033[1;31mERROR:\033[0m %s\n' "$1" >&2
exit 1
}
# --- Cleanup on exit ---
cleanup() {
if [ -n "${CLEANUP_DIR}" ] && [ -d "${CLEANUP_DIR}" ]; then
rm -rf "${CLEANUP_DIR}"
fi
}
trap cleanup EXIT INT TERM
# --- HTTP download abstraction ---
# download URL DEST
# Downloads URL to DEST file. Tries curl first, falls back to wget.
download() {
_url="$1"
_dest="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "${_dest}" "${_url}"
elif command -v wget >/dev/null 2>&1; then
wget -qO "${_dest}" "${_url}"
else
error "Neither curl nor wget found. Please install one and retry."
fi
}
# download_stdout URL
# Downloads URL content to stdout. Tries curl first, falls back to wget.
download_stdout() {
_url="$1"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "${_url}"
elif command -v wget >/dev/null 2>&1; then
wget -qO- "${_url}"
else
error "Neither curl nor wget found. Please install one and retry."
fi
}
# --- Help ---
usage() {
cat <<'HELP'
install.sh - Install csa (cli-sub-agent) and weave
USAGE:
sh install.sh [OPTIONS]
OPTIONS:
--from-source Compile from source instead of downloading prebuilt binaries
--help, -h Show this help message
ENVIRONMENT:
CSA_INSTALL_DIR Override install directory (default: ~/.local/bin)
MODES:
Default Download prebuilt binaries from GitHub Releases
--from-source Clone and compile with cargo (installs Rust via mise if needed)
EXAMPLES:
# Download prebuilt binary
curl -fsSL https://raw.githubusercontent.com/RyderFreeman4Logos/cli-sub-agent/main/install.sh | sh
# Compile from source
curl -fsSL https://raw.githubusercontent.com/RyderFreeman4Logos/cli-sub-agent/main/install.sh | sh -s -- --from-source
HELP
exit 0
}
# --- Detect platform ---
detect_platform() {
_os="$(uname -s)"
_arch="$(uname -m)"
case "${_os}" in
Linux) OS="linux" ;;
Darwin) OS="darwin" ;;
*) error "Unsupported OS: ${_os}. Only Linux and macOS are supported." ;;
esac
case "${_arch}" in
x86_64|amd64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
*) error "Unsupported architecture: ${_arch}. Only x86_64 and aarch64/arm64 are supported." ;;
esac
# Map to Rust target triple
case "${OS}-${ARCH}" in
linux-x86_64) TARGET="x86_64-unknown-linux-musl" ;;
linux-aarch64) TARGET="aarch64-unknown-linux-musl" ;;
darwin-x86_64) TARGET="x86_64-apple-darwin" ;;
darwin-aarch64) TARGET="aarch64-apple-darwin" ;;
*) error "Unsupported platform: ${OS}-${ARCH}" ;;
esac
info "Detected platform: ${OS} ${ARCH} (${TARGET})"
}
# --- Fetch latest release tag ---
fetch_latest_tag() {
info "Fetching latest release tag from GitHub..."
_response_file="${CLEANUP_DIR}/api_response.json"
download "${GITHUB_API}" "${_response_file}"
# Extract tag_name from JSON without jq (POSIX-compatible)
TAG=""
while IFS= read -r line; do
case "${line}" in
*'"tag_name"'*)
TAG="$(printf '%s' "${line}" | sed 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')"
break
;;
esac
done < "${_response_file}"
if [ -z "${TAG}" ]; then
error "Failed to determine latest release tag. Check network connectivity or visit https://github.com/${GITHUB_REPO}/releases"
fi
info "Latest release: ${TAG}"
}
# --- Install from prebuilt binary ---
install_binary() {
detect_platform
CLEANUP_DIR="$(mktemp -d "${TMPDIR_BASE}/csa-install.XXXXXX")"
fetch_latest_tag
ARCHIVE_NAME="csa-${TARGET}.tar.gz"
DOWNLOAD_URL="https://github.com/${GITHUB_REPO}/releases/download/${TAG}/${ARCHIVE_NAME}"
info "Downloading ${ARCHIVE_NAME}..."
download "${DOWNLOAD_URL}" "${CLEANUP_DIR}/${ARCHIVE_NAME}"
info "Extracting archive..."
tar -xzf "${CLEANUP_DIR}/${ARCHIVE_NAME}" -C "${CLEANUP_DIR}"
# Ensure install directory exists
mkdir -p "${INSTALL_DIR}"
# Install binaries
for _bin in csa weave; do
if [ -f "${CLEANUP_DIR}/${_bin}" ]; then
cp "${CLEANUP_DIR}/${_bin}" "${INSTALL_DIR}/${_bin}"
chmod +x "${INSTALL_DIR}/${_bin}"
success "Installed ${_bin} to ${INSTALL_DIR}/${_bin}"
else
warn "${_bin} binary not found in archive, skipping"
fi
done
verify_install
print_path_hint
print_next_steps
}
# --- Install from source ---
install_source() {
info "Installing from source..."
# Check for cargo
if ! command -v cargo >/dev/null 2>&1; then
info "cargo not found, attempting to install Rust via mise..."
# Check/install mise
if ! command -v mise >/dev/null 2>&1; then
info "Installing mise..."
download_stdout "https://mise.run" | sh
# Add mise to PATH for current session
if [ -f "${HOME}/.local/bin/mise" ]; then
export PATH="${HOME}/.local/bin:${PATH}"
fi
fi
if command -v mise >/dev/null 2>&1; then
info "Installing Rust toolchain via mise..."
mise use -g rust
# Add cargo bin to PATH for current session
if [ -d "${HOME}/.local/share/mise/installs/rust/latest/bin" ]; then
export PATH="${HOME}/.local/share/mise/installs/rust/latest/bin:${PATH}"
fi
fi
# Final check
if ! command -v cargo >/dev/null 2>&1; then
error "Could not install cargo automatically.
Please install Rust manually: https://rustup.rs
Then re-run this script with --from-source"
fi
fi
success "Found cargo: $(cargo --version)"
info "Compiling csa (this may take a few minutes)..."
cargo install --git "${GITHUB_GIT}" cli-sub-agent
info "Compiling weave..."
cargo install --git "${GITHUB_GIT}" weave
verify_install
print_next_steps
}
# --- Verification ---
verify_install() {
info "Verifying installation..."
_ok=true
if command -v csa >/dev/null 2>&1; then
_ver="$(csa --version 2>/dev/null || echo '(version unknown)')"
success "csa ${_ver}"
elif [ -x "${INSTALL_DIR}/csa" ]; then
success "csa installed at ${INSTALL_DIR}/csa (not yet in PATH)"
else
warn "csa binary not found"
_ok=false
fi
if command -v weave >/dev/null 2>&1; then
_ver="$(weave --version 2>/dev/null || echo '(version unknown)')"
success "weave ${_ver}"
elif [ -x "${INSTALL_DIR}/weave" ]; then
success "weave installed at ${INSTALL_DIR}/weave (not yet in PATH)"
else
warn "weave binary not found"
_ok=false
fi
if [ "${_ok}" = true ]; then
echo ""
success "Installation complete!"
else
echo ""
warn "Some binaries could not be verified. Check the output above."
fi
}
# --- PATH hint ---
print_path_hint() {
case ":${PATH}:" in
*":${INSTALL_DIR}:"*)
# Already in PATH, no hint needed
;;
*)
echo ""
warn "${INSTALL_DIR} is not in your PATH."
echo " Add it by appending one of these to your shell profile:"
echo ""
echo " # bash (~/.bashrc or ~/.bash_profile):"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo ""
echo " # zsh (~/.zshrc):"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo ""
echo " # fish (~/.config/fish/config.fish):"
echo " fish_add_path ${INSTALL_DIR}"
echo ""
echo " Then restart your shell or run:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
}
# --- Next steps ---
print_next_steps() {
echo ""
echo " Next steps:"
echo " 1. Initialize a project: csa init"
echo " 2. Check tool status: csa doctor"
echo " 3. Run your first task: csa run --sa-mode false \"hello world\""
echo ""
echo " Documentation: https://github.com/${GITHUB_REPO}"
echo ""
}
# --- Main ---
main() {
FROM_SOURCE=false
for arg in "$@"; do
case "${arg}" in
--from-source) FROM_SOURCE=true ;;
--help|-h) usage ;;
*) error "Unknown option: ${arg}. Use --help for usage." ;;
esac
done
echo ""
echo " Installing csa (cli-sub-agent)"
echo " ==============================="
echo ""
if [ "${FROM_SOURCE}" = true ]; then
install_source
else
install_binary
fi
}
main "$@"