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.
This commit is contained in:
Franco Fichtner 2021-07-07 07:58:14 +02:00
parent 0e7097cfb1
commit 69c007ef07
7 changed files with 60 additions and 28 deletions

4
plist
View File

@ -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

View File

@ -0,0 +1 @@
900 10

View File

@ -0,0 +1 @@
200 10

View File

@ -0,0 +1,5 @@
500 25
400 25
600 25
800 25
800 25

View File

@ -0,0 +1,5 @@
600 25
800 25
500 25
400 25
400 25

View File

@ -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

View File

@ -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