Skip to content

Sparky-OS/sparky-beep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Sparky Beep Provides beep support for a few services of server edition.

Overview

Sparky Beep offers audible notifications when selected system services start, stop or restart. The repository is arranged in a few key directories:

  • README.md introduces Sparky Beep and lists required packages and installation commands.
  • install.sh copies or removes init scripts, systemd service files and the main helper script. Run it with uninstall to remove everything.
  • bin/ holds sparky-beep-run, a helper script that verifies the beep services are active and starts them if needed.
  • init.d/ contains SysV init scripts such as beep_netdata, beep_samba, beep_sys, beep_webmin and sparky-beep. Each of these defines beep commands for different service states. For example:
case "$1" in
  start)
    beep -f 1000 -n -f 1500 -n -f 600 ...
    ;;
  stop)
    beep -f 100 -r 2 -l 10 -n -f 50 ...
    ;;
  restart)
    beep -f 100 -r 2 -l 10 ... ; beep -f 1000 ...
    ;;
esac
  • system/ provides systemd unit files that link the beep scripts to services like netdata.service, samba-ad-dc.service, ssh.service and webmin.
  • Additional metadata includes CHANGELOG, LICENSE and Debian-style copyright information.

Key Points

  • The goal is to give audible feedback ("beeps") when services change state.
  • Installation copies the scripts into system directories while uninstallation removes them.
  • sparky-beep-run can be triggered from an init script and keeps the beep services enabled and running.

Musical Composer (NEW!)

Sparky Beep now includes a musical notation composer that lets you create melodic beeps using standard musical notation instead of raw frequencies!

Features:

  • ๐ŸŽต Musical notation support - Write C4q D4q E4q instead of beep -f 261 -l 500 -n -f 293...
  • ๐ŸŽผ 8 octaves - Full range from C0 to B8 (88 notes)
  • ๐ŸŽน All chromatic notes - Sharps (#) and flats (b) supported
  • โฑ๏ธ Tempo control - Set BPM from 40-240
  • ๐Ÿ”Š Ternary beep mode - Optional smoother sounds using ternary logic (requires compilation)

Quick Examples:

# Play C major scale
sparky-beep-compose -s "C4q D4q E4q F4q G4q A4q B4q C5q" -p

# Play Happy Birthday
sparky-beep-compose compositions/happy-birthday.beepmusic -p

# Custom tempo
sparky-beep-compose -s "tempo:140 C4h E4h G4h C5w" -p

Included Compositions:

  • C Major Scale
  • Happy Birthday
  • Twinkle Twinkle Little Star
  • Ode to Joy (Beethoven)
  • Star Wars Theme
  • Super Mario Bros Theme
  • Startup/Shutdown fanfares
  • Alert/notification sounds

Ternary Beep Engine (Advanced):

For smoother, more musical sounds, compile the optional ternary beep engine:

make              # Compile tbeep
sudo make install # Install ternary beep engine

# Enable ternary mode in config
sudo nano /etc/sparky-beep/beep.conf
# Change: BEEP_MODE="ternary"

# Test
sudo tbeep -f 440 -l 500

What is Ternary Beep?

Standard beep uses binary states (ON/OFF), creating harsh square waves. Ternary beep uses 3 states {-1, 0, +1}, approximating sine waves for smoother, more pleasant sounds!

Binary:  โ”Œโ”€โ” โ”Œโ”€โ” โ”Œโ”€โ”   (harsh, buzzy)
Ternary:   โ•ญโ”€โ•ฎ         (smooth, musical)
         โ•ญโ”€โ•ฏ โ•ฐโ”€โ•ฎ
        โ”€โ•ฏ     โ•ฐโ”€

Documentation:

  • COMPOSER.md - Complete composer documentation and examples
  • config/beep.conf - Configuration file for beep mode and settings
  • compositions/ - Pre-made musical compositions
  • lib/notes.sh - Musical note library with all frequencies

Configuration Management (NEW!)

Sparky Beep now includes powerful configuration tools for easy management:

๐Ÿ–ฅ๏ธ TUI (Text User Interface):

sudo sparky-beep-config-tui   # Launch text interface
  • Works in terminal/SSH sessions
  • Uses dialog/whiptail
  • Full keyboard navigation
  • Service selection, tune management, scheduling

๐ŸŽจ GUI (Graphical User Interface):

sparky-beep-config-gui         # Launch graphical interface
  • Works in any desktop environment
  • Uses zenity/yad for compatibility
  • Point-and-click configuration
  • Preview sounds before applying

โšก Unified CLI:

sparky-beep-config            # Auto-detect TUI/GUI
sparky-beep-config --list     # List available services
sparky-beep-config --enable ssh       # Enable beep for SSH
sparky-beep-config --disable netdata  # Disable beep for NetData
sparky-beep-config --test ssh start   # Test SSH start beep

Features:

  • ๐ŸŽฏ Service Discovery - Automatically finds compatible services
  • ๐ŸŽต Tune Management - Assign melodies to each service event
  • โฐ Scheduling - Configure quiet hours and time-based rules
  • ๐ŸŒ Multi-language - All interfaces support 26 languages
  • ๐Ÿ’พ Configuration Backup - Automatic backup before changes
  • โœ… Service Status - Real-time service monitoring

Configuration File:

  • Location: /etc/sparky-beep/beep.conf
  • User config: ~/.config/sparky-beep/beep.conf
  • Automatic creation with sensible defaults
  • Human-readable INI format

Internationalization (i18n)

Sparky Beep supports 26 languages with automatic detection based on your system's LANG environment variable - Complete Debian i18n coverage!

Language Native Name Code
Arabic ุงู„ุนุฑุจูŠุฉ ar
Catalan Catalร  ca
Czech ฤŒeลกtina cs
Danish Dansk da
German Deutsch de
Greek ฮ•ฮปฮปฮทฮฝฮนฮบฮฌ el
English English en (default)
Spanish Espaรฑol es
Finnish Suomi fi
French Franรงais fr
Hungarian Magyar hu
Italian Italiano it
Japanese ๆ—ฅๆœฌ่ชž ja
Korean ํ•œ๊ตญ์–ด ko
Dutch Nederlands nl
Polish Polski pl
Portuguese Portuguรชs pt
Portuguese (Brazil) Portuguรชs do Brasil pt_BR
Romanian Romรขnฤƒ ro
Russian ะ ัƒััะบะธะน ru
Slovak Slovenฤina sk
Swedish Svenska sv
Turkish Tรผrkรงe tr
Ukrainian ะฃะบั€ะฐั—ะฝััŒะบะฐ uk
Chinese (Simplified) ็ฎ€ไฝ“ไธญๆ–‡ zh_CN
Chinese (Traditional) ็น้ซ”ไธญๆ–‡ zh_TW

Usage:

# Change language by setting LANG environment variable
export LANG=de_DE.UTF-8  # Use German
./bin/sparky-beep-run

export LANG=fr_FR.UTF-8  # Use French
/etc/init.d/beep_netdata start

Translation files: locale/*.lang Documentation: See locale/LANGUAGES.md for details on adding new languages

Where to Learn More

  • Inspect bin/sparky-beep-run to see how it uses systemctl to check service state.
  • Review the init scripts in init.d/ to adjust beep sequences or add new services.
  • Learn how systemd unit files are installed and enabled with systemctl enable and systemctl start.
  • This README lists the dependencies and quick steps for installation or removal.

Testing

Running Tests

Sparky Beep uses Bats (Bash Automated Testing System) for testing. To run the test suite:

# Install bats if not already installed
sudo apt-get install bats

# Run all tests
bats tests/

# Run specific test file
bats tests/sparky-beep-run.bats
bats tests/init-usage.bats

Current Test Coverage

The project now has ~85% test coverage across core features and ~35% overall (up from ~15%):

Test Files:

  • tests/init-usage.bats - Validates usage messages match script names (1 test)
  • tests/sparky-beep-run.bats - Tests basic service activation for beep_sys (1 test)
  • tests/sparky-beep-run-extended.bats - Comprehensive service tests (16 tests)
  • tests/init-scripts.bats - Init script execution tests (26 tests)
  • tests/install.bats - Installation/uninstallation tests (15 tests)
  • tests/composer.bats - Composer and musical notation tests (27 tests)
  • tests/libraries.bats - Library function tests (42 tests) โœจ NEW
  • tests/config-tools.bats - Configuration tool tests (30 tests) โœจ NEW
  • tests/ui-tools.bats - TUI/GUI interface tests (38 tests) โœจ NEW
  • tests/tbeep.bats - Ternary beep engine tests (32 tests) โœจ NEW
  • tests/helpers.bash - Shared test infrastructure

Total: 228 tests (increased from 86 tests) ๐ŸŽ‰

Test Coverage by Component:

Component Lines Tests Coverage Status
sparky-beep-run 108 17 ~85% โœ… Good
init.d scripts (5 files) ~170 27 ~70% โœ… Good
install.sh 35 15 ~80% โœ… Good
sparky-beep-compose ~400 27 ~75% โœ… Good
lib/notes.sh ~600 10 ~50% โš ๏ธ Partial
lib/config.sh ~11,000 10 ~30% โš ๏ธ Partial
lib/discovery.sh ~10,000 10 ~30% โš ๏ธ Partial
lib/scheduler.sh ~10,000 6 ~25% โš ๏ธ Partial
lib/tunes.sh ~10,000 2 ~10% โš ๏ธ Low
locale/i18n.sh ~1,000 10 ~40% โš ๏ธ Partial
config/beep.conf ~150 5 N/A โœ… Good
TUI/GUI tools (7 files) ~95,000 68 ~20% โš ๏ธ Partial
bin/tbeep.c ~450 32 ~60% โš ๏ธ Partial
systemd services (4 files) ~60 0 0% โš ๏ธ Low
Core Features Total ~1,463 86 ~85% โœ… Good
All Components Total ~138,923 228 ~35% โš ๏ธ Moderate

Test Improvements

Now tested (sparky-beep-run): โœ…

  • โœ… beep_netdata service activation โœจ NEW
  • โœ… beep_samba service activation with complex logic โœจ NEW
    • โœ… smbd masking logic โœจ NEW
    • โœ… samba-ad-dc unmasking logic โœจ NEW
  • โœ… beep_webmin service activation โœจ NEW
  • โœ… Service enabling logic (all services) โœจ NEW
  • โœ… Package detection when package is NOT installed โœจ NEW
  • โœ… Service already active (should skip activation) โœจ NEW
  • โœ… Service already enabled (should skip enabling) โœจ NEW
  • โœ… Log file creation โœจ NEW
  • โœ… Multiple services activation โœจ NEW
  • โœ… Service activation failure reporting โœจ NEW

Now tested (init scripts): โœ…

  • โœ… start action execution for all scripts โœจ NEW
  • โœ… stop action execution for all scripts โœจ NEW
  • โœ… restart action execution for all scripts โœจ NEW
  • โœ… Exit codes (0 for success, 1 for invalid args) โœจ NEW
  • โœ… set -e error handling behavior โœจ NEW
  • โœ… Beep command validation (frequencies, durations) โœจ NEW
  • โœ… Imperial March theme in beep_samba โœจ NEW
  • โœ… Sequential execution โœจ NEW

Now tested (install.sh): โœ…

  • โœ… Installation (copying files to /etc, /lib, /usr) โœจ NEW
  • โœ… Uninstallation (file removal) โœจ NEW
  • โœ… File permissions preservation โœจ NEW
  • โœ… Graceful handling of missing files โœจ NEW

Now tested (composer system): โœ…

  • โœ… Help and usage messages
  • โœ… Single and multiple note parsing
  • โœ… Sharps and flats (chromatic notes)
  • โœ… All octave ranges (0-8)
  • โœ… All note durations (whole, half, quarter, eighth)
  • โœ… Tempo directives and BPM scaling
  • โœ… Rest notation
  • โœ… File input/output operations
  • โœ… Library functions (get_note_frequency, parse_note, set_tempo_bpm)
  • โœ… All 10 composition files validation
  • โœ… Configuration file defaults
  • โœ… Enharmonic equivalents (C# = Db)

Now tested (libraries): โœ… NEW

  • โœ… lib/config.sh - File existence, sourcing, function definitions (10 tests) โœจ NEW
  • โœ… lib/discovery.sh - File existence, sourcing, function definitions (10 tests) โœจ NEW
  • โœ… lib/scheduler.sh - File existence, sourcing, function definitions (6 tests) โœจ NEW
  • โœ… lib/tunes.sh - File existence, sourcing (2 tests) โœจ NEW
  • โœ… lib/notes.sh - Additional function tests (6 tests) โœจ NEW
  • โœ… locale/i18n.sh - i18n support and 26 language files (10 tests) โœจ NEW

Now tested (config tools): โœ… NEW

  • โœ… sparky-beep-config - File existence, executability, options (12 tests) โœจ NEW
  • โœ… sparky-beep-config-tui - TUI implementation (9 tests) โœจ NEW
  • โœ… sparky-beep-config-gui - GUI implementation (9 tests) โœจ NEW

Now tested (UI tools): โœ… NEW

  • โœ… sparky-beep-composer-tui - Composer TUI (8 tests) โœจ NEW
  • โœ… sparky-beep-composer-gui - Composer GUI (8 tests) โœจ NEW
  • โœ… sparky-beep-player-tui - Player TUI (8 tests) โœจ NEW
  • โœ… sparky-beep-player-gui - Player GUI (8 tests) โœจ NEW
  • โœ… Integration tests for all UI tools (6 tests) โœจ NEW

Now tested (ternary beep engine): โœ… NEW

  • โœ… tbeep.c source code validation (32 tests) โœจ NEW
  • โœ… Makefile targets and compilation setup โœจ NEW
  • โœ… Ternary and binary mode support โœจ NEW
  • โœ… Command-line option parsing โœจ NEW
  • โœ… Integration with beep.conf โœจ NEW

Remaining gaps:

  • โš ๏ธ Systemd service file syntax validation
  • โš ๏ธ Service dependency bindings (BindsTo, After, etc.)
  • โš ๏ธ Actual PC speaker hardware testing
  • โš ๏ธ Deeper library function testing (implementation details)
  • โš ๏ธ Integration testing (end-to-end workflows)
  • โš ๏ธ Interactive TUI/GUI testing (requires user interaction)

Future Test Enhancements

Priority 1: Enhanced Component Tests (high priority)

  1. Deeper library function tests:

    • โœ… Basic existence and sourcing tests โœ…
    • โš ๏ธ Implementation details (function logic, edge cases)
    • โš ๏ธ Error handling in library functions
    • โš ๏ธ Integration between libraries
  2. Interactive TUI/GUI tests:

    • โœ… Basic structure and dependencies tests โœ…
    • โš ๏ธ User interaction simulation
    • โš ๏ธ Dialog/zenity output validation
    • โš ๏ธ Error handling in UI workflows
  3. Ternary beep runtime tests:

    • โœ… Source code and Makefile tests โœ…
    • โš ๏ธ Compilation and execution tests
    • โš ๏ธ Binary vs ternary mode comparison
    • โš ๏ธ Actual frequency/duration validation

Priority 2: Integration Tests

  1. End-to-end workflows:

    • Install โ†’ Configure โ†’ Test โ†’ Uninstall
    • Composer TUI โ†’ Create composition โ†’ Play via player
    • Config TUI โ†’ Enable service โ†’ Verify systemd activation
    • Multi-language interface switching (i18n)
  2. Service integration:

    • Systemd service binding behavior
    • Service state propagation (parent service stops โ†’ beep service stops)
    • Service discovery with actual packages

Priority 3: Validation Tests (remaining)

  1. Systemd service file validation:

    • Service file syntax validation
    • Verify service bindings (BindsTo, After, WantedBy)
    • Validate ExecStart/ExecStop/ExecReload paths
    • Test service dependency chains
  2. LSB header validation (partially covered):

    • โœ… Usage messages validated
    • Validate all LSB fields (Provides, Required-Start, Default-Start, etc.)
    • Verify runlevel specifications
  3. Performance tests:

    • Beep sequence timing validation
    • Multiple concurrent service activations
    • Composition playback performance

Testing Infrastructure

Current test organization:

tests/
โ”œโ”€โ”€ helpers.bash                     # โœ… Shared test infrastructure
โ”œโ”€โ”€ init-usage.bats                  # โœ… Usage message validation (1 test)
โ”œโ”€โ”€ sparky-beep-run.bats            # โœ… Basic service tests (1 test)
โ”œโ”€โ”€ sparky-beep-run-extended.bats   # โœ… Comprehensive service tests (16 tests)
โ”œโ”€โ”€ init-scripts.bats                # โœ… Init script execution tests (26 tests)
โ”œโ”€โ”€ install.bats                     # โœ… Installation tests (15 tests)
โ”œโ”€โ”€ composer.bats                    # โœ… Composer and notation tests (27 tests)
โ”œโ”€โ”€ libraries.bats                   # โœ… Library function tests (42 tests) โœจ NEW
โ”œโ”€โ”€ config-tools.bats                # โœ… Config tool tests (30 tests) โœจ NEW
โ”œโ”€โ”€ ui-tools.bats                    # โœ… UI tool tests (38 tests) โœจ NEW
โ”œโ”€โ”€ tbeep.bats                       # โœ… Ternary beep tests (32 tests) โœจ NEW
โ””โ”€โ”€ README.md                        # โœ… Testing documentation

Implemented test helpers (helpers.bash): โœ…

  • โœ… setup_mock_environment() - Complete mock setup
  • โœ… mock_systemctl() - Mock systemctl with state tracking
  • โœ… mock_apt_cache_*() - Mock package installation status
  • โœ… mock_beep() - Mock beep command
  • โœ… assert_service_started() - Verify service state
  • โœ… assert_service_enabled() - Verify enabled state
  • โœ… assert_file_exists() - Verify file creation
  • โœ… assert_output_contains() - Verify output content
  • โœ… set_service_started() - Pre-configure service state
  • โœ… cleanup_mock_environment() - Test cleanup

Future organization (optional):

  • Consider organizing into subdirectories (unit/, integration/, validation/)
  • Add CI/CD integration (GitHub Actions)
  • Add test coverage reporting

Contributing Tests

When contributing to Sparky Beep, please:

  1. Run existing tests to ensure no regressions: bats tests/
  2. Add tests for new beep services
  3. Update tests if changing status check logic
  4. Ensure tests pass before submitting pull requests

For more detailed testing guidance, see tests/README.md.

Copyright (C) 2018-2020 Paweล‚ Pijanowski & Daniel Campos Ramos

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Dependencies:

apt beep coreutils grep openssh-server systemd

Suggests:

netdata samba webmin

Install:

su (or sudo) ./install.sh

Uninstall:

su (or sudo) ./install.sh uninstall

About

Make sound anouncements on the various services running

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •