#!/usr/bin/env bash # Hive AI Tutor - Raspberry Pi Installation Script set -e echo "🐝 Hive AI Tutor - Raspberry Pi Installation" echo "===========================================" # Check if running on Raspberry Pi if ! grep -q "Raspberry Pi" /proc/cpuinfo 2>/dev/null; then echo "⚠️ Warning: This doesn't appear to be a Raspberry Pi" read -p "Continue anyway? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi # Check disk space DISK_FREE=$(df . | tail -1 | awk '{print $4}') if [ "$DISK_FREE" -lt 16000000 ]; then echo "❌ Error: Less than 16GB free disk space available" echo " Please free up some space and try again" exit 1 fi # Install system dependencies echo "📦 Installing system dependencies..." sudo apt-get update sudo apt-get install -y python3-pip python3-venv python3-dev \ libportaudio2 libportaudiocpp0 portaudio19-dev \ ffmpeg libsndfile1 # Create hive user (optional, comment out to use current user) # echo "👤 Creating hive user..." # sudo useradd -r -s /bin/bash -d /home/hive -m hive || true # Set installation directory INSTALL_DIR="$HOME/hive" DATA_DIR="$HOME/hive_data" echo "📁 Creating directories..." mkdir -p "$INSTALL_DIR" mkdir -p "$DATA_DIR" # Copy files echo "📋 Copying application files..." cp app.py "$INSTALL_DIR/" cp requirements.txt "$INSTALL_DIR/" # Create virtual environment echo "🐍 Creating virtual environment..." cd "$INSTALL_DIR" python3 -m venv hive_env # Activate virtual environment source hive_env/bin/activate # Upgrade pip echo "⬆️ Upgrading pip..." pip install --upgrade pip # Install Python dependencies (this will take a while) echo "📦 Installing Python dependencies (this may take 10-30 minutes)..." pip install -r requirements.txt # Create systemd service echo "⚙️ Setting up systemd service..." SERVICE_FILE="/etc/systemd/system/hive.service" # Substitute current user in service file sed "s/User=pi/User=$USER/g; s/Group=pi/Group=$USER/g; s|/home/pi/|$HOME/|g" hive.service | sudo tee "$SERVICE_FILE" > /dev/null # Reload systemd sudo systemctl daemon-reload # Enable service sudo systemctl enable hive.service echo "" echo "✅ Installation complete!" echo "" echo "To start Hive:" echo " sudo systemctl start hive.service" echo "" echo "To check status:" echo " sudo systemctl status hive.service" echo "" echo "To view logs:" echo " journalctl -u hive.service -f" echo "" echo "To access the UI:" echo " Open browser to http://localhost:7860" echo " Or http://$(hostname -I | awk '{print $1}'):7860 from another device" echo "" echo "Data directory: $DATA_DIR" echo "Installation directory: $INSTALL_DIR" echo ""