-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·525 lines (460 loc) · 15.6 KB
/
install.sh
File metadata and controls
executable file
·525 lines (460 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
#!/bin/bash
# Agent Second Brain — One-command installer
# Works on Mac and Windows WSL
# https://github.com/smixs/agent-second-brain
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Config
REPO_URL="https://github.com/smixs/agent-second-brain.git"
INSTALL_DIR="$HOME/agent-second-brain"
#######################################
# Print colored message
#######################################
info() { echo -e "${BLUE}ℹ${NC} $1"; }
success() { echo -e "${GREEN}✓${NC} $1"; }
warn() { echo -e "${YELLOW}⚠${NC} $1"; }
error() { echo -e "${RED}✗${NC} $1"; exit 1; }
#######################################
# Detect OS
#######################################
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="mac"
info "Detected: macOS"
elif grep -q Microsoft /proc/version 2>/dev/null; then
OS="wsl"
info "Detected: Windows WSL"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
info "Detected: Linux"
else
error "Unsupported OS. This script works on Mac and Windows WSL only."
fi
}
#######################################
# Check if command exists
#######################################
has_command() {
command -v "$1" &> /dev/null
}
#######################################
# Install Homebrew (Mac only)
#######################################
install_homebrew() {
if [[ "$OS" != "mac" ]]; then return; fi
if has_command brew; then
success "Homebrew already installed"
else
info "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add to PATH for current session
if [[ -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ -f /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
success "Homebrew installed"
fi
}
#######################################
# Install dependencies
#######################################
install_dependencies() {
info "Installing dependencies..."
if [[ "$OS" == "mac" ]]; then
# Node.js
if ! has_command node; then
info "Installing Node.js..."
brew install node
fi
success "Node.js $(node --version)"
# Python 3.12
if ! has_command python3.12; then
info "Installing Python 3.12..."
brew install python@3.12
fi
success "Python $(python3.12 --version)"
# Git
if ! has_command git; then
info "Installing Git..."
brew install git
fi
success "Git $(git --version | head -1)"
elif [[ "$OS" == "wsl" ]] || [[ "$OS" == "linux" ]]; then
info "Updating apt packages..."
sudo apt update && sudo apt upgrade -y
# Node.js 20
if ! has_command node; then
info "Installing Node.js..."
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
fi
success "Node.js $(node --version)"
# Python 3.12
if ! has_command python3.12; then
info "Installing Python 3.12..."
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.12 python3.12-venv python3.12-dev
fi
success "Python $(python3.12 --version)"
# Git
if ! has_command git; then
info "Installing Git..."
sudo apt install -y git curl wget
fi
success "Git $(git --version | head -1)"
fi
}
#######################################
# Install uv (Python package manager)
#######################################
install_uv() {
if has_command uv; then
success "uv already installed: $(uv --version)"
else
info "Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add to PATH for current session
export PATH="$HOME/.local/bin:$PATH"
success "uv installed: $(uv --version)"
fi
}
#######################################
# Install Claude Code CLI
#######################################
install_claude() {
if has_command claude; then
success "Claude Code already installed: $(claude --version)"
else
info "Installing Claude Code CLI..."
npm install -g @anthropic-ai/claude-code
success "Claude Code installed"
fi
}
#######################################
# Clone repository
#######################################
clone_repo() {
if [[ -d "$INSTALL_DIR" ]]; then
warn "Directory $INSTALL_DIR already exists"
read -p "Overwrite? (y/n): " -n 1 -r < /dev/tty
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$INSTALL_DIR"
else
error "Installation cancelled"
fi
fi
info "Cloning repository..."
git clone "$REPO_URL" "$INSTALL_DIR"
success "Repository cloned to $INSTALL_DIR"
}
#######################################
# Prompt for token
#######################################
prompt_token() {
local name="$1"
local desc="$2"
local url="$3"
local var_name="$4"
local optional="${5:-false}"
echo
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}$name${NC}"
echo "$desc"
echo -e "Get it here: ${GREEN}$url${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
if [[ "$optional" == "true" ]]; then
read -p "Enter token (or press Enter to skip): " token < /dev/tty
else
while true; do
read -p "Enter token: " token < /dev/tty
if [[ -n "$token" ]]; then
break
fi
warn "This token is required"
done
fi
eval "$var_name=\"$token\""
}
#######################################
# Collect tokens interactively
#######################################
collect_tokens() {
echo
echo -e "${GREEN}╔════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ TOKEN CONFIGURATION ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════╝${NC}"
echo
echo "You'll need to provide 4 tokens. Instructions for each below."
# Telegram Bot Token
prompt_token \
"1/4: Telegram Bot Token" \
"Create a bot via @BotFather in Telegram:
1. Open Telegram and search for @BotFather
2. Send /newbot
3. Follow instructions to create your bot
4. Copy the token (looks like: 7123456789:AAHd...)" \
"https://t.me/BotFather" \
"TELEGRAM_BOT_TOKEN"
# Telegram User ID
prompt_token \
"2/4: Your Telegram User ID" \
"Get your ID via @userinfobot:
1. Search for @userinfobot in Telegram
2. Send any message
3. Copy your ID (just the number)" \
"https://t.me/userinfobot" \
"TELEGRAM_USER_ID"
# Deepgram API Key
prompt_token \
"3/4: Deepgram API Key" \
"For voice transcription (free \$200 credit):
1. Sign up at console.deepgram.com
2. Go to Settings → API Keys
3. Create new key and copy it" \
"https://console.deepgram.com/" \
"DEEPGRAM_API_KEY"
# Todoist API Token (optional)
prompt_token \
"4/4: Todoist API Token (optional)" \
"For task management:
1. Log in to todoist.com
2. Settings → Integrations → Developer
3. Copy the API token" \
"https://todoist.com/app/settings/integrations/developer" \
"TODOIST_API_KEY" \
"true"
}
#######################################
# Create .env file
#######################################
create_env() {
info "Creating .env file..."
cat > "$INSTALL_DIR/.env" << EOF
# Telegram Bot Token (from @BotFather)
TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN
# Deepgram API Key (from console.deepgram.com)
DEEPGRAM_API_KEY=$DEEPGRAM_API_KEY
# Todoist API Token (optional)
TODOIST_API_KEY=$TODOIST_API_KEY
# Path to vault (don't change)
VAULT_PATH=./vault
# Your Telegram ID (bot responds only to you)
ALLOWED_USER_IDS=[$TELEGRAM_USER_ID]
EOF
success ".env file created"
}
#######################################
# Install Python dependencies
#######################################
install_python_deps() {
info "Installing Python dependencies..."
cd "$INSTALL_DIR"
uv sync
success "Python dependencies installed"
}
#######################################
# Install mcp-cli
#######################################
install_mcp_cli() {
if has_command mcp-cli; then
success "mcp-cli already installed"
else
info "Installing mcp-cli..."
curl -fsSL https://raw.githubusercontent.com/philschmid/mcp-cli/main/install.sh | bash
export PATH="$HOME/.local/bin:$PATH"
success "mcp-cli installed"
fi
# Configure mcp-cli for Todoist if token provided
if [[ -n "$TODOIST_API_KEY" ]]; then
info "Configuring mcp-cli for Todoist..."
mkdir -p ~/.config/mcp
cat > ~/.config/mcp/mcp_servers.json << EOF
{
"mcpServers": {
"todoist": {
"command": "npx",
"args": ["-y", "@doist/todoist-ai"],
"env": {
"TODOIST_API_KEY": "$TODOIST_API_KEY"
}
}
}
}
EOF
success "mcp-cli configured"
fi
}
#######################################
# Authenticate Claude
#######################################
auth_claude() {
echo
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}Claude Authentication${NC}"
echo "You need Claude Pro subscription (\$20/month) for this to work."
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo
if claude auth status &>/dev/null; then
success "Claude already authenticated"
else
info "Starting Claude authentication..."
echo "A browser window will open. Log in with your Anthropic account."
echo
claude auth login
success "Claude authenticated"
fi
}
#######################################
# Setup autostart (optional)
#######################################
setup_autostart() {
echo
read -p "Configure autostart (bot runs when computer starts)? (y/n): " -n 1 -r < /dev/tty
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
info "Skipping autostart configuration"
return
fi
if [[ "$OS" == "mac" ]]; then
setup_launchd
else
setup_systemd
fi
}
#######################################
# Setup launchd (Mac)
#######################################
setup_launchd() {
info "Configuring launchd..."
mkdir -p ~/Library/LaunchAgents
cat > ~/Library/LaunchAgents/com.agent-second-brain.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.agent-second-brain</string>
<key>ProgramArguments</key>
<array>
<string>$HOME/.local/bin/uv</string>
<string>run</string>
<string>python</string>
<string>-m</string>
<string>d_brain</string>
</array>
<key>WorkingDirectory</key>
<string>$INSTALL_DIR</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>$INSTALL_DIR/logs/bot.log</string>
<key>StandardErrorPath</key>
<string>$INSTALL_DIR/logs/bot-error.log</string>
</dict>
</plist>
EOF
mkdir -p "$INSTALL_DIR/logs"
launchctl load ~/Library/LaunchAgents/com.agent-second-brain.plist
success "Autostart configured (launchd)"
info "Bot will start automatically on login"
}
#######################################
# Setup systemd (Linux/WSL)
#######################################
setup_systemd() {
info "Configuring systemd..."
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/agent-second-brain.service << EOF
[Unit]
Description=Agent Second Brain Telegram Bot
After=network.target
[Service]
Type=simple
WorkingDirectory=$INSTALL_DIR
ExecStart=$HOME/.local/bin/uv run python -m d_brain
Restart=always
RestartSec=10
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable agent-second-brain
systemctl --user start agent-second-brain
success "Autostart configured (systemd)"
info "Bot is running now and will start on boot"
}
#######################################
# Start bot manually
#######################################
start_bot() {
echo
echo -e "${GREEN}╔════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ INSTALLATION COMPLETE! ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════╝${NC}"
echo
if [[ "$OS" == "mac" ]] && [[ -f ~/Library/LaunchAgents/com.agent-second-brain.plist ]]; then
echo "Bot is running in background."
echo
echo "Commands:"
echo " Stop: launchctl unload ~/Library/LaunchAgents/com.agent-second-brain.plist"
echo " Start: launchctl load ~/Library/LaunchAgents/com.agent-second-brain.plist"
echo " Logs: tail -f $INSTALL_DIR/logs/bot.log"
elif systemctl --user is-active --quiet agent-second-brain 2>/dev/null; then
echo "Bot is running in background."
echo
echo "Commands:"
echo " Stop: systemctl --user stop agent-second-brain"
echo " Start: systemctl --user start agent-second-brain"
echo " Logs: journalctl --user -u agent-second-brain -f"
else
echo "To start the bot manually:"
echo
echo -e " ${GREEN}cd $INSTALL_DIR && uv run python -m d_brain${NC}"
echo
read -p "Start bot now? (y/n): " -n 1 -r < /dev/tty
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
cd "$INSTALL_DIR"
info "Starting bot... (Ctrl+C to stop)"
uv run python -m d_brain
fi
fi
}
#######################################
# Main
#######################################
main() {
echo
echo -e "${GREEN}╔════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ AGENT SECOND BRAIN INSTALLER ║${NC}"
echo -e "${GREEN}║ ║${NC}"
echo -e "${GREEN}║ Voice-first AI assistant with memory ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════╝${NC}"
echo
detect_os
install_homebrew
install_dependencies
install_uv
install_claude
clone_repo
collect_tokens
create_env
install_python_deps
install_mcp_cli
auth_claude
setup_autostart
start_bot
}
main "$@"