-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·528 lines (469 loc) · 15.6 KB
/
install.sh
File metadata and controls
executable file
·528 lines (469 loc) · 15.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#!/usr/bin/env bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# GitHub repository
REPO="raaymax/lazytail"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
# Parse flags
NIGHTLY=false
for arg in "$@"; do
case "$arg" in
--nightly) NIGHTLY=true ;;
esac
done
echo -e "${GREEN}LazyTail Installer${NC}"
if [ "$NIGHTLY" = true ]; then
echo -e "${YELLOW}(nightly build)${NC}"
fi
echo ""
# Detect distribution
detect_distro() {
if [ -f /etc/arch-release ]; then
echo "arch"
elif [ -f /etc/debian_version ]; then
echo "debian"
elif [ -f /etc/fedora-release ]; then
echo "fedora"
else
echo "unknown"
fi
}
# Check if binary is already installed
check_existing_install() {
if command -v lazytail &> /dev/null; then
EXISTING_PATH=$(command -v lazytail)
echo -e "${YELLOW}Found existing installation: $EXISTING_PATH${NC}"
return 0
fi
return 1
}
# Detect OS and architecture
OS="$(uname -s)"
ARCH="$(uname -m)"
DISTRO=$(detect_distro)
case "$OS" in
Linux*)
PLATFORM="linux"
;;
Darwin*)
PLATFORM="macos"
;;
*)
echo -e "${RED}Unsupported operating system: $OS${NC}"
exit 1
;;
esac
case "$ARCH" in
x86_64|amd64)
ARCH_SUFFIX="x86_64"
;;
aarch64|arm64)
ARCH_SUFFIX="aarch64"
;;
*)
echo -e "${RED}Unsupported architecture: $ARCH${NC}"
exit 1
;;
esac
# Handle Arch Linux
if [ "$DISTRO" = "arch" ]; then
echo -e "${BLUE}Arch Linux detected!${NC}"
echo ""
# Check for AUR helpers
AUR_HELPER=""
if command -v yay &> /dev/null; then
AUR_HELPER="yay"
elif command -v paru &> /dev/null; then
AUR_HELPER="paru"
fi
if [ -n "$AUR_HELPER" ]; then
echo "Recommended installation method for Arch Linux is via AUR."
echo ""
echo "Benefits of AUR installation:"
echo " • Integrated with pacman"
echo " • Automatic updates with system upgrades"
echo " • Easy removal and dependency tracking"
echo ""
if check_existing_install; then
echo -e "${YELLOW}Found existing binary installation: $EXISTING_PATH${NC}"
echo "You can remove it after AUR installation completes."
echo ""
fi
echo "Do you want to install via AUR now using $AUR_HELPER? [Y/n]"
read -r response < /dev/tty
case "$response" in
[nN][oO]|[nN])
echo "Continuing with binary install..."
echo ""
;;
*)
echo ""
echo "Running: $AUR_HELPER -S lazytail"
echo ""
$AUR_HELPER -S lazytail
if [ $? -eq 0 ]; then
echo ""
echo -e "${GREEN}✓ LazyTail installed successfully via AUR!${NC}"
if check_existing_install && [[ "$EXISTING_PATH" != "/usr/bin/lazytail" ]]; then
echo ""
echo -e "${YELLOW}Cleanup: Remove old binary installation${NC}"
echo " rm $EXISTING_PATH"
fi
exit 0
else
echo -e "${RED}AUR installation failed. Falling back to binary install...${NC}"
echo ""
fi
;;
esac
else
echo "Recommended installation method for Arch Linux is via AUR:"
echo ""
echo " Install an AUR helper first:"
echo " ${GREEN}sudo pacman -S --needed git base-devel && git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si${NC}"
echo ""
echo " Then install lazytail:"
echo " ${GREEN}yay -S lazytail${NC}"
echo ""
echo "Or continue with binary install..."
echo "Press Ctrl+C to cancel, or Enter to continue..."
read -r < /dev/tty
echo ""
fi
fi
# Check for existing installation (for non-Arch or if user chose to continue)
if check_existing_install; then
echo ""
echo "Do you want to:"
echo " 1) Update existing installation"
echo " 2) Cancel"
echo ""
echo -n "Choice [1-2]: "
read -r choice < /dev/tty
case $choice in
1)
echo "Proceeding with update..."
;;
*)
echo "Installation cancelled."
exit 0
;;
esac
echo ""
fi
# Get release version
if [ "$NIGHTLY" = true ]; then
echo "Fetching nightly build..."
LATEST_VERSION="nightly"
else
echo "Fetching latest release..."
LATEST_VERSION=$(curl -sI "https://github.com/$REPO/releases/latest" | grep -i '^location:' | sed -E 's|.*/tag/||' | tr -d '[:space:]')
if [ -z "$LATEST_VERSION" ]; then
echo -e "${RED}Failed to fetch latest version${NC}"
exit 1
fi
fi
echo "Version: $LATEST_VERSION"
# Construct download URL
BINARY_NAME="lazytail-${PLATFORM}-${ARCH_SUFFIX}.tar.gz"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_VERSION/$BINARY_NAME"
echo "Downloading from: $DOWNLOAD_URL"
# Create temporary directory
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
# Download and extract
cd "$TMP_DIR"
if ! curl -L -o "$BINARY_NAME" "$DOWNLOAD_URL"; then
echo -e "${RED}Failed to download binary${NC}"
exit 1
fi
echo "Extracting..."
tar xzf "$BINARY_NAME"
# Install binary
mkdir -p "$INSTALL_DIR"
mv lazytail "$INSTALL_DIR/lazytail"
chmod +x "$INSTALL_DIR/lazytail"
echo ""
echo -e "${GREEN}✓ LazyTail installed successfully!${NC}"
echo ""
echo "Installed to: $INSTALL_DIR/lazytail"
echo "Version: $LATEST_VERSION"
echo ""
# Check if install directory is in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo -e "${YELLOW}Warning: $INSTALL_DIR is not in your PATH${NC}"
echo ""
echo "Add this to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo ""
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
echo ""
else
echo "Run 'lazytail --help' to get started"
fi
# Reminder about updates for binary installs
echo ""
echo -e "${BLUE}Note:${NC} To update in the future, re-run this script."
if [ "$DISTRO" = "arch" ]; then
echo "Consider switching to AUR for automatic updates: ${GREEN}yay -S lazytail${NC}"
fi
# MCP Configuration Section
echo ""
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}AI Assistant Integration (MCP)${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "LazyTail can integrate with AI assistants via MCP (Model Context Protocol)."
echo "This allows AI assistants to search and analyze your log files."
echo ""
# Get the installed binary path
LAZYTAIL_BIN="$INSTALL_DIR/lazytail"
# Helper function to add JSON entry to mcpServers
add_mcp_json_config() {
local config_file="$1"
local config_dir=$(dirname "$config_file")
mkdir -p "$config_dir"
if [ -f "$config_file" ]; then
# File exists - check if lazytail already configured
if grep -q '"lazytail"' "$config_file" 2>/dev/null; then
echo -e " ${YELLOW}⚠ lazytail already configured in $config_file${NC}"
return 0
fi
# Use jq for reliable cross-platform JSON manipulation
# (avoids sed -i portability issues between macOS and Linux)
if command -v jq &> /dev/null; then
jq --arg bin "$LAZYTAIL_BIN" '.mcpServers.lazytail = {"command": $bin, "args": ["--mcp"]}' \
"$config_file" > "$config_file.tmp" && mv "$config_file.tmp" "$config_file"
else
echo -e " ${YELLOW}⚠ jq not found. Please add manually to $config_file:${NC}"
echo ' "mcpServers": { "lazytail": { "command": "'"$LAZYTAIL_BIN"'", "args": ["--mcp"] } }'
return 0
fi
else
# Create new file
cat > "$config_file" << EOF
{
"mcpServers": {
"lazytail": {
"command": "$LAZYTAIL_BIN",
"args": ["--mcp"]
}
}
}
EOF
fi
echo -e " ${GREEN}✓ Configured in $config_file${NC}"
}
# Helper function for TOML config (Codex)
add_mcp_toml_config() {
local config_file="$1"
local config_dir=$(dirname "$config_file")
mkdir -p "$config_dir"
if [ -f "$config_file" ]; then
if grep -q '\[mcp_servers\.lazytail\]' "$config_file" 2>/dev/null; then
echo -e " ${YELLOW}⚠ lazytail already configured in $config_file${NC}"
return 0
fi
# Append to existing file
echo "" >> "$config_file"
cat >> "$config_file" << EOF
[mcp_servers.lazytail]
command = ["$LAZYTAIL_BIN", "--mcp"]
EOF
else
cat > "$config_file" << EOF
[mcp_servers.lazytail]
command = ["$LAZYTAIL_BIN", "--mcp"]
EOF
fi
echo -e " ${GREEN}✓ Configured in $config_file${NC}"
}
# Detect available AI assistants
ASSISTANTS_FOUND=()
# Claude Code
if command -v claude &> /dev/null; then
ASSISTANTS_FOUND+=("claude_code")
fi
# Claude Desktop
if [ -d "$HOME/.config/Claude" ] || [ -d "$HOME/Library/Application Support/Claude" ]; then
ASSISTANTS_FOUND+=("claude_desktop")
fi
# OpenAI Codex
if command -v codex &> /dev/null || [ -d "$HOME/.codex" ]; then
ASSISTANTS_FOUND+=("codex")
fi
# Gemini CLI
if command -v gemini &> /dev/null || [ -d "$HOME/.gemini" ]; then
ASSISTANTS_FOUND+=("gemini")
fi
# Cursor
if [ -d "$HOME/.cursor" ] || command -v cursor &> /dev/null; then
ASSISTANTS_FOUND+=("cursor")
fi
# Windsurf
if [ -d "$HOME/.codeium" ] || command -v windsurf &> /dev/null; then
ASSISTANTS_FOUND+=("windsurf")
fi
# Zed
if [ -d "$HOME/.config/zed" ] || command -v zed &> /dev/null; then
ASSISTANTS_FOUND+=("zed")
fi
if [ ${#ASSISTANTS_FOUND[@]} -eq 0 ]; then
echo "No supported AI assistants detected."
echo ""
echo "To manually configure MCP later, see: https://github.com/$REPO#ai-assistant-integration-mcp"
else
echo "Detected AI assistants: ${ASSISTANTS_FOUND[*]}"
echo ""
# Claude Code
if [[ " ${ASSISTANTS_FOUND[*]} " =~ " claude_code " ]]; then
echo -e "${BLUE}Claude Code${NC}"
echo " Configure MCP for Claude Code? [Y/n]"
read -r response < /dev/tty
case "$response" in
[nN][oO]|[nN])
echo " Skipped."
;;
*)
if claude mcp add lazytail --scope user -- "$LAZYTAIL_BIN" --mcp 2>/dev/null; then
echo -e " ${GREEN}✓ Added via 'claude mcp add'${NC}"
else
echo -e " ${RED}✗ Failed to add via CLI. Try manually: claude mcp add lazytail -- $LAZYTAIL_BIN --mcp${NC}"
fi
;;
esac
echo ""
fi
# Claude Desktop
if [[ " ${ASSISTANTS_FOUND[*]} " =~ " claude_desktop " ]]; then
echo -e "${BLUE}Claude Desktop${NC}"
echo " Configure MCP for Claude Desktop? [Y/n]"
read -r response < /dev/tty
case "$response" in
[nN][oO]|[nN])
echo " Skipped."
;;
*)
if [ "$PLATFORM" = "macos" ]; then
CONFIG_FILE="$HOME/Library/Application Support/Claude/claude_desktop_config.json"
else
CONFIG_FILE="$HOME/.config/Claude/claude_desktop_config.json"
fi
add_mcp_json_config "$CONFIG_FILE"
;;
esac
echo ""
fi
# OpenAI Codex
if [[ " ${ASSISTANTS_FOUND[*]} " =~ " codex " ]]; then
echo -e "${BLUE}OpenAI Codex${NC}"
echo " Configure MCP for Codex? [Y/n]"
read -r response < /dev/tty
case "$response" in
[nN][oO]|[nN])
echo " Skipped."
;;
*)
add_mcp_toml_config "$HOME/.codex/config.toml"
;;
esac
echo ""
fi
# Gemini CLI
if [[ " ${ASSISTANTS_FOUND[*]} " =~ " gemini " ]]; then
echo -e "${BLUE}Gemini CLI${NC}"
echo " Configure MCP for Gemini CLI? [Y/n]"
read -r response < /dev/tty
case "$response" in
[nN][oO]|[nN])
echo " Skipped."
;;
*)
if command -v gemini &> /dev/null; then
if gemini mcp add lazytail -- "$LAZYTAIL_BIN" --mcp 2>/dev/null; then
echo -e " ${GREEN}✓ Added via 'gemini mcp add'${NC}"
else
add_mcp_json_config "$HOME/.gemini/settings.json"
fi
else
add_mcp_json_config "$HOME/.gemini/settings.json"
fi
;;
esac
echo ""
fi
# Cursor
if [[ " ${ASSISTANTS_FOUND[*]} " =~ " cursor " ]]; then
echo -e "${BLUE}Cursor${NC}"
echo " Configure MCP for Cursor (global)? [Y/n]"
read -r response < /dev/tty
case "$response" in
[nN][oO]|[nN])
echo " Skipped."
;;
*)
add_mcp_json_config "$HOME/.cursor/mcp.json"
;;
esac
echo ""
fi
# Windsurf
if [[ " ${ASSISTANTS_FOUND[*]} " =~ " windsurf " ]]; then
echo -e "${BLUE}Windsurf${NC}"
echo " Configure MCP for Windsurf? [Y/n]"
read -r response < /dev/tty
case "$response" in
[nN][oO]|[nN])
echo " Skipped."
;;
*)
add_mcp_json_config "$HOME/.codeium/windsurf/mcp_config.json"
;;
esac
echo ""
fi
# Zed
if [[ " ${ASSISTANTS_FOUND[*]} " =~ " zed " ]]; then
echo -e "${BLUE}Zed${NC}"
echo " Configure MCP for Zed? [Y/n]"
read -r response < /dev/tty
case "$response" in
[nN][oO]|[nN])
echo " Skipped."
;;
*)
ZED_SETTINGS="$HOME/.config/zed/settings.json"
if [ -f "$ZED_SETTINGS" ]; then
if grep -q '"lazytail"' "$ZED_SETTINGS" 2>/dev/null; then
echo -e " ${YELLOW}⚠ lazytail already configured in $ZED_SETTINGS${NC}"
else
echo -e " ${YELLOW}⚠ Zed requires manual configuration.${NC}"
echo " Add to $ZED_SETTINGS under 'context_servers':"
echo ""
echo " \"context_servers\": {"
echo " \"lazytail\": {"
echo " \"command\": { \"path\": \"$LAZYTAIL_BIN\", \"args\": [\"--mcp\"] }"
echo " }"
echo " }"
fi
else
echo -e " ${YELLOW}⚠ Zed settings not found. Add to $ZED_SETTINGS:${NC}"
echo ""
echo " \"context_servers\": {"
echo " \"lazytail\": {"
echo " \"command\": { \"path\": \"$LAZYTAIL_BIN\", \"args\": [\"--mcp\"] }"
echo " }"
echo " }"
fi
;;
esac
echo ""
fi
fi
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "Installation complete! Run 'lazytail --help' to get started."