Quick Reference Table

ScriptVersionPurpose
lyrebird-orchestrator.sh2.1.2Unified management interface
lyrebird-stream-manager.sh1.4.3Stream lifecycle management
usb-audio-mapper.sh1.2.1USB device persistence via udev
lyrebird-mic-check.sh1.0.0Hardware capability detection
lyrebird-diagnostics.sh1.0.2System health diagnostics
install_mediamtx.sh2.0.1MediaMTX installation & upgrade
lyrebird-alerts.sh1.0.0Webhook alerting system
lyrebird-metrics.sh1.0.0Prometheus metrics export
lyrebird-storage.sh1.0.0Storage management & cleanup
lyrebird-updater.sh1.5.1Version management & rollback
lyrebird-common.shShared 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

Exit Codes

CodeMeaning
0Success
1General error
2Permission denied
3Missing dependencies
4Script 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

Available Commands
startStart all configured streams
stopGracefully stop all streams
restartStop then start all streams
statusShow stream status and process info
monitorHealth check + restart failed streams (cron use)
configDisplay active stream configuration
force-stopForce kill all and clean stale files
installInstall systemd service + cron monitoring

Features

Exit Codes

CodeMeaning
0Success
1General error
2Critical resource state (triggers restart)
3Missing dependencies
4Configuration error
5Lock acquisition failed (another instance running)
6No USB devices found
7MediaMTX not running
10Stream 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

FlagDescription
-i, --interactiveRun in interactive mode (default)
-n, --non-interactiveSkip 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, --testTest USB port detection without making changes
-D, --debugEnable debug output

Output

The script creates:

⚠️
Reboot Required

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

ℹ️
USB Audio Adapter Note

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

OptionDescription
--config <path>Specify alternate MediaMTX config file
--timeout <seconds>Set command timeout (default: 30)
--debugEnable verbose debug output
--quietSuppress non-error output
--no-colorDisable colored output

Exit Codes

CodeMeaning
0All checks passed
1Warnings detected (system functional but needs attention)
2Failures detected (system degraded or non-functional)
127Prerequisites 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

OptionDescription
-V <version>Install specific MediaMTX version (e.g., v1.15.0)
-p <prefix>Custom installation prefix (default: /usr/local)
-f, --forceForce installation, skip verification
-n, --dry-runShow actions without executing
-q, --quietSuppress non-error output
-v, --verboseEnable debug output
--no-serviceSkip systemd service creation

Features


🔔 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

TypeConfig ValueNotes
DiscorddiscordRich embeds with color-coded severity
SlackslackIncoming webhook format
ntfy.shntfyFree, self-hostable push notifications
PushoverpushoverMobile push for iOS/Android
Generic HTTPgenericAny 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

CodeMeaning
0Success
2Prerequisites not met
3Not a git repository
5Permission error
7Locked (another instance running)
9User 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

FunctionPurpose
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