From fce66420c8479df57c3ce38ef7f985d5683a9674 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Wed, 9 Aug 2017 18:08:34 -0400 Subject: [PATCH] Refactor music.sh to use functions --- .../root_partition/opt/groomer/music.sh | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/circlean_fs/root_partition/opt/groomer/music.sh b/circlean_fs/root_partition/opt/groomer/music.sh index 81d8122..20b5235 100755 --- a/circlean_fs/root_partition/opt/groomer/music.sh +++ b/circlean_fs/root_partition/opt/groomer/music.sh @@ -1,22 +1,25 @@ #!/bin/bash -set -e -#set -x - -source ./config.sh - killed(){ echo 'Music stopped.' } -trap killed EXIT TERM INT - -# Force output on analog -amixer cset numid=3 1 - -files=(${MUSIC_DIR}*) - -while true; do - # -id flags set interface to "dumb" and -qq silences most/all terminal output - $TIMIDITY -idqq ${files[RANDOM % ${#files[@]}]} +run_timidity() { + # Force output on analog + amixer cset numid=3 1 + files=(${MUSIC_DIR}*) + while true; do + # -id flags set interface to "dumb" and -qq silences most/all terminal output + "${TIMIDITY}" -idqq "${files[RANDOM % ${#files[@]}]}" done +} + +main() { + set -eu # exit when a line returns non-0 status, treat unset variables as errors + trap killed EXIT TERM INT # run clean when the script ends or is interrupted + check_is_root + source ./config.sh # get config values + run_timidity +} + +main