#!/bin/bash

# Deploy bcrypt compatibility fix to production server
# Server: 192.168.0.103

echo "Deploying bcrypt compatibility fix to production server..."

# Copy updated files to server
echo "Copying requirements.txt..."
scp requirements.txt trevor@192.168.0.103:/home/trevor/dev/chat/

echo "Copying shared/auth.py..."
scp shared/auth.py trevor@192.168.0.103:/home/trevor/dev/chat/shared/

echo "Copying user service schemas..."
scp services/user_service/schemas.py trevor@192.168.0.103:/home/trevor/dev/chat/services/user_service/

echo "Connecting to server to update dependencies..."
ssh trevor@192.168.0.103 << 'EOF'
cd /home/trevor/dev/chat

# Stop services
echo "Stopping services..."
./stop_services.sh

# Update Python packages
echo "Updating bcrypt to version 4.0.1..."
pip install --upgrade bcrypt==4.0.1
pip install --upgrade passlib[bcrypt]==1.7.4

# Verify bcrypt installation
echo "Verifying bcrypt installation..."
python3 -c "import bcrypt; print(f'bcrypt version: {bcrypt.__version__}')"

# Restart services
echo "Restarting services..."
./start_services_no_docker.sh

echo "Deployment complete. Services are starting..."
EOF

echo "Deployment script completed."
echo "Check server logs at 192.168.0.103 to verify bcrypt compatibility fix."