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:
@@ -1,23 +1,48 @@
|
||||
#!/bin/bash
|
||||
# Wrapper script for approve-sensors that sets minimal required env vars
|
||||
# Wrapper script for approve-sensors that works in both dev and system mode
|
||||
|
||||
# Get script directory
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"
|
||||
# Detect installation type
|
||||
if [ -d "/opt/sensorpajen" ]; then
|
||||
# System installation
|
||||
PROJECT_ROOT="/opt/sensorpajen"
|
||||
VENV_PATH="/opt/sensorpajen/venv"
|
||||
|
||||
# Load config from system location
|
||||
if [ -f "/etc/sensorpajen/sensorpajen.env" ]; then
|
||||
set -a
|
||||
source /etc/sensorpajen/sensorpajen.env
|
||||
set +a
|
||||
else
|
||||
echo "Warning: /etc/sensorpajen/sensorpajen.env not found"
|
||||
# Set minimal defaults
|
||||
export MQTT_HOST="${MQTT_HOST:-localhost}"
|
||||
export MQTT_PORT="${MQTT_PORT:-1883}"
|
||||
fi
|
||||
else
|
||||
# Development installation
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"
|
||||
VENV_PATH="$PROJECT_ROOT/.venv"
|
||||
|
||||
# Set minimal required environment variables
|
||||
export MQTT_HOST="${MQTT_HOST:-localhost}"
|
||||
export MQTT_PORT="${MQTT_PORT:-1883}"
|
||||
|
||||
# Set minimal required environment variables
|
||||
export MQTT_HOST="${MQTT_HOST:-localhost}"
|
||||
export MQTT_PORT="${MQTT_PORT:-1883}"
|
||||
|
||||
# Load actual config if it exists (will override defaults)
|
||||
if [ -f "$PROJECT_ROOT/config/sensorpajen.env" ]; then
|
||||
set -a
|
||||
source "$PROJECT_ROOT/config/sensorpajen.env"
|
||||
set +a
|
||||
# Load actual config if it exists (will override defaults)
|
||||
if [ -f "$PROJECT_ROOT/config/sensorpajen.env" ]; then
|
||||
set -a
|
||||
source "$PROJECT_ROOT/config/sensorpajen.env"
|
||||
set +a
|
||||
fi
|
||||
fi
|
||||
|
||||
# Activate virtual environment
|
||||
source "$PROJECT_ROOT/.venv/bin/activate"
|
||||
if [ -f "$VENV_PATH/bin/activate" ]; then
|
||||
source "$VENV_PATH/bin/activate"
|
||||
else
|
||||
echo "Error: Virtual environment not found at $VENV_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run the approve-sensors command
|
||||
python -m sensorpajen.approve_sensors "$@"
|
||||
|
||||
170
scripts/verify-deb.sh
Executable file
170
scripts/verify-deb.sh
Executable file
@@ -0,0 +1,170 @@
|
||||
#!/bin/bash
|
||||
# Automated verification script for Debian package
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo "======================================================================"
|
||||
echo " Sensorpajen Debian Package Verification"
|
||||
echo "======================================================================"
|
||||
echo ""
|
||||
|
||||
# Check dependencies
|
||||
echo -n "Checking for dpkg-deb... "
|
||||
if command -v dpkg-deb >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}OK${NC}"
|
||||
else
|
||||
echo -e "${RED}MISSING${NC}"
|
||||
echo "Install with: sudo apt install dpkg-dev"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "Checking for lintian... "
|
||||
if command -v lintian >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}OK${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}MISSING${NC}"
|
||||
echo "Install with: sudo apt install lintian"
|
||||
echo "Continuing without lintian checks..."
|
||||
SKIP_LINTIAN=1
|
||||
fi
|
||||
|
||||
echo -n "Checking for debhelper... "
|
||||
if dpkg -l debhelper >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}OK${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}MISSING${NC}"
|
||||
echo "Install with: sudo apt install debhelper"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Get project root
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Check required files exist
|
||||
echo "Checking required files..."
|
||||
REQUIRED_FILES=(
|
||||
"debian/control"
|
||||
"debian/rules"
|
||||
"debian/install"
|
||||
"debian/changelog"
|
||||
"debian/postinst"
|
||||
"debian/prerm"
|
||||
"debian/postrm"
|
||||
"debian/compat"
|
||||
"debian/sensorpajen.service"
|
||||
"src/sensorpajen/main.py"
|
||||
"pyproject.toml"
|
||||
)
|
||||
|
||||
ALL_FILES_OK=1
|
||||
for file in "${REQUIRED_FILES[@]}"; do
|
||||
echo -n " $file... "
|
||||
if [ -f "$file" ]; then
|
||||
echo -e "${GREEN}OK${NC}"
|
||||
else
|
||||
echo -e "${RED}MISSING${NC}"
|
||||
ALL_FILES_OK=0
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $ALL_FILES_OK -eq 0 ]; then
|
||||
echo -e "${RED}Some required files are missing!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Extract version from pyproject.toml
|
||||
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
|
||||
echo "Package version: $VERSION"
|
||||
echo ""
|
||||
|
||||
# Clean previous builds
|
||||
echo "Cleaning previous builds..."
|
||||
rm -f ../*.deb ../*.build ../*.buildinfo ../*.changes
|
||||
rm -rf debian/.debhelper debian/sensorpajen debian/files
|
||||
|
||||
# Build the package
|
||||
echo "Building Debian package..."
|
||||
echo "======================================================================"
|
||||
dpkg-buildpackage -us -uc -b
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED}Build failed!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}Build successful!${NC}"
|
||||
echo ""
|
||||
|
||||
# Find the built package
|
||||
DEB_FILE=$(ls -t ../*.deb 2>/dev/null | head -1)
|
||||
|
||||
if [ -z "$DEB_FILE" ]; then
|
||||
echo -e "${RED}No .deb file found!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Package: $DEB_FILE"
|
||||
echo ""
|
||||
|
||||
# Show package contents
|
||||
echo "Package contents:"
|
||||
echo "======================================================================"
|
||||
dpkg-deb -c "$DEB_FILE" | head -20
|
||||
TOTAL_FILES=$(dpkg-deb -c "$DEB_FILE" | wc -l)
|
||||
if [ $TOTAL_FILES -gt 20 ]; then
|
||||
echo "... and $(($TOTAL_FILES - 20)) more files"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Show package info
|
||||
echo "Package information:"
|
||||
echo "======================================================================"
|
||||
dpkg-deb -I "$DEB_FILE"
|
||||
echo ""
|
||||
|
||||
# Run lintian if available
|
||||
if [ -z "$SKIP_LINTIAN" ]; then
|
||||
echo "Running lintian checks..."
|
||||
echo "======================================================================"
|
||||
|
||||
# Run lintian - allow warnings but fail on errors
|
||||
if lintian "$DEB_FILE"; then
|
||||
echo -e "${GREEN}Lintian passed!${NC}"
|
||||
else
|
||||
LINTIAN_EXIT=$?
|
||||
echo -e "${YELLOW}Lintian found issues (exit code: $LINTIAN_EXIT)${NC}"
|
||||
echo "Review the output above. Warnings are acceptable, errors should be fixed."
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Final summary
|
||||
echo "======================================================================"
|
||||
echo -e "${GREEN}Package verification complete!${NC}"
|
||||
echo "======================================================================"
|
||||
echo ""
|
||||
echo "Package location: $DEB_FILE"
|
||||
echo ""
|
||||
echo "To install on a Raspberry Pi:"
|
||||
echo " scp $DEB_FILE pi@raspberrypi:~/"
|
||||
echo " ssh pi@raspberrypi"
|
||||
echo " sudo apt install ./$(basename $DEB_FILE)"
|
||||
echo ""
|
||||
echo "To test locally (not recommended, will modify /opt and /etc):"
|
||||
echo " sudo apt install $DEB_FILE"
|
||||
echo ""
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user