#!/bin/bash # PetBot Prerequisites Installation Script (Shell Version) # This script installs all required packages and sets up the environment set -e # Exit on any error echo "============================================================" echo "๐Ÿพ PetBot Prerequisites Installation Script (Shell Version)" echo "============================================================" echo # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${GREEN}โœ…${NC} $1" } print_error() { echo -e "${RED}โŒ${NC} $1" } print_warning() { echo -e "${YELLOW}โš ๏ธ${NC} $1" } print_info() { echo -e "${BLUE}โ„น๏ธ${NC} $1" } # Check if we're in the right directory echo "๐Ÿ” Checking directory structure..." if [ ! -f "requirements.txt" ] || [ ! -f "src/database.py" ] || [ ! -f "webserver.py" ]; then print_error "Required files not found. Please run this script from the PetBot project directory." exit 1 fi print_status "Directory structure is correct" # Check Python version echo echo "๐Ÿ” Checking Python version..." python_version=$(python3 --version 2>&1) if [ $? -ne 0 ]; then print_error "Python 3 is not installed or not in PATH" print_info "Please install Python 3.7+ and try again" exit 1 fi # Extract version numbers version_string=$(echo "$python_version" | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') major=$(echo "$version_string" | cut -d'.' -f1) minor=$(echo "$version_string" | cut -d'.' -f2) if [ "$major" -lt 3 ] || ([ "$major" -eq 3 ] && [ "$minor" -lt 7 ]); then print_error "Python 3.7+ required. Current version: $python_version" exit 1 fi print_status "Python version is compatible: $python_version" # Check pip availability echo echo "๐Ÿ” Checking pip availability..." if ! command -v pip3 &> /dev/null; then if ! python3 -m pip --version &> /dev/null; then print_error "pip is not available" print_info "Install pip with:" print_info " Ubuntu/Debian: sudo apt install python3-pip" print_info " CentOS/RHEL: sudo yum install python3-pip" print_info " macOS: brew install python3" exit 1 fi PIP_CMD="python3 -m pip" else PIP_CMD="pip3" fi pip_version=$($PIP_CMD --version) print_status "pip is available: $pip_version" # Create required directories echo echo "๐Ÿ” Creating required directories..." if [ ! -d "data" ]; then mkdir -p data print_status "Created data directory" else print_status "Data directory already exists" fi if [ ! -d "backups" ]; then mkdir -p backups print_status "Created backups directory" else print_status "Backups directory already exists" fi if [ ! -d "logs" ]; then mkdir -p logs print_status "Created logs directory" else print_status "Logs directory already exists" fi # Install packages from requirements.txt echo echo "๐Ÿ“ฆ Installing packages from requirements.txt..." if $PIP_CMD install -r requirements.txt; then print_status "Successfully installed packages from requirements.txt" else print_error "Failed to install from requirements.txt" echo echo "๐Ÿ“ฆ Trying individual package installation..." # Try individual packages packages=( "irc>=20.3.0" "aiosqlite>=0.19.0" "python-dotenv>=1.0.0" ) failed_packages=() for package in "${packages[@]}"; do echo "Installing $package..." if $PIP_CMD install "$package"; then print_status "Successfully installed $package" else print_error "Failed to install $package" failed_packages+=("$package") fi done if [ ${#failed_packages[@]} -gt 0 ]; then print_error "Failed to install the following packages:" for package in "${failed_packages[@]}"; do echo " - $package" done exit 1 fi fi # Verify installation echo echo "๐Ÿ” Verifying installation..." # List of modules to test modules=( "irc:IRC client library" "aiosqlite:Async SQLite database" "dotenv:Environment variable loading" "asyncio:Async programming (built-in)" "sqlite3:SQLite database (built-in)" "json:JSON handling (built-in)" "socket:Network communication (built-in)" "threading:Threading (built-in)" ) failed_imports=() for module_info in "${modules[@]}"; do module=$(echo "$module_info" | cut -d':' -f1) description=$(echo "$module_info" | cut -d':' -f2) if python3 -c "import $module" 2>/dev/null; then print_status "$module: $description" else print_error "$module: $description - Import failed" failed_imports+=("$module") fi done if [ ${#failed_imports[@]} -gt 0 ]; then print_error "Some modules failed to import:" for module in "${failed_imports[@]}"; do echo " - $module" done exit 1 fi # Test basic project imports echo echo "๐Ÿงช Testing project imports..." if python3 -c " import sys import os sys.path.append(os.path.dirname(os.path.abspath('.'))) from src.database import Database from src.irc_connection_manager import IRCConnectionManager from src.backup_manager import BackupManager print('All project imports successful') " 2>/dev/null; then print_status "Project imports successful" else print_error "Project imports failed" print_info "This might be due to missing dependencies or path issues" exit 1 fi # Check for optional system dependencies echo echo "๐Ÿ” Checking optional system dependencies..." if command -v git &> /dev/null; then print_status "Git is available" else print_warning "Git is not available (optional for development)" fi if command -v curl &> /dev/null; then print_status "curl is available" else print_warning "curl is not available (optional for testing)" fi # Make scripts executable echo echo "๐Ÿ”ง Making scripts executable..." chmod +x install_prerequisites.py chmod +x run_bot_debug.py chmod +x run_bot_with_reconnect.py chmod +x test_backup_simple.py chmod +x test_reconnection.py print_status "Made scripts executable" # Show summary echo echo "๐ŸŽ‰ Installation completed successfully!" echo echo "๐Ÿ“‹ Next steps:" echo "1. Review and update configuration files in the config/ directory" echo "2. Test the bot with: python3 run_bot_debug.py" echo "3. Or use the new reconnection system: python3 run_bot_with_reconnect.py" echo "4. Check the web interface at: http://localhost:8080" echo "5. Review CLAUDE.md for development guidelines" echo echo "๐Ÿ”ง Available test commands:" echo " python3 test_backup_simple.py - Test backup system" echo " python3 test_reconnection.py - Test IRC reconnection" echo echo "๐Ÿ“š Documentation:" echo " README.md - Project overview" echo " CLAUDE.md - Development guide" echo " TODO.md - Current status" echo " issues.txt - Security audit findings" echo " BACKUP_SYSTEM_INTEGRATION.md - Backup system guide" echo echo "๐Ÿš€ You're ready to run PetBot!" echo "โœ… All prerequisites have been installed successfully!"