-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·287 lines (241 loc) · 7.75 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·287 lines (241 loc) · 7.75 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
#!/bin/bash
# O2FileSearchPlus Enhanced Setup Script
# This script sets up both backend and frontend components
set -e # Exit on any error
echo "🚀 O2FileSearchPlus Enhanced Setup"
echo "=================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Detect operating system
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
print_warning "macOS detected. Homebrew will be used for missing dependencies."
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
else
OS="other"
print_warning "This script is primarily tested on Linux and macOS."
fi
# Check for required commands
check_command() {
local cmd="$1"
local brew_pkg="${2:-$cmd}"
if ! command -v "$cmd" &> /dev/null; then
if [[ "$OS" == "macos" ]]; then
if command -v brew &> /dev/null; then
print_warning "$cmd not found. Installing $brew_pkg via Homebrew..."
brew install "$brew_pkg"
else
print_error "$cmd is required but Homebrew is not installed."
echo "Install Homebrew from https://brew.sh/ and rerun this script."
exit 1
fi
else
print_error "$cmd is not installed. Please install it first."
exit 1
fi
fi
}
# Check for python-magic / libmagic
check_python_magic() {
python3 - <<'EOF' >/dev/null 2>&1
import magic
EOF
if [[ $? -ne 0 ]]; then
if [[ "$OS" == "macos" ]]; then
if command -v brew &> /dev/null; then
print_warning "python-magic not found. Installing libmagic via Homebrew..."
brew install libmagic
pip3 install python-magic
else
print_error "python-magic is required but Homebrew is not installed."
echo "Install Homebrew from https://brew.sh/ and install libmagic and python-magic manually."
exit 1
fi
else
print_error "python-magic is not installed. Run 'pip install python-magic' and ensure libmagic is available."
exit 1
fi
fi
}
print_status "Checking prerequisites..."
# Ensure commands exist (install via Homebrew on macOS if missing)
check_command python3 python
check_command node node
check_command npm npm
check_python_magic
# Check Python version
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2 | cut -d'.' -f1,2)
PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d'.' -f1)
PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d'.' -f2)
if [ "$PYTHON_MAJOR" -lt 3 ] || ([ "$PYTHON_MAJOR" -eq 3 ] && [ "$PYTHON_MINOR" -lt 8 ]); then
print_error "Python 3.8+ is required. Found: $(python3 --version)"
exit 1
fi
print_success "Python $(python3 --version | cut -d' ' -f2) found"
# Check Node.js version
NODE_VERSION=$(node --version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 18 ]; then
print_error "Node.js 18+ is required. Found: $(node --version)"
exit 1
fi
print_success "Node.js $(node --version) found"
# Check npm
print_success "npm $(npm --version) found"
# Setup Backend
print_status "Setting up backend..."
cd backend
# Create virtual environment if it doesn't exist
if [ ! -d "venv" ]; then
print_status "Creating Python virtual environment..."
python3 -m venv venv
print_success "Virtual environment created"
else
print_status "Virtual environment already exists"
fi
# Activate virtual environment
print_status "Activating virtual environment..."
source venv/bin/activate
# Upgrade pip
print_status "Upgrading pip..."
pip install --upgrade pip
# Install Python dependencies
print_status "Installing Python dependencies..."
pip install -r requirements.txt
print_success "Backend dependencies installed"
# Test backend import
print_status "Testing backend setup..."
python -c "import fastapi, uvicorn, chardet; print('Backend dependencies OK')" || {
print_error "Backend dependency test failed"
exit 1
}
print_success "Backend setup complete"
# Go back to root directory
cd ..
# Setup Frontend
print_status "Setting up frontend..."
cd frontend
# Install Node.js dependencies
print_status "Installing Node.js dependencies..."
npm install
print_success "Frontend dependencies installed"
# Test frontend build
print_status "Testing frontend build..."
npm run build || {
print_error "Frontend build test failed"
exit 1
}
print_success "Frontend setup complete"
# Go back to root directory
cd ..
# Create startup scripts
print_status "Creating startup scripts..."
# Backend startup script
cat > start_backend.sh << 'EOF'
#!/bin/bash
cd backend
source venv/bin/activate
echo "Starting O2FileSearchPlus Backend on http://localhost:8000"
echo "API Documentation available at http://localhost:8000/docs"
python main.py
EOF
# Frontend startup script
cat > start_frontend.sh << 'EOF'
#!/bin/bash
cd frontend
echo "Starting O2FileSearchPlus Frontend on http://localhost:3000"
npm run dev
EOF
# Combined startup script
cat > start_all.sh << 'EOF'
#!/bin/bash
# Start both backend and frontend in separate terminals
echo "Starting O2FileSearchPlus Enhanced..."
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Try to open in separate terminals
if command_exists gnome-terminal; then
gnome-terminal --tab --title="Backend" -- bash -c "./start_backend.sh; exec bash"
gnome-terminal --tab --title="Frontend" -- bash -c "./start_frontend.sh; exec bash"
elif command_exists xterm; then
xterm -title "Backend" -e "./start_backend.sh" &
xterm -title "Frontend" -e "./start_frontend.sh" &
elif command_exists konsole; then
konsole --new-tab -e "./start_backend.sh" &
konsole --new-tab -e "./start_frontend.sh" &
else
echo "No suitable terminal emulator found."
echo "Please run the following commands in separate terminals:"
echo "1. ./start_backend.sh"
echo "2. ./start_frontend.sh"
fi
echo "Backend will be available at: http://localhost:8000"
echo "Frontend will be available at: http://localhost:3000"
echo "API Documentation at: http://localhost:8000/docs"
EOF
# Make scripts executable
chmod +x start_backend.sh start_frontend.sh start_all.sh
print_success "Startup scripts created"
# Create systemd service file template
print_status "Creating systemd service template..."
cat > o2filesearch.service << EOF
[Unit]
Description=O2FileSearchPlus Enhanced Backend
After=network.target
[Service]
Type=simple
User=$USER
WorkingDirectory=$(pwd)/backend
Environment=PATH=$(pwd)/backend/venv/bin
ExecStart=$(pwd)/backend/venv/bin/python main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
print_success "Systemd service template created"
# Final instructions
echo ""
echo "🎉 Setup Complete!"
echo "=================="
echo ""
echo "Quick Start:"
echo "1. Run: ./start_all.sh"
echo "2. Open http://localhost:3000 in your browser"
echo "3. Go to Index tab and start indexing your files"
echo ""
echo "Manual Start:"
echo "1. Backend: ./start_backend.sh"
echo "2. Frontend: ./start_frontend.sh"
echo ""
echo "Production Deployment:"
echo "1. Copy o2filesearch.service to /etc/systemd/system/"
echo "2. Run: sudo systemctl enable o2filesearch"
echo "3. Run: sudo systemctl start o2filesearch"
echo "4. Build frontend: cd frontend && npm run build && npm start"
echo ""
echo "Troubleshooting:"
echo "- Check logs in backend/o2filesearch.log"
echo "- Ensure ports 3000 and 8000 are available"
echo "- Verify file permissions for indexing directories"
echo ""
print_success "Ready to use O2FileSearchPlus Enhanced!"