secubox-deb/packages/secubox-eye-remote/core/__init__.py
CyberMind-FR 740c20cc29 feat(secubox-eye-remote): Implement boot media core logic with 4R pattern
Adds BootMediaManager for USB Mass Storage LUN image management:

Core Features:
- Thread-safe with RLock for reentrant operations
- 4R double-buffer pattern (active/shadow slots)
- Image validation (FAT32/ext magic, size constraints 16MiB-4GiB)
- SHA256 integrity verification
- Atomic symlink swaps for zero-downtime updates
- TFTP boot file extraction (optional, disabled in test mode)

Functions Implemented:
- validate_image(): Check FAT32/ext magic and size limits
- upload_to_shadow(): Stream upload with hash computation
- swap(): Atomic active↔shadow exchange with LUN detach/reattach
- rollback(): Convenience wrapper for swap operation
- get_state(): Read current state from symlinks and state.json

Technical Details:
- Uses RLock instead of Lock to prevent deadlock (get_state called from swap)
- Subprocess calls for gadget-setup.sh LUN management
- Test mode flag (SECUBOX_TEST_MODE) to skip TFTP extraction
- State persistence in /var/lib/secubox/eye-remote/boot-media/state.json

Tests:
- 18 integration tests covering all operations
- Mock subprocess.run for gadget script calls
- Validates atomic operations and state persistence

Next: Task 5 - FastAPI router endpoints

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-23 11:16:30 +02:00

5 lines
166 B
Python

"""SecuBox Eye Remote — Core modules."""
from .boot_media import BootMediaManager, get_boot_media_manager
__all__ = ["BootMediaManager", "get_boot_media_manager"]