forked from mrveiss/AutoBot-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
556 lines (475 loc) · 18.6 KB
/
setup.sh
File metadata and controls
556 lines (475 loc) · 18.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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
#!/bin/bash
# AutoBot - Distributed VM Setup Script
# Handles initial setup for distributed VM architecture
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/infrastructure/shared/scripts/lib/ssot-config.sh" 2>/dev/null || true
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
print_usage() {
echo -e "${GREEN}AutoBot - Distributed VM Setup Script${NC}"
echo "Configures AutoBot for distributed VM deployment across multiple machines"
echo ""
echo -e "${CYAN}TIP: For interactive setup, run: ./scripts/setup_wizard.sh${NC}"
echo ""
echo "Usage: $0 [setup_type] [options]"
echo ""
echo -e "${YELLOW}Setup Types:${NC}"
echo " initial Complete distributed setup (default)"
echo " distributed Same as initial - full distributed VM setup"
echo " backend-only Setup only backend dependencies (WSL main machine)"
echo " agent Agent and environment setup only"
echo " ssh-keys Generate and distribute SSH keys for VM connectivity"
echo " vm-services Install services on individual VMs"
echo " knowledge Knowledge base setup and population"
echo " desktop VNC desktop environment setup for headless servers"
echo " repair Repair existing installation"
echo ""
echo -e "${YELLOW}Environment Options:${NC}"
echo " --distributed Setup for distributed VM deployment (default)"
echo " --backend-only Setup only backend on main machine"
echo " --development Development mode - Vite dev servers, hot reload, debugging"
echo " --production Production mode - nginx, systemd services, optimized builds"
echo ""
echo -e "${YELLOW}General Options:${NC}"
echo " --force Force setup even if already configured"
echo " --skip-deps Skip dependency installation"
echo " --help Show this help"
echo ""
echo -e "${BLUE}Distributed Architecture:${NC}"
echo " Main (WSL): ${AUTOBOT_BACKEND_HOST:-172.16.168.20} - Backend API server"
echo " VM1 Frontend: ${AUTOBOT_FRONTEND_HOST:-172.16.168.21} - Vue.js web interface (Native Vite)"
echo " VM2 NPU Worker: ${AUTOBOT_NPU_WORKER_HOST:-172.16.168.22} - Hardware AI acceleration"
echo " VM3 Redis: ${AUTOBOT_REDIS_HOST:-172.16.168.23} - Database and caching"
echo " VM4 AI Stack: ${AUTOBOT_AI_STACK_HOST:-172.16.168.24} - AI processing services"
echo " VM5 Browser: ${AUTOBOT_BROWSER_SERVICE_HOST:-172.16.168.25} - Web automation (Playwright)"
echo ""
echo -e "${CYAN}Examples:${NC}"
echo " $0 initial # Complete distributed setup"
echo " $0 distributed --development # Development mode setup"
echo " $0 backend-only --production # Backend only production setup"
echo " $0 ssh-keys # Generate SSH keys for VMs"
echo " $0 knowledge # Setup knowledge base"
echo ""
exit 0
}
# Logging functions
log() {
echo -e "${CYAN}[INFO]${NC} $1"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
# Check if we're running in the correct directory
check_autobot_directory() {
if [ ! -f "config/config.yaml.template" ] || [ ! -d "autobot-user-backend" ] || [ ! -d "autobot-slm-frontend" ]; then
error "Please run this script from the AutoBot root directory"
error "Required: config/config.yaml.template, autobot-user-backend/, autobot-slm-frontend/"
exit 1
fi
}
# Detect OS and distribution
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if grep -qi microsoft /proc/version 2>/dev/null; then
OS="wsl"
DISTRO=$(lsb_release -si 2>/dev/null || echo "Unknown")
else
OS="linux"
DISTRO=$(lsb_release -si 2>/dev/null || echo "Unknown")
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
DISTRO="macOS"
else
OS="unknown"
DISTRO="Unknown"
fi
log "Detected OS: $OS ($DISTRO)"
}
# Check system requirements
check_requirements() {
log "Checking system requirements..."
# Check Python
if ! command -v python3 &> /dev/null; then
error "Python 3 is not installed. Please install Python 3.8 or later."
exit 1
fi
# Check Node.js for frontend builds
if ! command -v node &> /dev/null; then
warn "Node.js not found. Frontend builds may not work."
warn "Please install Node.js 16+ for frontend development."
fi
# Check available memory and disk space
if command -v free &> /dev/null; then
MEMORY_MB=$(free -m | awk 'NR==2{print $2}')
if [ "$MEMORY_MB" -lt 4096 ]; then
warn "System has less than 4GB RAM. Performance may be affected."
fi
fi
success "System requirements check completed"
}
# Setup Python virtual environment and dependencies
setup_python_environment() {
log "Setting up Python environment..."
# Create virtual environment if it doesn't exist or if forced
if [ ! -d "venv" ] || [ "$FORCE_SETUP" = true ]; then
log "Creating Python virtual environment..."
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
# Install Python dependencies from config/requirements.txt
if [ -f "config/requirements.txt" ]; then
log "Installing AutoBot Python dependencies..."
pip install -r config/requirements.txt
elif [ -f "requirements.txt" ]; then
log "Installing dependencies from requirements.txt..."
pip install -r requirements.txt
else
log "Installing core AutoBot dependencies..."
# Install critical dependencies if no requirements file found
pip install fastapi>=0.115.0 uvicorn>=0.30.0 python-multipart>=0.0.9
pip install aiohttp==3.12.15 aiofiles>=23.0.0 websockets>=11.0.0
pip install redis>=5.0 chromadb>=0.4.0
pip install transformers>=4.55.2 sentence-transformers>=2.2.0
pip install llama-index llama-index-llms-ollama llama-index-embeddings-ollama
pip install playwright>=1.40.0 selenium>=4.15.0
fi
# Install voice processing dependencies (optional)
if [ -f "config/requirements-voice.txt" ]; then
log "Installing voice processing dependencies..."
# Install voice dependencies with fallback handling
pip install speechrecognition==3.10.0 pydub==0.25.1 gtts==2.3.1 pyttsx3 || warn "Some voice dependencies failed to install - voice features may be limited"
fi
success "Python environment configured"
else
log "Python virtual environment already exists"
fi
# Setup Node.js dependencies for frontend (if present)
if [ -d "autobot-slm-frontend" ] && command -v npm &> /dev/null; then
log "Setting up Node.js dependencies for Vue frontend..."
cd autobot-slm-frontend
if [ ! -d "node_modules" ] || [ "$FORCE_SETUP" = true ]; then
npm install
success "Node.js dependencies installed"
else
log "Node.js dependencies already installed"
fi
cd ..
fi
}
# Generate SSH keys for VM connectivity
generate_ssh_keys() {
log "Generating SSH keys for VM connectivity..."
SSH_KEY_PATH="$HOME/.ssh/autobot_key"
if [ ! -f "$SSH_KEY_PATH" ] || [ "$FORCE_SETUP" = true ]; then
log "Creating SSH key pair..."
ssh-keygen -t rsa -b 4096 -f "$SSH_KEY_PATH" -N "" -C "autobot-vm-access"
chmod 600 "$SSH_KEY_PATH"
chmod 644 "$SSH_KEY_PATH.pub"
success "SSH keys generated: $SSH_KEY_PATH"
# Display public key for VM setup
echo -e "\n${YELLOW}Public key for VM setup:${NC}"
cat "$SSH_KEY_PATH.pub"
echo ""
echo -e "${CYAN}Copy this public key to ~/.ssh/authorized_keys on all VMs${NC}"
else
log "SSH keys already exist"
success "Using existing SSH keys: $SSH_KEY_PATH"
fi
}
# Setup configuration files
setup_configuration() {
log "Setting up configuration files..."
# Create config.yaml from template if it doesn't exist
if [ ! -f "config/config.yaml" ]; then
log "Creating config.yaml from template..."
cp config/config.yaml.template config/config.yaml
# Enable voice interface by default
if command -v sed &> /dev/null; then
sed -i 's/enabled: false/enabled: true/' config/config.yaml || warn "Could not enable voice interface in config"
fi
success "Configuration file created"
else
log "Configuration file already exists"
fi
# Create required directories
log "Creating required directories..."
mkdir -p data/chats data/knowledge data/outputs logs temp reports analysis models
mkdir -p logs/ai-ml analysis/ai-ml data/outputs/ai-ml data/outputs/multimodal
# Setup .env file for environment variables
if [ ! -f ".env" ]; then
log "Creating .env file..."
cat > .env << EOF
# AutoBot Environment Configuration
NODE_ENV=development
BACKEND_URL=http://${AUTOBOT_BACKEND_HOST:-172.16.168.20}:${AUTOBOT_BACKEND_PORT:-8001}
FRONTEND_URL=http://${AUTOBOT_FRONTEND_HOST:-172.16.168.21}:${AUTOBOT_FRONTEND_PORT:-5173}
REDIS_URL=redis://${AUTOBOT_REDIS_HOST:-172.16.168.23}:${AUTOBOT_REDIS_PORT:-6379}
NPU_WORKER_URL=http://${AUTOBOT_NPU_WORKER_HOST:-172.16.168.22}:${AUTOBOT_NPU_WORKER_PORT:-8081}
AI_STACK_URL=http://${AUTOBOT_AI_STACK_HOST:-172.16.168.24}:${AUTOBOT_AI_STACK_PORT:-8080}
BROWSER_VM_URL=http://${AUTOBOT_BROWSER_SERVICE_HOST:-172.16.168.25}:${AUTOBOT_BROWSER_SERVICE_PORT:-3000}
# Security
SECRET_KEY=your-secret-key-here
# Voice Interface
VOICE_ENABLED=true
# User Management Mode (Issue #576)
# Available: single_user (default), single_company, multi_company, provider
# - single_user: No auth, personal use
# - single_company: Auth enabled, teams, PostgreSQL required
# - multi_company: Multi-tenant, PostgreSQL required
# - provider: SaaS with billing, PostgreSQL required
AUTOBOT_USER_MODE=single_user
EOF
success ".env file created"
else
log ".env file already exists"
fi
}
# Setup NPU Worker (VM2)
setup_npu_worker() {
log "Setting up NPU Worker environment..."
# Create NPU-specific requirements and install
if command -v pip &> /dev/null; then
log "Installing NPU dependencies..."
# Activate virtual environment if it exists
[ -f "venv/bin/activate" ] && source venv/bin/activate
pip install --upgrade pip
# Install NPU-specific dependencies
pip install torch>=2.0.0 transformers>=4.55.2 sentence-transformers>=2.2.0
pip install openvino>=2023.0.0 openvino-dev
pip install fastapi uvicorn aiohttp requests pyyaml
pip install psutil numpy opencv-python pillow
success "NPU Worker dependencies installed"
else
warn "pip not available, skipping NPU dependency installation"
fi
# Setup NPU model directory
mkdir -p models/npu models/onnx models/openvino
log "NPU Worker setup completed"
}
# Setup AI Stack (VM4)
setup_ai_stack() {
log "Setting up AI Stack environment..."
if command -v pip &> /dev/null; then
log "Installing AI/ML dependencies..."
[ -f "venv/bin/activate" ] && source venv/bin/activate
pip install --upgrade pip
# Install AI/ML dependencies from AutoBot requirements
pip install fastapi>=0.115.0 uvicorn>=0.30.0 aiohttp==3.12.15
pip install openai>=1.0.0 anthropic>=0.7.0 tiktoken>=0.5.0
pip install transformers>=4.55.2 sentence-transformers>=2.2.0
pip install torch>=2.0.0 torchvision>=0.15.0 torchaudio>=2.0.0
pip install chromadb>=0.4.0 redis>=5.0
pip install llama-index llama-index-llms-ollama llama-index-embeddings-ollama
pip install langchain langchain-community langchain-experimental
success "AI Stack dependencies installed"
else
warn "pip not available, skipping AI dependency installation"
fi
# Setup AI model directories
mkdir -p models/llm models/embeddings models/vision
log "AI Stack setup completed"
}
# Setup Browser VM (VM5)
setup_browser_vm() {
log "Setting up Browser VM environment..."
if command -v pip &> /dev/null; then
log "Installing browser automation dependencies..."
[ -f "venv/bin/activate" ] && source venv/bin/activate
pip install --upgrade pip
# Install browser automation dependencies
pip install playwright>=1.40.0 selenium>=4.15.0
pip install fastapi>=0.115.0 uvicorn>=0.30.0
pip install httpx>=0.25.0 requests>=2.32.4
pip install beautifulsoup4>=4.12.0 newspaper3k>=0.2.8
# Install Playwright browsers
if command -v playwright &> /dev/null; then
log "Installing Playwright browsers..."
playwright install --with-deps
fi
success "Browser VM dependencies installed"
else
warn "pip not available, skipping browser dependency installation"
fi
log "Browser VM setup completed"
}
# Setup VNC Desktop environment
setup_desktop() {
log "Setting up VNC desktop environment..."
if [ "$OS" = "linux" ] || [ "$OS" = "wsl" ]; then
# Create VNC startup script
cat > scripts/start_vnc.sh << 'EOF'
#!/bin/bash
# Start VNC server for AutoBot desktop access
# Kill any existing VNC servers
vncserver -kill :1 2>/dev/null || true
# Start new VNC server
vncserver :1 -geometry 1920x1080 -depth 24
echo "VNC server started on :1 (port 5901)"
echo "Connect using VNC viewer to: localhost:5901"
EOF
chmod +x scripts/start_vnc.sh
success "VNC desktop setup completed"
else
log "VNC desktop setup skipped (not applicable for this OS)"
fi
}
# Setup knowledge base
setup_knowledge_base() {
log "Setting up knowledge base..."
# Create knowledge base directories
mkdir -p data/knowledge_base/documents data/knowledge_base/embeddings
mkdir -p data/chromadb
# Initialize knowledge base if Python is available
if [ -f "venv/bin/activate" ]; then
source venv/bin/activate
if [ -f "scripts/populate_kb_chromadb.py" ]; then
log "Initializing knowledge base with sample data..."
python scripts/populate_kb_chromadb.py || warn "Knowledge base initialization failed"
fi
fi
success "Knowledge base setup completed"
}
# Repair existing installation
repair_installation() {
log "Repairing AutoBot installation..."
# Re-run key setup steps with force
FORCE_SETUP=true
setup_python_environment
setup_configuration
# Reinstall requirements
if [ -f "venv/bin/activate" ]; then
source venv/bin/activate
if [ -f "config/requirements.txt" ]; then
pip install -r config/requirements.txt --force-reinstall
fi
if [ -f "config/requirements-voice.txt" ]; then
pip install speechrecognition==3.10.0 pydub==0.25.1 gtts==2.3.1 pyttsx3 --force-reinstall || warn "Voice dependencies repair incomplete"
fi
fi
success "Installation repair completed"
}
# Main setup orchestration
main() {
echo -e "${GREEN}============================================${NC}"
echo -e "${GREEN} AutoBot Distributed Setup ${NC}"
echo -e "${GREEN}============================================${NC}"
echo ""
# Parse command line arguments
SETUP_TYPE="initial"
FORCE_SETUP=false
SKIP_DEPS=false
DEVELOPMENT_MODE=false
PRODUCTION_MODE=false
while [[ $# -gt 0 ]]; do
case $1 in
initial|distributed|backend-only|agent|ssh-keys|vm-services|knowledge|desktop|repair)
SETUP_TYPE="$1"
shift
;;
--force)
FORCE_SETUP=true
shift
;;
--skip-deps)
SKIP_DEPS=true
shift
;;
--development)
DEVELOPMENT_MODE=true
shift
;;
--production)
PRODUCTION_MODE=true
shift
;;
--help|-h)
print_usage
;;
*)
error "Unknown option: $1"
print_usage
;;
esac
done
# Initial checks
check_autobot_directory
detect_os
check_requirements
# Execute setup based on type
case $SETUP_TYPE in
initial|distributed)
log "Starting complete distributed setup..."
setup_python_environment
generate_ssh_keys
setup_configuration
setup_knowledge_base
success "Complete distributed setup finished"
;;
backend-only)
log "Starting backend-only setup..."
setup_python_environment
setup_configuration
success "Backend-only setup finished"
;;
agent)
log "Starting agent environment setup..."
setup_python_environment
setup_configuration
success "Agent setup finished"
;;
ssh-keys)
generate_ssh_keys
;;
vm-services)
log "Setting up VM-specific services..."
setup_npu_worker
setup_ai_stack
setup_browser_vm
success "VM services setup finished"
;;
knowledge)
setup_knowledge_base
;;
desktop)
setup_desktop
;;
repair)
repair_installation
;;
*)
error "Unknown setup type: $SETUP_TYPE"
print_usage
;;
esac
echo ""
echo -e "${GREEN}============================================${NC}"
echo -e "${GREEN} Setup Complete! ${NC}"
echo -e "${GREEN}============================================${NC}"
echo ""
echo -e "${CYAN}Next steps:${NC}"
echo "1. Configure your LLM API keys in config/config.yaml"
echo "2. Start AutoBot with: bash run_autobot.sh --dev"
echo "3. Access the web interface at: http://${AUTOBOT_FRONTEND_HOST:-172.16.168.21}:${AUTOBOT_FRONTEND_PORT:-5173}"
echo "4. Access the desktop via VNC at: http://127.0.0.1:6080/vnc.html"
echo ""
echo -e "${YELLOW}For voice features:${NC}"
echo "- Microphone access may require additional system setup"
echo "- Voice interface is enabled by default in config"
echo "- Test voice features in the web interface settings"
echo ""
}
# Run main function
main "$@"