Files
pi-pm3/pi-gen/stageDangerousPi/04-dangerous-pi
michael a9acdb85ce Build optimization: pre-built PM3 binaries, ARM64 CI, base image caching
Replace PM3 compile-from-source in pi-gen with pre-built tarball extraction
(saves 43-58 min). Merge stagePM3 into stageDangerousPi as 02-pm3-install
substage, renumber all subsequent substages. Switch CI PM3 build to native
ARM64 runner (ubuntu-24.04-arm64) eliminating QEMU overhead. Add weekly
base-image workflow for pre-baking stages 0-2. Support PM3_TARBALL,
BASE_IMAGE, and APT_PROXY env vars in build-image.sh.

Also includes prior Phase 5 work: theme system, design system integration,
component update system, OS updates, CI build pipeline, and test results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 12:01:01 -08:00
..

Dangerous Pi - pi-gen Stage Integration

This directory contains the pi-gen stage scripts for installing Dangerous Pi into the custom Raspberry Pi OS image.

Files

  • 00-run.sh - Pre-chroot script that prepares application files
  • 00-run-chroot.sh - Chroot script that installs Dangerous Pi and dependencies

What Gets Installed

The stage performs the following actions:

1. Python Dependencies

Installs all required Python packages via pip:

  • FastAPI and Uvicorn (web framework and ASGI server)
  • AsyncIO libraries (aiosqlite, aiohttp)
  • Pydantic (data validation)
  • SSE-Starlette (Server-Sent Events)
  • psutil (system monitoring)
  • smbus2 (I2C communication for UPS)

2. Application Installation

  • Creates /opt/dangerous-pi directory
  • Copies application files (backend, frontend, plugins)
  • Creates data and logs directories
  • Sets proper ownership (pi:pi)

3. Configuration

  • Creates environment file from template at /opt/dangerous-pi/.env
  • Configures default settings (can be customized post-install)

4. Systemd Service

  • Installs systemd service unit
  • Enables service to start on boot
  • Configures service with security hardening

5. Hardware Access

  • Enables I2C interface in /boot/config.txt (for UPS HAT)
  • Adds pi user to hardware groups:
    • i2c - I2C bus access
    • bluetooth - Bluetooth access
    • gpio - GPIO pin access
    • dialout - Serial device access (for Proxmark3)

Build Process

During the pi-gen build:

  1. 00-run.sh executes outside the chroot:

    • Copies application files to temporary location
    • Prepares directory structure
  2. 00-run-chroot.sh executes inside the chroot:

    • Installs Python dependencies
    • Copies files to /opt/dangerous-pi
    • Configures system
    • Installs and enables systemd service

Integration with Existing pi-pm3 Stages

Dangerous Pi (stage 04) runs after:

  • Stage 01: Proxmark3 installation
  • Stage 02: RaspAP installation
  • Stage 03: ttyd installation

This order ensures all dependencies are available.

Port Conflict Handling

The ttyd-bash service (from stage 03) uses port 8000, which conflicts with Dangerous Pi's default port. See the port conflict handling task for resolution options.

Post-Build Configuration

After the image is built and booted, you can customize:

  1. Edit /opt/dangerous-pi/.env to configure settings
  2. Restart service: sudo systemctl restart dangerous-pi
  3. View status: sudo systemctl status dangerous-pi
  4. View logs: sudo journalctl -u dangerous-pi -f

Testing the Stage

To test this stage during development:

  1. Make changes to Dangerous Pi code
  2. Run pi-gen build (this stage will copy the latest code)
  3. Flash image to SD card
  4. Boot Raspberry Pi
  5. Check service status

Customization

Change Installation Directory

Edit 00-run-chroot.sh:

mkdir -p /your/custom/path
cd /your/custom/path

Also update the systemd service file paths.

Add Additional Dependencies

Edit 00-run-chroot.sh and add to the pip install command:

pip3 install --break-system-packages \
    <existing packages> \
    your-new-package==1.0.0

Skip Service Auto-Start

Comment out or remove from 00-run-chroot.sh:

# systemctl enable dangerous-pi.service

Troubleshooting

Build Fails - Python Package Error

Check that all package versions in the pip install command match requirements.txt.

Build Fails - Permission Error

Ensure scripts are executable:

chmod +x 00-run.sh 00-run-chroot.sh

Service Doesn't Start After Boot

Check systemd logs:

sudo journalctl -u dangerous-pi -b

Common issues:

  • Missing dependencies
  • Incorrect file permissions
  • Port conflict with ttyd
  • Missing environment variables

I2C Not Working

Verify I2C is enabled:

grep i2c_arm /boot/config.txt
ls -l /dev/i2c*

Can't Access Proxmark3

Verify user is in dialout group:

groups pi | grep dialout
ls -l /dev/ttyACM*

Development Workflow

  1. Make changes to Dangerous Pi code in main repository
  2. Test locally with python3 -m app.backend.main
  3. When ready to test in image:
    • Run pi-gen build (or incremental build for this stage)
    • Flash to SD card and test
  4. Iterate as needed

Version Management

The VERSION file is copied from the repository root. If it doesn't exist, version defaults to "0.1.0".

To set a specific version:

echo "1.0.0" > /path/to/dangerous-pi/VERSION

Then rebuild the image.