# Quick Build Reference

TL;DR for building your Dangerous Pi image.

## Prerequisites

```bash
# 1. Install Docker
brew install docker  # macOS
# OR
sudo apt-get install docker.io  # Linux

# 2. Clone pi-gen
git clone https://github.com/RPi-Distro/pi-gen.git
cd pi-gen
git checkout arm64
```

## Build Commands

### First Time (Full Build)

```bash
# Copy your stage to pi-gen
cp -r /path/to/dangerous-pi/pi-gen/stageDTPM3 /path/to/pi-gen/
cp /path/to/dangerous-pi/pi-gen/config /path/to/pi-gen/config

# Build
cd /path/to/pi-gen
sudo ./build.sh

# OR with Docker (recommended)
./docker-build.sh
```

⏱️ **Time**: 1-2 hours
📦 **Output**: `deploy/image_2025-11-26-Proxmark3.img`

### Quick Iteration (After Code Changes)

```bash
cd /path/to/pi-gen

# Copy updated code
cp -r /path/to/dangerous-pi/pi-gen/stageDTPM3 .

# Rebuild only your stage
CONTINUE=1 STAGE=stageDTPM3 sudo ./build.sh
```

⏱️ **Time**: 5-10 minutes
💡 **Use**: Testing Dangerous Pi changes only

## Flash & Test

### Flash Image

```bash
# Using Balena Etcher (easiest)
# https://etcher.balena.io/

# OR using dd
sudo dd if=deploy/image.img of=/dev/sdX bs=4M status=progress
```

### Connect & Test

1. **Boot Pi** with SD card
2. **Connect to WiFi**:
   - SSID: `raspi-webgui`
   - Password: `ChangeMe`
3. **Run tests**:
   ```bash
   ./test-image.sh 10.3.141.1
   ```

### Verify Manually

```bash
# SSH
ssh dt@10.3.141.1  # password: proxmark3

# Check service
sudo systemctl status dangerous-pi.service

# Test API
curl http://10.3.141.1:8000/api/health
```

## What Was Built

Your image includes:

- ✅ **Stage 01**: Proxmark3 firmware & client
- ✅ **Stage 02**: RaspAP (WiFi access point)
- ✅ **Stage 03**: ttyd (web terminal)
- ✅ **Stage 04**: Dangerous Pi backend at `/opt/dangerous-pi`

## Key Config Values

From [pi-gen/config](pi-gen/config):

```bash
IMG_NAME="Proxmark3"
TARGET_HOSTNAME="Proxmark3"
FIRST_USER_NAME="dt"
FIRST_USER_PASS="proxmark3"
```

## Troubleshooting

**Build fails?**
```bash
# Check disk space
df -h  # Need 20GB+

# Clean and retry
sudo rm -rf work/ deploy/
sudo ./build.sh
```

**Service not starting?**
```bash
# Check logs
ssh dt@10.3.141.1
sudo journalctl -u dangerous-pi.service -n 50

# Common issue: Port conflict with ttyd
# See PORT_CONFLICT.md
```

**Image too large?**
Already optimized! Your scripts include:
- Package cache cleanup
- Pip cache removal
- Auto-remove unused packages

## Files Created

- 📄 [BUILD_GUIDE.md](BUILD_GUIDE.md) - Complete build guide
- 🚀 [build-image.sh](build-image.sh) - Build helper script
- ✅ [test-image.sh](test-image.sh) - Automated testing
- 📖 This file - Quick reference

## Recommended Workflow

1. **Initial setup**: Full build with `./build.sh`
2. **Development**: Make code changes
3. **Quick rebuild**: `CONTINUE=1 STAGE=stageDTPM3 ./build.sh`
4. **Flash**: Use Balena Etcher
5. **Test**: Run `./test-image.sh`
6. **Iterate**: Repeat steps 2-5

## Full Documentation

See [BUILD_GUIDE.md](BUILD_GUIDE.md) for:
- Detailed configuration options
- Advanced customization
- Stage architecture
- Optimization tips
- Complete troubleshooting guide

---

**Quick Start**: `./docker-build.sh` → Flash → Test 🎉
