-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
317 lines (258 loc) · 7.85 KB
/
deploy.sh
File metadata and controls
317 lines (258 loc) · 7.85 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
#!/bin/bash
# Voice Interview Assistant - Production Deployment Script
# This script sets up the application for production use
set -e # Exit on any error
echo "🚀 Voice Interview Assistant - Production Deployment"
echo "=================================================="
# Configuration
APP_NAME="voice-interview-assistant"
APP_DIR="/opt/$APP_NAME"
SERVICE_NAME="voice-assistant"
LOG_DIR="/var/log/$APP_NAME"
CONFIG_DIR="/etc/$APP_NAME"
# Check if running as root
if [[ $EUID -eq 0 ]]; then
echo "❌ This script should not be run as root for security reasons"
echo "Please run as a regular user with sudo privileges"
exit 1
fi
# Function to print status messages
print_status() {
echo "📋 $1"
}
print_success() {
echo "✅ $1"
}
print_error() {
echo "❌ $1"
}
# Check prerequisites
print_status "Checking prerequisites..."
# Check Python version
if ! command -v python3 &> /dev/null; then
print_error "Python 3 is not installed"
exit 1
fi
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2 | cut -d'.' -f1-2)
if [[ $(echo "$PYTHON_VERSION < 3.8" | bc -l) -eq 1 ]]; then
print_error "Python 3.8 or higher is required (found $PYTHON_VERSION)"
exit 1
fi
print_success "Python $PYTHON_VERSION found"
# Check if pip is available
if ! command -v pip3 &> /dev/null; then
print_error "pip3 is not installed"
exit 1
fi
# Check if Ollama is running
if ! curl -s http://localhost:11434/api/tags > /dev/null; then
print_error "Ollama is not running. Please start Ollama service first:"
echo " curl -fsSL https://ollama.ai/install.sh | sh"
echo " ollama serve"
exit 1
fi
print_success "Ollama service is running"
# Create application directory
print_status "Setting up application directory..."
sudo mkdir -p "$APP_DIR"
sudo mkdir -p "$LOG_DIR"
sudo mkdir -p "$CONFIG_DIR"
# Set proper permissions
sudo chown $USER:$USER "$APP_DIR"
sudo chown $USER:$USER "$LOG_DIR"
sudo chown $USER:$USER "$CONFIG_DIR"
print_success "Directories created"
# Copy application files
print_status "Installing application files..."
if [[ ! -f "voice_assistant.py" ]]; then
print_error "voice_assistant.py not found in current directory"
exit 1
fi
cp voice_assistant.py "$APP_DIR/"
cp requirements.txt "$APP_DIR/" 2>/dev/null || echo "# Core requirements" > "$APP_DIR/requirements.txt"
# Copy configuration template
if [[ -f "config.ini" ]]; then
cp config.ini "$CONFIG_DIR/config.ini"
else
cat > "$CONFIG_DIR/config.ini" << 'EOF'
[audio]
sample_rate = 44100
channels = 1
dtype = int16
[whisper]
model = base.en
device = auto
[ai]
api_url = http://localhost:11434/api/chat
model = llama3
timeout = 60
[ui]
window_width = 600
window_height = 80
popup_width = 800
popup_height = 600
window_alpha = 0.85
always_on_top = true
[logging]
level = INFO
file = /var/log/voice-interview-assistant/voice_assistant.log
EOF
fi
print_success "Application files installed"
# Create virtual environment
print_status "Creating virtual environment..."
cd "$APP_DIR"
python3 -m venv venv
source venv/bin/activate
# Install dependencies
print_status "Installing Python dependencies..."
pip install --upgrade pip
# Install system dependencies for audio
if command -v apt-get &> /dev/null; then
print_status "Installing system dependencies (Ubuntu/Debian)..."
sudo apt-get update
sudo apt-get install -y portaudio19-dev python3-dev build-essential
elif command -v yum &> /dev/null; then
print_status "Installing system dependencies (CentOS/RHEL)..."
sudo yum install -y portaudio-devel python3-devel gcc gcc-c++
elif command -v dnf &> /dev/null; then
print_status "Installing system dependencies (Fedora)..."
sudo dnf install -y portaudio-devel python3-devel gcc gcc-c++
fi
# Install Python packages
cat > requirements.txt << 'EOF'
numpy>=1.21.0
scipy>=1.7.0
sounddevice>=0.4.4
requests>=2.28.0
openai-whisper>=20231117
torch>=1.13.0
torchaudio>=0.13.0
EOF
pip install -r requirements.txt
print_success "Dependencies installed"
# Create systemd service (optional)
read -p "🤔 Do you want to create a systemd service? (y/N): " create_service
if [[ $create_service =~ ^[Yy]$ ]]; then
print_status "Creating systemd service..."
sudo tee "/etc/systemd/system/$SERVICE_NAME.service" > /dev/null << EOF
[Unit]
Description=Voice Interview Assistant
After=network.target
Requires=network.target
[Service]
Type=simple
User=$USER
Group=$USER
WorkingDirectory=$APP_DIR
Environment=PATH=$APP_DIR/venv/bin
Environment=DISPLAY=:0
ExecStart=$APP_DIR/venv/bin/python $APP_DIR/voice_assistant.py
ExecStartPre=/bin/sleep 10
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=$SERVICE_NAME
# Security settings
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=$LOG_DIR $CONFIG_DIR
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
print_success "Systemd service created and enabled"
echo "To start the service: sudo systemctl start $SERVICE_NAME"
echo "To check status: sudo systemctl status $SERVICE_NAME"
echo "To view logs: journalctl -u $SERVICE_NAME -f"
fi
# Create desktop entry
read -p "🤔 Do you want to create a desktop shortcut? (y/N): " create_desktop
if [[ $create_desktop =~ ^[Yy]$ ]]; then
print_status "Creating desktop entry..."
mkdir -p "$HOME/.local/share/applications"
cat > "$HOME/.local/share/applications/$APP_NAME.desktop" << EOF
[Desktop Entry]
Name=Voice Interview Assistant
Comment=AI-powered voice interview preparation tool
Exec=$APP_DIR/venv/bin/python $APP_DIR/voice_assistant.py
Icon=audio-input-microphone
Terminal=false
Type=Application
Categories=Office;AudioVideo;
StartupNotify=true
EOF
chmod +x "$HOME/.local/share/applications/$APP_NAME.desktop"
print_success "Desktop entry created"
fi
# Create launcher script
print_status "Creating launcher script..."
cat > "$APP_DIR/start.sh" << EOF
#!/bin/bash
cd "$APP_DIR"
source venv/bin/activate
export CONFIG_FILE="$CONFIG_DIR/config.ini"
python voice_assistant.py
EOF
chmod +x "$APP_DIR/start.sh"
# Create log rotation configuration
print_status "Setting up log rotation..."
sudo tee "/etc/logrotate.d/$APP_NAME" > /dev/null << EOF
$LOG_DIR/*.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 644 $USER $USER
postrotate
# Restart service if running
systemctl is-active --quiet $SERVICE_NAME && systemctl restart $SERVICE_NAME || true
endscript
}
EOF
print_success "Log rotation configured"
# Final setup
print_status "Performing final setup..."
# Create symlink for easy access
sudo ln -sf "$APP_DIR/start.sh" "/usr/local/bin/$APP_NAME" 2>/dev/null || true
# Set proper permissions
chmod 755 "$APP_DIR"
chmod 644 "$APP_DIR"/*.py
chmod 755 "$APP_DIR/start.sh"
print_success "Setup completed!"
echo ""
echo "🎉 Voice Interview Assistant has been successfully deployed!"
echo ""
echo "📁 Installation directory: $APP_DIR"
echo "📄 Configuration file: $CONFIG_DIR/config.ini"
echo "📊 Log directory: $LOG_DIR"
echo ""
echo "🚀 How to run:"
echo " 1. Direct execution: $APP_DIR/start.sh"
echo " 2. From anywhere: $APP_NAME"
if [[ $create_service =~ ^[Yy]$ ]]; then
echo " 3. As service: sudo systemctl start $SERVICE_NAME"
fi
echo ""
echo "⚙️ Configuration:"
echo " Edit $CONFIG_DIR/config.ini to customize settings"
echo ""
echo "📋 Monitoring:"
echo " Logs: tail -f $LOG_DIR/voice_assistant.log"
if [[ $create_service =~ ^[Yy]$ ]]; then
echo " Service status: sudo systemctl status $SERVICE_NAME"
echo " Service logs: journalctl -u $SERVICE_NAME -f"
fi
echo ""
echo "🔧 Before first run:"
echo " 1. Ensure Ollama is running: ollama serve"
echo " 2. Ensure llama3 model is available: ollama pull llama3"
echo " 3. Test microphone: arecord -d 3 test.wav && aplay test.wav"
echo ""
print_success "Deployment completed successfully!"