#!/bin/bash # PiCam First-Boot Setup Script # Run this on the Raspberry Pi after first boot to configure the IMX219 camera # and install the streaming server. set -e LOGFILE="/var/log/picam-setup.log" PROJECT_DIR="/home/pi/piCam" REPO_URL="" # Leave empty if copying files manually to the SD card exec > >(tee -a "$LOGFILE") exec 2>&1 echo "========================================" echo "PiCam First-Boot Setup Starting" echo "Date: $(date)" echo "========================================" # Update system echo "[1/6] Updating package lists..." sudo apt-get update echo "[2/6] Installing system dependencies..." sudo apt-get install -y \ python3-pip \ python3-venv \ python3-picamera2 \ libcamera-dev \ libcap-dev \ git \ i2c-tools \ v4l-utils # Ensure camera interface is enabled (legacy method, though Bookworm uses libcamera) echo "[3/6] Ensuring camera interface is enabled..." if command -v raspi-config &> /dev/null; then sudo raspi-config nonint do_camera 0 || true fi # Create project directory echo "[4/6] Setting up project directory..." mkdir -p "$PROJECT_DIR" # If files are already present (e.g., copied to SD card), use them. # Otherwise, clone or create a placeholder. if [ ! -f "$PROJECT_DIR/stream_picamera2.py" ]; then echo "Stream scripts not found in $PROJECT_DIR." echo "Please copy the project files manually:" echo " scp -r /path/to/piCam/* pi@picam.local:/home/pi/piCam/" fi # Setup Python virtual environment echo "[5/6] Creating Python virtual environment..." python3 -m venv "$PROJECT_DIR/venv" source "$PROJECT_DIR/venv/bin/activate" # Install Python dependencies echo "[6/6] Installing Python packages..." pip install --upgrade pip pip install Flask opencv-python-headless # Install systemd service for auto-start echo "Installing systemd service..." cat <