🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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 files00-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-pidirectory - 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
piuser to hardware groups:i2c- I2C bus accessbluetooth- Bluetooth accessgpio- GPIO pin accessdialout- Serial device access (for Proxmark3)
Build Process
During the pi-gen build:
-
00-run.shexecutes outside the chroot:- Copies application files to temporary location
- Prepares directory structure
-
00-run-chroot.shexecutes 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:
- Edit
/opt/dangerous-pi/.envto configure settings - Restart service:
sudo systemctl restart dangerous-pi - View status:
sudo systemctl status dangerous-pi - View logs:
sudo journalctl -u dangerous-pi -f
Testing the Stage
To test this stage during development:
- Make changes to Dangerous Pi code
- Run pi-gen build (this stage will copy the latest code)
- Flash image to SD card
- Boot Raspberry Pi
- 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
- Make changes to Dangerous Pi code in main repository
- Test locally with
python3 -m app.backend.main - When ready to test in image:
- Run pi-gen build (or incremental build for this stage)
- Flash to SD card and test
- 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.