#!/bin/bash # PetBot Prerequisites Installation Script (Simple - fixes externally-managed-environment) set -e # Exit on any error echo "============================================================" echo "๐Ÿพ PetBot Prerequisites Installation (Simple Fix)" echo "============================================================" echo # Colors GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[0;33m' NC='\033[0m' print_success() { echo -e "${GREEN}โœ…${NC} $1"; } print_error() { echo -e "${RED}โŒ${NC} $1"; } print_warning() { echo -e "${YELLOW}โš ๏ธ${NC} $1"; } echo "๐Ÿ” Checking Python and venv..." # Check Python if ! command -v python3 &> /dev/null; then print_error "Python 3 is not installed" exit 1 fi python_version=$(python3 --version) print_success "Python available: $python_version" # Check venv if ! python3 -c "import venv" 2>/dev/null; then print_error "python3-venv is not available" echo "Install with: sudo apt install python3-venv" exit 1 fi print_success "venv module is available" echo echo "๐Ÿ”ง Setting up virtual environment..." # Create virtual environment if it doesn't exist if [ ! -d "venv" ]; then python3 -m venv venv print_success "Virtual environment created" else print_success "Virtual environment already exists" fi # Activate virtual environment source venv/bin/activate print_success "Virtual environment activated" echo echo "๐Ÿ“ฆ Installing packages in virtual environment..." # Upgrade pip pip install --upgrade pip # Install packages if [ -f "requirements.txt" ]; then pip install -r requirements.txt print_success "Installed from requirements.txt" else # Install individual packages pip install "irc>=20.3.0" "aiosqlite>=0.19.0" "python-dotenv>=1.0.0" print_success "Installed individual packages" fi echo echo "๐Ÿ” Verifying installation..." # Test imports python -c "import irc, aiosqlite, dotenv, asyncio, sqlite3; print('All modules imported successfully')" print_success "All required modules are available" echo echo "๐Ÿ”ง Creating directories..." # Create required directories mkdir -p data backups logs print_success "Created required directories" echo echo "๐Ÿ”ง Creating helper scripts..." # Create activation script cat > activate_petbot.sh << 'EOF' #!/bin/bash echo "๐Ÿพ Activating PetBot virtual environment..." if [ -d "venv" ]; then source venv/bin/activate echo "โœ… Virtual environment activated" echo "๐Ÿš€ You can now run:" echo " python run_bot_with_reconnect.py" echo " python test_backup_simple.py" echo " python test_reconnection.py" echo "" echo "๐Ÿ’ก To deactivate: deactivate" else echo "โŒ Virtual environment not found" fi EOF # Create run script cat > run_petbot.sh << 'EOF' #!/bin/bash if [ -d "venv" ]; then source venv/bin/activate echo "๐Ÿš€ Starting PetBot with auto-reconnect..." python run_bot_with_reconnect.py else echo "โŒ Virtual environment not found" echo "Run: ./install_prerequisites_simple.sh" fi EOF # Create debug run script cat > run_petbot_debug.sh << 'EOF' #!/bin/bash if [ -d "venv" ]; then source venv/bin/activate echo "๐Ÿš€ Starting PetBot in debug mode..." python run_bot_debug.py else echo "โŒ Virtual environment not found" echo "Run: ./install_prerequisites_simple.sh" fi EOF # Create test script cat > test_petbot.sh << 'EOF' #!/bin/bash if [ -d "venv" ]; then source venv/bin/activate echo "๐Ÿงช Running PetBot tests..." echo "1. Testing backup system..." python test_backup_simple.py echo echo "2. Testing reconnection system..." python test_reconnection.py else echo "โŒ Virtual environment not found" echo "Run: ./install_prerequisites_simple.sh" fi EOF # Make scripts executable chmod +x activate_petbot.sh run_petbot.sh run_petbot_debug.sh test_petbot.sh print_success "Created helper scripts" echo echo "๐Ÿงช Testing installation..." # Test basic imports python -c " import sys, os sys.path.append('.') from src.database import Database from src.irc_connection_manager import IRCConnectionManager from src.backup_manager import BackupManager print('โœ… All project modules imported successfully') " print_success "Installation test completed" # Deactivate for clean finish deactivate echo echo "๐ŸŽ‰ Installation completed successfully!" echo echo "๐Ÿ“‹ How to use PetBot:" echo echo "๐Ÿ”ง Method 1: Using wrapper scripts (recommended)" echo " ./run_petbot.sh # Start bot with auto-reconnect" echo " ./run_petbot_debug.sh # Start bot in debug mode" echo " ./test_petbot.sh # Run tests" echo echo "๐Ÿ”ง Method 2: Manual activation" echo " source venv/bin/activate" echo " python run_bot_with_reconnect.py" echo " deactivate # when done" echo echo "๐Ÿ”ง Method 3: Using activation helper" echo " ./activate_petbot.sh" echo " # Then run commands normally" echo echo "๐ŸŒ Web Interface:" echo " http://localhost:8080 # Access after starting bot" echo echo "โš ๏ธ Important:" echo " - Always use the wrapper scripts OR activate venv first" echo " - The virtual environment is in the 'venv' directory" echo " - This fixes the externally-managed-environment issue" echo echo "โœ… Ready to run PetBot!"