Component Reference
Detailed documentation for every script in the LyreBirdAudio suite.
Quick Reference Table
| Script | Version | Purpose |
|---|---|---|
lyrebird-orchestrator.sh | 2.1.2 | Unified management interface |
lyrebird-stream-manager.sh | 1.4.3 | Stream lifecycle management |
usb-audio-mapper.sh | 1.2.1 | USB device persistence via udev |
lyrebird-mic-check.sh | 1.0.0 | Hardware capability detection |
lyrebird-diagnostics.sh | 1.0.2 | System health diagnostics |
install_mediamtx.sh | 2.0.1 | MediaMTX installation & upgrade |
lyrebird-alerts.sh | 1.0.0 | Webhook alerting system |
lyrebird-metrics.sh | 1.0.0 | Prometheus metrics export |
lyrebird-storage.sh | 1.0.0 | Storage management & cleanup |
lyrebird-updater.sh | 1.5.1 | Version management & rollback |
lyrebird-common.sh | — | Shared utility library |
🎛️ Orchestrator
lyrebird-orchestrator.sh — Unified management interface that delegates
to all other scripts. This is the recommended entry point for all operations.
Usage
sudo ./lyrebird-orchestrator.sh
Features
- Interactive TUI menu for all operations
- Quick Setup Wizard for first-time configuration
- Hardware capability inspection and display
- SHA256 integrity verification for sourced scripts
- Automatic detection of outdated script names
- Comprehensive logging to
/var/log/lyrebird-orchestrator.log
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Permission denied |
| 3 | Missing dependencies |
| 4 | Script not found |
📡 Stream Manager
lyrebird-stream-manager.sh — Core audio streaming script.
Detects USB microphones, manages FFmpeg processes, monitors stream health, and provides
automatic recovery with exponential backoff.
Usage
# Individual streams (default)
sudo ./lyrebird-stream-manager.sh start
# Multiplex (mix all mics)
sudo ./lyrebird-stream-manager.sh -m multiplex -f amix start
# Multiplex (merge channels)
sudo ./lyrebird-stream-manager.sh -m multiplex -f amerge start
# Custom multiplex stream name
sudo ./lyrebird-stream-manager.sh -m multiplex -n studio start
Commands
Features
- Wrapper-based FFmpeg supervision with exponential backoff (10s → 300s)
- Health monitoring via MediaMTX REST API
- Dual-lookup config (friendly name first, then full device ID, then defaults)
- CPU, memory, and file descriptor monitoring
- Lock file prevents concurrent executions
- Graceful shutdown with process tree termination
- Per-device FFmpeg log files with rotation
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Critical resource state (triggers restart) |
| 3 | Missing dependencies |
| 4 | Configuration error |
| 5 | Lock acquisition failed (another instance running) |
| 6 | No USB devices found |
| 7 | MediaMTX not running |
| 10 | Stream monitoring degraded |
🔌 USB Audio Mapper
usb-audio-mapper.sh — Creates persistent udev rules that give
USB audio devices stable names across reboots, even when USB enumeration order changes.
Usage
# Interactive mode (guided wizard)
sudo ./usb-audio-mapper.sh
# Non-interactive (for automation)
sudo ./usb-audio-mapper.sh -n -d "Device" -v XXXX -p YYYY -f friendly-name
# Test USB port detection
sudo ./usb-audio-mapper.sh --test
# Debug mode
sudo ./usb-audio-mapper.sh --debug
Options
| Flag | Description |
|---|---|
-i, --interactive | Run in interactive mode (default) |
-n, --non-interactive | Skip all prompts |
-d, --device <name> | Device label for logging |
-v, --vendor <id> | 4-digit hex vendor ID |
-p, --product <id> | 4-digit hex product ID |
-f, --friendly <name> | Friendly name for the stream |
-t, --test | Test USB port detection without making changes |
-D, --debug | Enable debug output |
Output
The script creates:
/etc/udev/rules.d/99-usb-soundcards.rules— udev rules file/dev/snd/by-usb-port/Device_N— Persistent symlinks (after reboot)
After mapping devices, a reboot is required for udev rules to take effect and persistent symlinks to be created. Do not skip this step.
🎙️ Capability Checker
lyrebird-mic-check.sh — Non-invasively detects USB audio hardware
capabilities via the ALSA proc filesystem. Never opens devices (won't interrupt active streams).
Usage
# List all detected devices
./lyrebird-mic-check.sh
# Show details for device index 0
./lyrebird-mic-check.sh 0
# Generate configuration file (recommended)
sudo ./lyrebird-mic-check.sh -g --quality=normal
# Validate existing configuration
sudo ./lyrebird-mic-check.sh -V
# JSON output for scripting
./lyrebird-mic-check.sh --json
# Restore configuration from backup
sudo ./lyrebird-mic-check.sh --restore
# Dry-run (preview without writing)
./lyrebird-mic-check.sh -g --dry-run
What It Detects
- Supported sample rates (16kHz, 44.1kHz, 48kHz, 96kHz, etc.)
- Channel configurations (mono, stereo)
- Supported audio formats and bit depths
- Device busy state (non-destructively)
- USB audio adapter chip type (with warnings for limited chips)
For USB adapters with 3.5mm inputs, detected capabilities reflect the USB chip — not the microphone plugged into the analog jack. Always verify audio quality after configuration by checking actual recordings.
🩺 Diagnostics
lyrebird-diagnostics.sh — Comprehensive system health checker
with 20+ checks covering devices, services, connectivity, and resources.
Usage
# Quick check (essential systems, fast)
sudo ./lyrebird-diagnostics.sh quick
# Full check (comprehensive analysis)
sudo ./lyrebird-diagnostics.sh full
# Debug check (maximum verbosity)
sudo ./lyrebird-diagnostics.sh debug
Options
| Option | Description |
|---|---|
--config <path> | Specify alternate MediaMTX config file |
--timeout <seconds> | Set command timeout (default: 30) |
--debug | Enable verbose debug output |
--quiet | Suppress non-error output |
--no-color | Disable colored output |
Exit Codes
| Code | Meaning |
|---|---|
| 0 | All checks passed |
| 1 | Warnings detected (system functional but needs attention) |
| 2 | Failures detected (system degraded or non-functional) |
| 127 | Prerequisites missing (cannot complete diagnostics) |
📦 MediaMTX Installer
install_mediamtx.sh — Downloads, verifies, and installs MediaMTX
with atomic updates and automatic rollback on failure.
Usage
# Install latest version
sudo ./install_mediamtx.sh install
# Install specific version
sudo ./install_mediamtx.sh -V v1.15.0 install
# Update existing installation
sudo ./install_mediamtx.sh update
# Check current status
./install_mediamtx.sh status
# Verify installation integrity
sudo ./install_mediamtx.sh verify
# Uninstall MediaMTX
sudo ./install_mediamtx.sh uninstall
# Dry-run (show what would happen)
sudo ./install_mediamtx.sh --dry-run install
Options
| Option | Description |
|---|---|
-V <version> | Install specific MediaMTX version (e.g., v1.15.0) |
-p <prefix> | Custom installation prefix (default: /usr/local) |
-f, --force | Force installation, skip verification |
-n, --dry-run | Show actions without executing |
-q, --quiet | Suppress non-error output |
-v, --verbose | Enable debug output |
--no-service | Skip systemd service creation |
Features
- Platform-aware: Linux (x86_64, ARM64, ARMv7, ARMv6), macOS, FreeBSD
- SHA256 checksum verification of downloaded binaries
- Atomic installation (writes to temp, then renames)
- Automatic rollback if verification fails
- Built-in upgrade support for MediaMTX 1.15.0+
- Creates dedicated
mediamtxservice user - Generates default
mediamtx.ymlif not present
🔔 Webhook Alerts
lyrebird-alerts.sh — Pure-Bash webhook alerting with rate limiting
and deduplication. No new dependencies required.
Usage
# Interactive setup wizard
./lyrebird-alerts.sh setup
# Send test alert
./lyrebird-alerts.sh test
# Send a custom alert
./lyrebird-alerts.sh send --level warning --title "Alert" --message "Something happened"
# Check configuration status
./lyrebird-alerts.sh status
# Show current config
./lyrebird-alerts.sh config
Supported Webhook Types
| Type | Config Value | Notes |
|---|---|---|
| Discord | discord | Rich embeds with color-coded severity |
| Slack | slack | Incoming webhook format |
| ntfy.sh | ntfy | Free, self-hostable push notifications |
| Pushover | pushover | Mobile push for iOS/Android |
| Generic HTTP | generic | Any HTTP POST endpoint |
Configuration
# /etc/lyrebird/alerts.conf
LYREBIRD_ALERT_ENABLED=true
LYREBIRD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
LYREBIRD_WEBHOOK_TYPE="discord"
LYREBIRD_ALERT_RATE_LIMIT=300 # Seconds between duplicate alerts
LYREBIRD_HOSTNAME="field-unit-1"
LYREBIRD_LOCATION="North Forest"
Pre-Built Alert Functions
# Source in your scripts
source ./lyrebird-alerts.sh
alert_stream_down "mic1" "FFmpeg process died"
alert_stream_up "mic1"
alert_device_disconnect "USB_Mic_2"
alert_disk_warning "/" "82%"
alert_mediamtx_down
alert_network_down
📊 Prometheus Metrics
lyrebird-metrics.sh — Exports operational metrics in
Prometheus/OpenMetrics text format for Grafana dashboards.
Usage
# One-time metrics output (stdout)
./lyrebird-metrics.sh
# Start HTTP server (for Prometheus scraping)
./lyrebird-metrics.sh serve --port 9100
# Export only stream metrics
./lyrebird-metrics.sh --streams-only
# Export only system metrics
./lyrebird-metrics.sh --system-only
Available Metrics
# Service status
lyrebird_mediamtx_up 1
lyrebird_mediamtx_uptime_seconds 3600
# Per-stream metrics
lyrebird_stream_active{name="mic1"} 1
lyrebird_stream_uptime_seconds{name="mic1"} 1800
# USB device status
lyrebird_usb_devices_total 3
lyrebird_usb_device_connected{name="mic1"} 1
# System resources
lyrebird_cpu_usage_percent 15.5
lyrebird_memory_usage_percent 45.2
lyrebird_disk_usage_percent{mount="/"} 62
lyrebird_load_average_1m 0.5
Prometheus Configuration
# prometheus.yml
scrape_configs:
- job_name: 'lyrebird'
static_configs:
- targets: ['field-unit-1:9100']
scrape_interval: 30s
💾 Storage Management
lyrebird-storage.sh — Manages disk space with configurable
retention policies. Essential for long-running deployments.
Usage
# Check storage status
./lyrebird-storage.sh status
# Run cleanup (respects retention policy)
sudo ./lyrebird-storage.sh cleanup
# Emergency cleanup (aggressive)
sudo ./lyrebird-storage.sh emergency
# Monitor mode (continuous)
./lyrebird-storage.sh monitor --interval 300
Configuration
# /etc/lyrebird/storage.conf
RECORDING_RETENTION_DAYS=30 # Keep recordings for 30 days
LOG_RETENTION_DAYS=7 # Keep logs for 7 days
DISK_WARNING_PERCENT=80 # Warn at 80% disk usage
DISK_CRITICAL_PERCENT=90 # Critical at 90% usage
RECORDING_DIR="/var/recordings"
LOG_DIR="/var/log/lyrebird"
Automated Cleanup
# /etc/cron.d/lyrebird-storage
0 3 * * * root /path/to/lyrebird-storage.sh cleanup --quiet
*/15 * * * * root /path/to/lyrebird-storage.sh monitor --once
🔄 Version Manager
lyrebird-updater.sh — Safe git-based version management with
transaction-based updates and automatic rollback.
Usage
# Interactive menu
./lyrebird-updater.sh
# Check for updates
./lyrebird-updater.sh --status
# List available versions
./lyrebird-updater.sh --list
# Rollback to previous version
./lyrebird-updater.sh --rollback
# Run post-update migrations manually
sudo ./lyrebird-updater.sh --migrate
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 2 | Prerequisites not met |
| 3 | Not a git repository |
| 5 | Permission error |
| 7 | Locked (another instance running) |
| 9 | User aborted |
📚 Shared Library
lyrebird-common.sh — Utility functions shared across all scripts
via sourcing. All scripts work with or without it (fallback definitions included).
Provided Functions
| Function | Purpose |
|---|---|
lyrebird_command_exists() | Check command availability (cached) |
lyrebird_compute_hash() | Portable SHA256 hashing |
log_debug() / log_info() | Logging with timestamps |
log_warn() / log_error() | Warning and error logging |
lyrebird_timestamp() | Formatted timestamp |
Exit Code Constants
E_SUCCESS=0
E_PERMISSION=2
E_MISSING_DEPS=3
E_CONFIG_ERROR=4
E_LOCKED=5