-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·386 lines (319 loc) · 10.6 KB
/
install.sh
File metadata and controls
executable file
·386 lines (319 loc) · 10.6 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
375
376
377
378
379
380
381
382
383
384
385
386
#!/bin/bash
# Neumann CLI Installer
# Usage: curl -sSfL https://raw.githubusercontent.com/Shadylukin/Neumann/main/install.sh | bash
#
# Environment variables:
# NEUMANN_INSTALL_DIR - Installation directory (default: /usr/local/bin or ~/.local/bin)
# NEUMANN_VERSION - Specific version to install (default: latest)
# NEUMANN_NO_MODIFY_PATH - Set to 1 to skip PATH modification
# NEUMANN_SKIP_EXTRAS - Set to 1 to skip completions and man page installation
set -euo pipefail
REPO="Shadylukin/Neumann"
BINARY_NAME="neumann"
GITHUB_API="https://api.github.com"
GITHUB_RELEASES="https://github.com/${REPO}/releases"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
info() {
echo -e "${BLUE}==>${NC} $1"
}
success() {
echo -e "${GREEN}==>${NC} $1"
}
warn() {
echo -e "${YELLOW}Warning:${NC} $1"
}
error() {
echo -e "${RED}Error:${NC} $1" >&2
exit 1
}
detect_platform() {
local os arch
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$os" in
linux)
os="linux"
;;
darwin)
os="darwin"
;;
mingw*|msys*|cygwin*)
error "Windows detected. Please download from GitHub releases or use: winget install neumann"
;;
*)
error "Unsupported operating system: $os"
;;
esac
case "$arch" in
x86_64|amd64)
arch="x86_64"
;;
arm64|aarch64)
arch="aarch64"
;;
*)
error "Unsupported architecture: $arch"
;;
esac
echo "${os}-${arch}"
}
get_latest_version() {
local version
version=$(curl -sSfL "${GITHUB_API}/repos/${REPO}/releases/latest" 2>/dev/null | \
grep '"tag_name"' | \
sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')
if [ -z "$version" ]; then
return 1
fi
echo "$version"
}
download_binary() {
local version="$1"
local platform="$2"
local tmpdir="$3"
local archive_name="neumann-${version}-${platform}.tar.gz"
local url="${GITHUB_RELEASES}/download/${version}/${archive_name}"
info "Downloading ${archive_name}..."
if curl -sSfL -o "${tmpdir}/${archive_name}" "$url" 2>/dev/null; then
info "Extracting archive..."
tar -xzf "${tmpdir}/${archive_name}" -C "$tmpdir"
if [ -f "${tmpdir}/${BINARY_NAME}" ]; then
return 0
fi
fi
return 1
}
build_from_source() {
local tmpdir="$1"
info "Pre-built binary not available for this platform"
info "Building from source..."
# Check for Rust
if ! command -v cargo &>/dev/null; then
error "Cargo not found. Please install Rust from https://rustup.rs"
fi
# Check Rust version
local rust_version
rust_version=$(rustc --version | sed -E 's/rustc ([0-9]+\.[0-9]+).*/\1/')
local required="1.75"
if [ "$(printf '%s\n' "$required" "$rust_version" | sort -V | head -n1)" != "$required" ]; then
error "Rust $required or later is required (found $rust_version)"
fi
# Clone and build
info "Cloning repository..."
git clone --depth 1 "https://github.com/${REPO}.git" "${tmpdir}/neumann" || \
error "Failed to clone repository"
cd "${tmpdir}/neumann"
info "Building release binary (this may take a few minutes)..."
cargo build --release --package neumann-db || \
error "Build failed"
cp "target/release/${BINARY_NAME}" "${tmpdir}/${BINARY_NAME}"
# Copy completions if available
local completions_dir
completions_dir=$(find target/release/build -path "*neumann_shell*/out/completions" -type d 2>/dev/null | head -1)
if [ -n "$completions_dir" ] && [ -d "$completions_dir" ]; then
mkdir -p "${tmpdir}/completions"
cp "$completions_dir"/* "${tmpdir}/completions/" 2>/dev/null || true
fi
# Copy man page if available
local man_dir
man_dir=$(find target/release/build -path "*neumann_shell*/out/man" -type d 2>/dev/null | head -1)
if [ -n "$man_dir" ] && [ -d "$man_dir" ]; then
mkdir -p "${tmpdir}/man"
cp "$man_dir"/* "${tmpdir}/man/" 2>/dev/null || true
fi
}
get_install_dir() {
# Use environment variable if set
if [ -n "${NEUMANN_INSTALL_DIR:-}" ]; then
echo "$NEUMANN_INSTALL_DIR"
return
fi
# Try /usr/local/bin first (requires sudo)
if [ -w "/usr/local/bin" ]; then
echo "/usr/local/bin"
return
fi
# Fall back to ~/.local/bin
local local_bin="${HOME}/.local/bin"
mkdir -p "$local_bin"
echo "$local_bin"
}
install_binary() {
local tmpdir="$1"
local install_dir="$2"
local binary_path="${tmpdir}/${BINARY_NAME}"
if [ ! -f "$binary_path" ]; then
error "Binary not found at ${binary_path}"
fi
# Check if we need sudo
if [ ! -w "$install_dir" ]; then
info "Installing to ${install_dir} (requires sudo)..."
sudo install -m 755 "$binary_path" "${install_dir}/${BINARY_NAME}"
else
info "Installing to ${install_dir}..."
install -m 755 "$binary_path" "${install_dir}/${BINARY_NAME}"
fi
}
install_extras() {
local tmpdir="$1"
# Skip if disabled
if [ "${NEUMANN_SKIP_EXTRAS:-0}" = "1" ]; then
return
fi
# Install shell completions
if [ -d "${tmpdir}/completions" ]; then
# Bash completions
local bash_completions="/usr/local/share/bash-completion/completions"
if [ -d "$bash_completions" ] || sudo mkdir -p "$bash_completions" 2>/dev/null; then
if [ -f "${tmpdir}/completions/neumann.bash" ]; then
sudo cp "${tmpdir}/completions/neumann.bash" "$bash_completions/neumann" 2>/dev/null || true
fi
fi
# Zsh completions
local zsh_completions="/usr/local/share/zsh/site-functions"
if [ -d "$zsh_completions" ] || sudo mkdir -p "$zsh_completions" 2>/dev/null; then
if [ -f "${tmpdir}/completions/_neumann" ]; then
sudo cp "${tmpdir}/completions/_neumann" "$zsh_completions/_neumann" 2>/dev/null || true
fi
fi
# Fish completions
local fish_completions="/usr/local/share/fish/vendor_completions.d"
if [ -d "$fish_completions" ] || sudo mkdir -p "$fish_completions" 2>/dev/null; then
if [ -f "${tmpdir}/completions/neumann.fish" ]; then
sudo cp "${tmpdir}/completions/neumann.fish" "$fish_completions/neumann.fish" 2>/dev/null || true
fi
fi
info "Shell completions installed (restart shell to activate)"
fi
# Install man page
if [ -f "${tmpdir}/man/neumann.1" ]; then
local man_dir="/usr/local/share/man/man1"
if [ -d "$man_dir" ] || sudo mkdir -p "$man_dir" 2>/dev/null; then
sudo cp "${tmpdir}/man/neumann.1" "$man_dir/" 2>/dev/null && \
info "Man page installed (try: man neumann)" || true
fi
fi
}
add_to_path() {
local install_dir="$1"
# Skip if disabled
if [ "${NEUMANN_NO_MODIFY_PATH:-0}" = "1" ]; then
return
fi
# Skip if already in PATH
if echo "$PATH" | tr ':' '\n' | grep -qx "$install_dir"; then
return
fi
# Skip if it's a standard directory
if [ "$install_dir" = "/usr/local/bin" ] || [ "$install_dir" = "/usr/bin" ]; then
return
fi
local shell_config
if [ -n "${ZSH_VERSION:-}" ] || [ -f "${HOME}/.zshrc" ]; then
shell_config="${HOME}/.zshrc"
elif [ -n "${BASH_VERSION:-}" ] || [ -f "${HOME}/.bashrc" ]; then
shell_config="${HOME}/.bashrc"
else
warn "Could not determine shell config file"
warn "Please add ${install_dir} to your PATH manually"
return
fi
local path_line="export PATH=\"${install_dir}:\$PATH\""
if ! grep -qF "$install_dir" "$shell_config" 2>/dev/null; then
{
echo ""
echo "# Added by Neumann installer"
echo "$path_line"
} >> "$shell_config"
info "Added ${install_dir} to PATH in ${shell_config}"
warn "Please restart your shell or run: source ${shell_config}"
fi
}
check_existing_installation() {
if command -v "$BINARY_NAME" &>/dev/null; then
local current_version
current_version=$("$BINARY_NAME" --version 2>/dev/null | head -n1 || echo "unknown")
info "Found existing installation: ${current_version}"
fi
}
main() {
echo ""
echo " Neumann CLI Installer"
echo " ====================="
echo ""
# Detect platform
local platform
platform=$(detect_platform)
info "Detected platform: ${platform}"
# Map platform to target triple
local target
case "$platform" in
linux-x86_64)
target="x86_64-unknown-linux-gnu"
;;
darwin-x86_64)
target="x86_64-apple-darwin"
;;
darwin-aarch64)
target="aarch64-apple-darwin"
;;
*)
error "Unknown platform: ${platform}"
;;
esac
# Check for existing installation
check_existing_installation
# Get version to install
local version="${NEUMANN_VERSION:-}"
if [ -z "$version" ]; then
info "Fetching latest version..."
version=$(get_latest_version) || true
fi
# Create temporary directory
local tmpdir
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
# Try to download pre-built binary
local binary_available=false
if [ -n "$version" ]; then
info "Installing version: ${version}"
if download_binary "$version" "$target" "$tmpdir"; then
binary_available=true
fi
fi
# Fall back to building from source
if [ "$binary_available" = false ]; then
build_from_source "$tmpdir"
fi
# Install
local install_dir
install_dir=$(get_install_dir)
install_binary "$tmpdir" "$install_dir"
# Install extras (completions, man page)
install_extras "$tmpdir"
# Update PATH if needed
add_to_path "$install_dir"
# Verify installation
echo ""
success "Neumann CLI installed successfully!"
echo ""
if [ -x "${install_dir}/${BINARY_NAME}" ]; then
info "Installed to: ${install_dir}/${BINARY_NAME}"
info "Version: $("${install_dir}/${BINARY_NAME}" --version 2>/dev/null || echo 'unknown')"
fi
echo ""
echo " Get started:"
echo " neumann # Start interactive shell"
echo " neumann --help # Show help"
echo " neumann -c 'query' # Execute single query"
echo ""
echo " Documentation:"
echo " https://github.com/${REPO}"
echo ""
}
main "$@"