-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·506 lines (418 loc) · 12.6 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·506 lines (418 loc) · 12.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
#!/bin/bash
# Flow Setup Script
# Comprehensive setup for the Flow screen history and search system
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
log_success() {
echo -e "${GREEN}✅ $1${NC}"
}
log_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
log_error() {
echo -e "${RED}❌ $1${NC}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Detect operating system
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "linux"
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
echo "windows"
else
echo "unknown"
fi
}
# Install system dependencies
install_system_deps() {
local os=$(detect_os)
log_info "Installing system dependencies for $os..."
case $os in
"macos")
if ! command_exists brew; then
log_error "Homebrew not found. Please install Homebrew first:"
log_info "Run: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
exit 1
fi
log_info "Installing Tesseract OCR..."
brew install tesseract
log_info "Installing PortAudio (for audio features)..."
brew install portaudio
;;
"linux")
if command_exists apt-get; then
log_info "Installing dependencies via apt..."
sudo apt-get update
sudo apt-get install -y tesseract-ocr tesseract-ocr-eng python3-dev python3-venv portaudio19-dev
elif command_exists yum; then
log_info "Installing dependencies via yum..."
sudo yum install -y tesseract python3-devel python3-venv portaudio-devel
elif command_exists pacman; then
log_info "Installing dependencies via pacman..."
sudo pacman -S tesseract python python-virtualenv portaudio
else
log_error "Unsupported Linux distribution. Please install tesseract and python3-venv manually."
exit 1
fi
;;
"windows")
log_warning "Windows detected. Please ensure you have:"
log_info "1. Python 3.10+ installed from python.org"
log_info "2. Tesseract OCR installed from GitHub releases"
log_info "3. Git installed from git-scm.com"
read -p "Press Enter to continue once dependencies are installed..."
;;
*)
log_error "Unsupported operating system: $OSTYPE"
exit 1
;;
esac
}
# Check Python version
check_python() {
log_info "Checking Python version..."
if command_exists python3; then
local version=$(python3 --version 2>&1 | cut -d' ' -f2)
local major=$(echo $version | cut -d'.' -f1)
local minor=$(echo $version | cut -d'.' -f2)
if [[ $major -eq 3 ]] && [[ $minor -ge 10 ]]; then
log_success "Python $version found"
return 0
else
log_error "Python 3.10+ required, found $version"
return 1
fi
else
log_error "Python 3 not found"
return 1
fi
}
# Setup virtual environment for a component
setup_venv() {
local component=$1
local requirements_file=$2
log_info "Setting up virtual environment for $component..."
cd "$component"
# Remove existing venv if it exists
if [[ -d ".venv" ]]; then
log_warning "Removing existing virtual environment..."
rm -rf .venv
fi
# Create new virtual environment
python3 -m venv .venv
# Activate virtual environment
source .venv/bin/activate
# Upgrade pip
pip install --upgrade pip
# Install requirements
if [[ -f "$requirements_file" ]]; then
log_info "Installing $component dependencies..."
pip install -r "$requirements_file"
else
log_warning "No requirements file found for $component"
fi
# Deactivate virtual environment
deactivate
cd ..
log_success "$component virtual environment setup complete"
}
# Create configuration files
create_config() {
log_info "Creating configuration files..."
# Create .env file
if [[ ! -f ".env" ]]; then
cat > .env << EOF
# ChromaDB Configuration
CHROMA_HOST=localhost
CHROMA_PORT=8000
# Dashboard Configuration
DASHBOARD_HOST=0.0.0.0
DASHBOARD_PORT=8080
# Screen Capture Configuration
CAPTURE_INTERVAL=60
MAX_CONCURRENT_OCR=4
# Logging Configuration
LOG_LEVEL=INFO
# Audio Configuration (optional)
AUDIO_ENABLED=false
AUDIO_DEVICE_INDEX=0
EOF
log_success "Created .env configuration file"
else
log_info ".env file already exists, skipping..."
fi
# Create refinery config
if [[ ! -f "refinery/config.json" ]]; then
cat > refinery/config.json << EOF
{
"capture_interval": 60,
"max_concurrent_ocr": 4,
"auto_start": false,
"data_retention_days": 90,
"compress_old_data": true,
"screens": {
"enabled": true,
"naming_convention": "screen_{index}"
},
"ocr": {
"language": "eng",
"confidence_threshold": 30
}
}
EOF
log_success "Created refinery configuration file"
else
log_info "Refinery config already exists, skipping..."
fi
}
# Create startup scripts
create_startup_scripts() {
log_info "Creating startup scripts..."
# Create start-all script
cat > start-all.sh << 'EOF'
#!/bin/bash
# Flow System Startup Script
# Starts all Flow components in the correct order
set -e
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
log_success() {
echo -e "${GREEN}✅ $1${NC}"
}
# Function to check if port is in use
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null; then
return 0 # Port is in use
else
return 1 # Port is free
fi
}
# Function to start component in background
start_component() {
local name=$1
local command=$2
local logfile=$3
log_info "Starting $name..."
nohup bash -c "$command" > "$logfile" 2>&1 &
echo $! > "${name}.pid"
sleep 2
if kill -0 $(cat "${name}.pid") 2>/dev/null; then
log_success "$name started successfully (PID: $(cat "${name}.pid"))"
else
echo "❌ Failed to start $name"
return 1
fi
}
log_info "Starting Flow System..."
# Check if ChromaDB port is available
if check_port 8000; then
log_info "Port 8000 is already in use (ChromaDB may already be running)"
else
# Start ChromaDB
start_component "chromadb" \
"cd refinery && source .venv/bin/activate && chroma run --host localhost --port 8000" \
"logs/chromadb.log"
fi
# Wait for ChromaDB to be ready
log_info "Waiting for ChromaDB to be ready..."
for i in {1..30}; do
if curl -s http://localhost:8000/api/v1/heartbeat >/dev/null 2>&1; then
log_success "ChromaDB is ready"
break
fi
sleep 1
if [[ $i -eq 30 ]]; then
echo "❌ ChromaDB failed to start within 30 seconds"
exit 1
fi
done
# Start Screen Capture
start_component "screen-capture" \
"cd refinery && source .venv/bin/activate && python run.py" \
"logs/screen-capture.log"
# Start Dashboard
start_component "dashboard" \
"cd dashboard && source .venv/bin/activate && python app.py" \
"logs/dashboard.log"
# Start MCP Server
start_component "mcp-server" \
"cd mcp-server && source .venv/bin/activate && python server.py" \
"logs/mcp-server.log"
log_success "All Flow components started successfully!"
echo ""
echo "🌐 Dashboard: http://localhost:8080"
echo "🔍 ChromaDB: http://localhost:8000"
echo ""
echo "📋 To stop all components, run: ./stop-all.sh"
echo "📊 To view logs, check the logs/ directory"
EOF
# Create stop-all script
cat > stop-all.sh << 'EOF'
#!/bin/bash
# Flow System Shutdown Script
# Stops all Flow components gracefully
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
log_success() {
echo -e "${GREEN}✅ $1${NC}"
}
log_error() {
echo -e "${RED}❌ $1${NC}"
}
# Function to stop component
stop_component() {
local name=$1
local pidfile="${name}.pid"
if [[ -f "$pidfile" ]]; then
local pid=$(cat "$pidfile")
if kill -0 "$pid" 2>/dev/null; then
log_info "Stopping $name (PID: $pid)..."
kill "$pid"
# Wait for process to stop
for i in {1..10}; do
if ! kill -0 "$pid" 2>/dev/null; then
log_success "$name stopped"
rm "$pidfile"
return 0
fi
sleep 1
done
# Force kill if still running
log_info "Force stopping $name..."
kill -9 "$pid" 2>/dev/null || true
rm "$pidfile"
log_success "$name force stopped"
else
log_info "$name was not running"
rm "$pidfile"
fi
else
log_info "No PID file found for $name"
fi
}
log_info "Stopping Flow System..."
# Stop components in reverse order
stop_component "mcp-server"
stop_component "dashboard"
stop_component "screen-capture"
stop_component "chromadb"
# Kill any remaining Flow processes
log_info "Cleaning up any remaining processes..."
pkill -f "python.*flow" 2>/dev/null || true
pkill -f "chroma run" 2>/dev/null || true
log_success "Flow system stopped"
EOF
# Create logs directory
mkdir -p logs
# Make scripts executable
chmod +x start-all.sh stop-all.sh
log_success "Startup scripts created"
}
# Verify installation
verify_installation() {
log_info "Verifying installation..."
local errors=0
# Check Python environments
for component in refinery dashboard mcp-server; do
if [[ -d "$component/.venv" ]]; then
log_success "$component virtual environment exists"
else
log_error "$component virtual environment missing"
((errors++))
fi
done
# Check Tesseract
if command_exists tesseract; then
local version=$(tesseract --version 2>&1 | head -1)
log_success "Tesseract found: $version"
else
log_error "Tesseract not found"
((errors++))
fi
# Check configuration files
if [[ -f ".env" ]]; then
log_success "Configuration file (.env) exists"
else
log_error "Configuration file (.env) missing"
((errors++))
fi
if [[ $errors -eq 0 ]]; then
log_success "Installation verification passed!"
return 0
else
log_error "Installation verification failed with $errors errors"
return 1
fi
}
# Main setup function
main() {
echo "🚀 Flow Setup Script"
echo "===================="
echo ""
# Check if we're in the Flow directory
if [[ ! -f "README.md" ]] || [[ ! -d "refinery" ]]; then
log_error "Please run this script from the Flow project root directory"
exit 1
fi
# Install system dependencies
install_system_deps
# Check Python
if ! check_python; then
log_error "Please install Python 3.10+ and try again"
exit 1
fi
# Setup virtual environments
setup_venv "refinery" "flow-requirements.txt"
setup_venv "dashboard" "requirements.txt"
setup_venv "mcp-server" "requirements.txt"
# Create configuration files
create_config
# Create startup scripts
create_startup_scripts
# Verify installation
if verify_installation; then
echo ""
log_success "Flow setup completed successfully! 🎉"
echo ""
echo "📋 Next steps:"
echo "1. Start the system: ./start-all.sh"
echo "2. Open dashboard: http://localhost:8080"
echo "3. Configure Claude Desktop (see README.md)"
echo ""
echo "📖 For detailed instructions, see:"
echo " - INSTALLATION.md - Complete installation guide"
echo " - TROUBLESHOOTING.md - Common issues and solutions"
echo " - README.md - Project overview and usage"
else
log_error "Setup completed with errors. Please check the output above."
exit 1
fi
}
# Run main function
main "$@"