From 69c007ef07e43373b76d334fcc232a02f6bc533b Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 7 Jul 2021 07:58:14 +0200 Subject: [PATCH] rc: opnsense-beep melody database directory An idea from the last refactoring: create a database directory that holds the defaults as portable files with the ability to invoke other user-created melodies as well as override the default using ".local" suffix. --- plist | 4 +++ src/etc/opnsense-beep.d/high | 1 + src/etc/opnsense-beep.d/low | 1 + src/etc/opnsense-beep.d/start | 5 ++++ src/etc/opnsense-beep.d/stop | 5 ++++ src/man/man8/opnsense-beep.8 | 23 +++++++++++++--- src/sbin/opnsense-beep | 49 +++++++++++++++++------------------ 7 files changed, 60 insertions(+), 28 deletions(-) create mode 100644 src/etc/opnsense-beep.d/high create mode 100644 src/etc/opnsense-beep.d/low create mode 100644 src/etc/opnsense-beep.d/start create mode 100644 src/etc/opnsense-beep.d/stop diff --git a/plist b/plist index fa5f5fe9c..7a58e3007 100644 --- a/plist +++ b/plist @@ -61,6 +61,10 @@ /usr/local/etc/lighttpd_webgui/conf.d/README /usr/local/etc/lighttpd_webgui/conf.d/extforward.conf.example /usr/local/etc/netflow.conf.example +/usr/local/etc/opnsense-beep.d/high +/usr/local/etc/opnsense-beep.d/low +/usr/local/etc/opnsense-beep.d/start +/usr/local/etc/opnsense-beep.d/stop /usr/local/etc/pkg/fingerprints/OPNsense/revoked/opnsense-update.deciso.com.20160725 /usr/local/etc/pkg/fingerprints/OPNsense/revoked/opnsense-update.deciso.com.20170721 /usr/local/etc/pkg/fingerprints/OPNsense/revoked/opnsense-update.deciso.com.20180627 diff --git a/src/etc/opnsense-beep.d/high b/src/etc/opnsense-beep.d/high new file mode 100644 index 000000000..b189ed5a3 --- /dev/null +++ b/src/etc/opnsense-beep.d/high @@ -0,0 +1 @@ +900 10 diff --git a/src/etc/opnsense-beep.d/low b/src/etc/opnsense-beep.d/low new file mode 100644 index 000000000..60929c8ef --- /dev/null +++ b/src/etc/opnsense-beep.d/low @@ -0,0 +1 @@ +200 10 diff --git a/src/etc/opnsense-beep.d/start b/src/etc/opnsense-beep.d/start new file mode 100644 index 000000000..f40d6aa1e --- /dev/null +++ b/src/etc/opnsense-beep.d/start @@ -0,0 +1,5 @@ +500 25 +400 25 +600 25 +800 25 +800 25 diff --git a/src/etc/opnsense-beep.d/stop b/src/etc/opnsense-beep.d/stop new file mode 100644 index 000000000..71e6e8fb3 --- /dev/null +++ b/src/etc/opnsense-beep.d/stop @@ -0,0 +1,5 @@ +600 25 +800 25 +500 25 +400 25 +400 25 diff --git a/src/man/man8/opnsense-beep.8 b/src/man/man8/opnsense-beep.8 index 1423c6884..8ff28c125 100644 --- a/src/man/man8/opnsense-beep.8 +++ b/src/man/man8/opnsense-beep.8 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd February 1, 2021 +.Dd July 7, 2021 .Dt OPNSENSE-BEEP 8 .Os .Sh NAME @@ -36,9 +36,9 @@ .Sh DESCRIPTION The .Nm -will emit system beeps or melodies. +utility will emit system beeps or melodies. .Pp -Supported melody arguments are as follows: +Default melodies are as follows: .Pp .Bl -bullet -compact .It @@ -51,7 +51,24 @@ Supported melody arguments are as follows: .It .Ar stop .El +.Pp +Argument given will load the melody file from the database directory. +Local files can be added at will. +All files including the defaults can be overwritten by appending +.Sq .local +to a file name. +.Pp +The file format is one note value followed by a duration value per line +as understood by +.Xr beep 1 . +.Sh FILES +.Bl -tag -width Ds +.It Pa /usr/local/etc/opnsene-beep.d +The melody database directory. +.El .Sh EXIT STATUS .Ex -std +.Sh SEE ALSO +.Xr beep 1 .Sh AUTHORS .An Scott Ullrich Aq Mt sullrich@gmail.com diff --git a/src/sbin/opnsense-beep b/src/sbin/opnsense-beep index 7eef02498..354d4edc0 100755 --- a/src/sbin/opnsense-beep +++ b/src/sbin/opnsense-beep @@ -25,26 +25,26 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +BEEPDIR="/usr/local/etc/opnsense-beep.d" COMMAND=${1} -HIGH="900" -LOW="200" -START="500 400 600 800 800" -STOP="600 800 500 400 400" +if [ -z "${COMMAND}" ]; then + COMMAND=low +fi while getopts "" OPT; do - case ${OPT} in - *) - echo "Usage: man ${0##*/}" >&2 - exit 1 - ;; - esac + case ${OPT} in + *) + echo "Usage: man ${0##*/}" >&2 + exit 1 + ;; + esac done shift $((${OPTIND} - 1)) if [ ! -c "/dev/speaker" ]; then - exit + exit 1 fi if [ -f /conf/config.xml ]; then @@ -53,17 +53,16 @@ if [ -f /conf/config.xml ]; then fi fi -case "${COMMAND}" in -start) - for NOTE in ${START}; do /usr/local/bin/beep -p ${NOTE} 25; done - ;; -stop) - for NOTE in ${STOP}; do /usr/local/bin/beep -p ${NOTE} 25; done - ;; -high) - for NOTE in ${HIGH}; do /usr/local/bin/beep -p ${NOTE} 10; done - ;; -low|*) - for NOTE in ${LOW}; do /usr/local/bin/beep -p ${NOTE} 10; done - ;; -esac +BEEPFILE="${BEEPDIR}/${COMMAND}" + +if [ -f "${BEEPFILE}.local" ]; then + BEEPFILE="${BEEPFILE}.local" +fi + +if [ ! -f "${BEEPFILE}" ]; then + exit 1 +fi + +cat "${BEEPFILE}" | while read NOTE DURATION; do + /usr/local/bin/beep -p "${NOTE}" "${DURATION}" +done