#!/bin/bash # Production deployment script for Talk2Me set -e # Exit on error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Configuration APP_NAME="talk2me" APP_USER="talk2me" APP_DIR="/opt/talk2me" VENV_DIR="$APP_DIR/venv" LOG_DIR="/var/log/talk2me" PID_FILE="/var/run/talk2me.pid" WORKERS=${WORKERS:-4} # Functions print_status() { echo -e "${GREEN}[INFO]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } # Check if running as root if [[ $EUID -ne 0 ]]; then print_error "This script must be run as root" exit 1 fi # Create application user if doesn't exist if ! id "$APP_USER" &>/dev/null; then print_status "Creating application user: $APP_USER" useradd -m -s /bin/bash $APP_USER fi # Create directories print_status "Creating application directories" mkdir -p $APP_DIR $LOG_DIR chown -R $APP_USER:$APP_USER $APP_DIR $LOG_DIR # Copy application files print_status "Copying application files" rsync -av --exclude='venv' --exclude='__pycache__' --exclude='*.pyc' \ --exclude='logs' --exclude='.git' --exclude='node_modules' \ ./ $APP_DIR/ # Create virtual environment print_status "Setting up Python virtual environment" su - $APP_USER -c "cd $APP_DIR && python3 -m venv $VENV_DIR" # Install dependencies print_status "Installing Python dependencies" su - $APP_USER -c "cd $APP_DIR && $VENV_DIR/bin/pip install --upgrade pip" su - $APP_USER -c "cd $APP_DIR && $VENV_DIR/bin/pip install -r requirements-prod.txt" # Install Whisper model print_status "Downloading Whisper model (this may take a while)" su - $APP_USER -c "cd $APP_DIR && $VENV_DIR/bin/python -c 'import whisper; whisper.load_model(\"base\")'" # Build frontend assets if [ -f "package.json" ]; then print_status "Building frontend assets" cd $APP_DIR npm install npm run build fi # Create systemd service print_status "Creating systemd service" cat > /etc/systemd/system/talk2me.service < /etc/nginx/sites-available/talk2me <