Phase 8: Implement Debian package creation (2025-12-27)
- Create debian/ directory structure with all required files: - control: Package metadata and dependencies - compat: Debhelper compatibility level - changelog: Version history - rules: Build instructions - install: File installation mappings - postinst: Post-installation setup (user, venv, setcap) - prerm: Pre-removal script (stop service) - postrm: Post-removal script (cleanup, preserve config) - sensorpajen.service: System-wide systemd unit - Update config.py to support dual-mode operation: - Auto-detects system installation (/opt/sensorpajen) - Uses /etc/sensorpajen for config in system mode - Falls back to PROJECT_ROOT/config for development - Update scripts/approve-sensors.sh for system paths: - Detects system vs development installation - Uses correct venv and config paths - Create scripts/verify-deb.sh: Automated build and verification - Create debian/README.md: Comprehensive packaging documentation Package features: - System-wide installation to /opt/sensorpajen/ - Configuration in /etc/sensorpajen/ (preserved on upgrade/remove) - Dedicated sensorpajen system user - Automatic venv creation with dependencies - Bluetooth capabilities set automatically - Service auto-enabled but waits for config before starting - Dual-mode code supports both system and development installations
This commit is contained in:
185
ROADMAP.md
185
ROADMAP.md
@@ -321,142 +321,75 @@ config/sensorpajen.env
|
||||
|
||||
---
|
||||
|
||||
### Phase 8: APT Package Creation ✓ TODO
|
||||
### Phase 8: APT Package Creation ✅ DONE (2025-12-27)
|
||||
**Goal**: Create Debian package for easy installation on Raspberry Pi
|
||||
|
||||
#### Tasks:
|
||||
1. Create debian/ directory structure:
|
||||
```bash
|
||||
mkdir -p debian
|
||||
```
|
||||
**Notes**:
|
||||
- Complete debian/ directory structure created
|
||||
- System-wide installation to /opt/sensorpajen
|
||||
- Configuration in /etc/sensorpajen
|
||||
- Dedicated sensorpajen system user
|
||||
- Automatic venv creation in postinst
|
||||
- Bluetooth capabilities set automatically
|
||||
- Config preserved on remove/purge for safety
|
||||
- Dual-mode support: system installation and development
|
||||
- config.py auto-detects installation type
|
||||
|
||||
2. Create `debian/control`:
|
||||
``APT package installation instructions
|
||||
- Development installation instructions
|
||||
- Configuration guide (relative paths)
|
||||
- Service management commands
|
||||
- Troubleshooting section
|
||||
- Remove DHT11 references
|
||||
- Remove pirate_audio references
|
||||
#### Files Created:
|
||||
- ✅ debian/control - Package metadata and dependencies
|
||||
- ✅ debian/compat - Debhelper compatibility level
|
||||
- ✅ debian/changelog - Package version history
|
||||
- ✅ debian/rules - Build instructions
|
||||
- ✅ debian/install - File installation mappings
|
||||
- ✅ debian/postinst - Post-installation script (user, venv, setcap)
|
||||
- ✅ debian/prerm - Pre-removal script (stop service)
|
||||
- ✅ debian/postrm - Post-removal script (cleanup)
|
||||
- ✅ debian/sensorpajen.service - System-wide systemd unit
|
||||
|
||||
3. Create INSTALL.md:
|
||||
- APT package installation steps
|
||||
- Manual installation steps
|
||||
- Configuration examples
|
||||
- First-time setup guide
|
||||
- Raspberry Pi specific instructionsds}, ${misc:Depends},
|
||||
python3-bluepy,
|
||||
python3-paho-mqtt,
|
||||
bluetooth,
|
||||
bluez
|
||||
Description: Bluetooth temperature sensor monitor
|
||||
Monitors Xiaomi Mijia LYWSD03MMC Bluetooth temperature sensors
|
||||
and publishes data to MQTT broker.
|
||||
```
|
||||
#### Code Updates:
|
||||
- ✅ Updated src/sensorpajen/config.py to detect system installation
|
||||
- Checks for /opt/sensorpajen existence
|
||||
- Uses /etc/sensorpajen for config in system mode
|
||||
- Falls back to PROJECT_ROOT/config for development
|
||||
- ✅ Updated scripts/approve-sensors.sh for dual-mode operation
|
||||
- Detects system vs development installation
|
||||
- Uses correct venv and config paths
|
||||
- ✅ Created scripts/verify-deb.sh - Automated build and verification
|
||||
|
||||
3. Create `debian/rules`:
|
||||
```makefile
|
||||
#!/usr/bin/make -f
|
||||
|
||||
%:
|
||||
dh $@ --with python3 --buildsystem=pybuild
|
||||
|
||||
override_dh_auto_install:
|
||||
pytOption 1: APT Package (Recommended for Raspberry Pi)
|
||||
|
||||
1. Download and install the .deb package:
|
||||
```bash
|
||||
sudo dpkg -i sensorpajen_1.0.0_all.deb
|
||||
sudo apt-get install -f # Fix any dependencies
|
||||
```
|
||||
|
||||
2. Configure:
|
||||
```bash
|
||||
mkdir -p ~/sensorpajen/config
|
||||
cp /usr/share/doc/sensorpajen/examples/sensorpajen.env.example ~/sensorpajen/config/sensorpajen.env
|
||||
cp /usr/share/doc/sensorpajen/examples/sensors.json.example ~/sensorpajen/config/sensors.json
|
||||
# Edit both files
|
||||
nano ~/sensorpajen/config/sensorpajen.env
|
||||
nano ~/sensorpajen/config/sensors.json
|
||||
chmod 600 ~/sensorpajen/config/sensorpajen.env
|
||||
```
|
||||
|
||||
3. Enable and start service:
|
||||
```bash
|
||||
systemctl --user enable sensorpajen
|
||||
systemctl --user start sensorpajen
|
||||
```
|
||||
|
||||
### Option 2: Development Installation
|
||||
|
||||
1. Clone Repository
|
||||
```bash
|
||||
git clone <repo> ~/sensorpajen
|
||||
cd ~/sensorpajen
|
||||
```
|
||||
|
||||
2. Create Virtual Environment
|
||||
```bash
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install -e .
|
||||
```
|
||||
#### Package Details:
|
||||
- Package name: sensorpajen
|
||||
- Version: 2.0.0-dev
|
||||
- Architecture: all
|
||||
- System paths:
|
||||
- Application: /opt/sensorpajen/
|
||||
- Configuration: /etc/sensorpajen/
|
||||
- Service file: /etc/systemd/system/sensorpajen.service
|
||||
- Examples: /usr/share/doc/sensorpajen/examples/
|
||||
- Runs as dedicated sensorpajen user (system account)
|
||||
- Auto-enables service but waits for configuration before starting
|
||||
|
||||
### Relative Paths (For Portability)
|
||||
- **Project root**: `~/sensorpajen/` (or wherever you clone/install)
|
||||
- **Application config**: `~/sensorpajen/config/`
|
||||
- **Environment file**: `~/sensorpajen/config/sensorpajen.env` (0600)
|
||||
- **Sensor mapping**: `~/sensorpajen/config/sensors.json` (0644)
|
||||
- **Service file**: `~/.config/systemd/user/sensorpajen.service`
|
||||
#### Build and Test:
|
||||
```bash
|
||||
# Build package
|
||||
./scripts/verify-deb.sh
|
||||
|
||||
### Advantages of Relative Paths
|
||||
- Works on any system (development, production, multiple Raspberry Pis)
|
||||
- Easy to backup/restore entire directory
|
||||
- No hardcoded paths in code
|
||||
- Simple to deploy via git pull or package installation
|
||||
- User service runs without sudo
|
||||
# Or manually:
|
||||
dpkg-buildpackage -us -uc -b
|
||||
lintian ../sensorpajen_*.deb
|
||||
|
||||
### APT Package Installation
|
||||
When installed via .deb package:
|
||||
- **Python package**: `/usr/lib/python3/dist-packages/sensorpajen/`
|
||||
- **Service file**: `/lib/systemd/user/sensorpajen.service`
|
||||
- **Config templates**: `/usr/share/doc/sensorpajen/examples/`
|
||||
- **User config**: `~/sensorpajen/config/` (created by user)sensorpajen
|
||||
```
|
||||
|
||||
5. Verify
|
||||
```bash
|
||||
systemctl --user status sensorpajen
|
||||
journalctl --user -u sensorpajen -f
|
||||
```uetooth access
|
||||
if [ "$1" = "configure" ]; then
|
||||
PYTHON_PATH=$(readlink -f /usr/bin/python3)
|
||||
setcap 'cap_net_raw,cap_net_admin+eip' "$PYTHON_PATH" || true
|
||||
fi
|
||||
|
||||
#DEBHELPER#
|
||||
```
|
||||
# Install on Raspberry Pi:
|
||||
scp ../sensorpajen_*.deb pi@raspberrypi:~/
|
||||
ssh pi@raspberrypi
|
||||
sudo apt install ./sensorpajen_*.deb
|
||||
|
||||
7. Create `debian/README.Debian`:
|
||||
- Installation instructions
|
||||
- Configuration guide
|
||||
- Service management
|
||||
# Configure:
|
||||
sudo nano /etc/sensorpajen/sensorpajen.env
|
||||
sudo nano /etc/sensorpajen/sensors.json
|
||||
|
||||
8. Build the package:
|
||||
```bash
|
||||
dpkg-buildpackage -us -uc -b
|
||||
```
|
||||
|
||||
9. Test installation on Raspberry Pi:
|
||||
```bash
|
||||
sudo dpkg -i ../sensorpajen_1.0.0_all.deb
|
||||
sudo apt-get install -f # Fix dependencies if needed
|
||||
```
|
||||
|
||||
10. Create installation documentation:
|
||||
- Package installation instructions
|
||||
- Configuration setup after installation
|
||||
- Service enablement
|
||||
# Start:
|
||||
sudo systemctl start sensorpajen
|
||||
sudo journalctl -u sensorpajen -f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user