From 0d5fb940df0f431de1a563943e3588684cd4b1ff Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 19 Feb 2024 07:10:51 -0800 Subject: [PATCH] Fixes and improvements in 2011/vik/try.sh Check for perl(1) before trying to run ./raw2wav. If neither mplayer(1) nor perl(1) are installed then the script tells the user to install one or both and try again. Function raw2wav() checks that perl(1) is installed. If it's not it silently returns. With this change and the above it no longer makes any assumption about what is installed and also tells the user what they need to do if they don't have the proper tools installed. Typo fix. --- 2011/vik/try.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/2011/vik/try.sh b/2011/vik/try.sh index 0fe7cba06..d61f9efd8 100755 --- a/2011/vik/try.sh +++ b/2011/vik/try.sh @@ -17,14 +17,19 @@ make CC="$CC" all >/dev/null # clear screen after compilation so that only the entry is shown clear -# fine mplayer +# find mplayer MPLAYER="$(type -P mplayer)" +# find perl +PERL="$(type -P perl)" raw2wav() { if [[ "$#" != 2 ]]; then echo "$0: raw2wav() expects two args, got: $#" 1>&2 return + elif [[ -z "$PERL" ]]; then + # silently return if perl not installed + return fi read -r -n 1 -p "Press any key to run: ./vik $1 > $2: " @@ -40,10 +45,18 @@ raw2wav() echo 1>&2 } +if [[ -z "$MPLAYER" && -z "$PERL" ]]; then + echo "Neither mplayer(1) nor perl(1) installed. Please install one or" 1>&2 + echo "both of these and try again." 1>&2 + echo 1>& + exit 1 +fi + +# If we have mplayer we'll try playing the sounds directly. In either case, +# if perl is installed, the alternate procedure will be run, creating WAV +# files. If they do not have mplayer then if they have perl we will create WAV +# files. if [[ -n "$MPLAYER" && -f "$MPLAYER" && -x "$MPLAYER" ]]; then - # If we have mplayer we'll try playing the sounds directly. If however it - # fails for some reason we will run the alternate procedure, creating WAV - # files. read -r -n 1 -p "Press any key to run: ./vik randowan.mod | $MPLAYER -demuxer rawaudio -: " echo 1>&2 ./vik randowan.mod | mplayer -demuxer rawaudio -